This commit is contained in:
artyom 2018-11-23 21:04:41 +03:00
Родитель caf9361f8f
Коммит 14549609d9
9 изменённых файлов: 49 добавлений и 39 удалений

Просмотреть файл

@ -8,15 +8,13 @@
<TabControl>
<TabItem>
<TabItem.Header>
<TextBlock Text="Direct Auth"
IsVisible="{Binding SupportsDirectAuth}"/>
<TextBlock Text="Direct Auth" IsVisible="{Binding SupportsDirectAuth}"/>
</TabItem.Header>
<views:DirectAuthView DataContext="{Binding DirectAuth}"/>
</TabItem>
<TabItem>
<TabItem.Header>
<TextBlock Text="Direct Auth"
IsVisible="{Binding SupportsOAuth}"/>
<TextBlock Text="Direct Auth" IsVisible="{Binding SupportsOAuth}"/>
</TabItem.Header>
<views:OAuthView DataContext="{Binding OAuth}"/>
</TabItem>

Просмотреть файл

@ -104,20 +104,26 @@
</Grid>
<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Orientation="Horizontal" Margin="10">
<Button Grid.Column="0"
Content="Logout"
Classes="Rounded"
IsVisible="{Binding CanLogout}"
Command="{Binding Logout}"/>
<StackPanel Grid.Column="1" Orientation="Horizontal" Margin="10">
<TextBlock Text="You selected: " Foreground="#aaaaaa"/>
<TextBlock Text="{Binding SelectedFile.Name}"
Foreground="#888888"/>
</StackPanel>
<Button Grid.Column="1"
<Button Grid.Column="2"
Content="Upload"
Classes="Rounded"
Command="{Binding UploadToCurrentPath}"/>
<Button Grid.Column="2"
<Button Grid.Column="3"
Content="Download"
Classes="Rounded"
Command="{Binding DownloadSelectedFile}" />

Просмотреть файл

@ -19,6 +19,8 @@ namespace Camelotia.Presentation.Interfaces
ICommand Refresh { get; }
ICommand Logout { get; }
ICommand Back { get; }
ICommand Open { get; }
@ -31,6 +33,8 @@ namespace Camelotia.Presentation.Interfaces
bool HasErrors { get; }
bool CanLogout { get; }
string CurrentPath { get; }
string Description { get; }

Просмотреть файл

@ -1,3 +1,4 @@
using System;
using System.Reactive;
using System.Reactive.Linq;
using System.Windows.Input;
@ -45,6 +46,9 @@ namespace Camelotia.Presentation.ViewModels
_isBusy = _login.IsExecuting
.ToProperty(this, x => x.IsBusy);
_login.Subscribe(x => Username = string.Empty);
_login.Subscribe(x => Password = string.Empty);
}
[Reactive] public string Username { get; set; }

Просмотреть файл

@ -25,9 +25,11 @@ namespace Camelotia.Presentation.ViewModels
private readonly ObservableAsPropertyHelper<string> _currentPath;
private readonly ObservableAsPropertyHelper<bool> _hasErrors;
private readonly ObservableAsPropertyHelper<bool> _isLoading;
private readonly ObservableAsPropertyHelper<bool> _canLogout;
private readonly ObservableAsPropertyHelper<bool> _isReady;
private readonly ReactiveCommand<Unit, string> _back;
private readonly ReactiveCommand<Unit, string> _open;
private readonly ReactiveCommand<Unit, Unit> _logout;
private readonly IProvider _provider;
public ProviderViewModel(
@ -126,6 +128,14 @@ namespace Camelotia.Presentation.ViewModels
.Select(ignore => Unit.Default)
.InvokeCommand(_open);
var isAuthEnabled = provider.SupportsDirectAuth || provider.SupportsOAuth;
var canLogout = provider.IsAuthorized
.Select(loggedIn => loggedIn && isAuthEnabled)
.DistinctUntilChanged();
_canLogout = canLogout.ToProperty(this, x => x.CanLogout);
_logout = ReactiveCommand.CreateFromTask(provider.Logout, canLogout);
Auth = authViewModel;
Activator = new ViewModelActivator();
this.WhenActivated(disposable =>
@ -156,6 +166,8 @@ namespace Camelotia.Presentation.ViewModels
public string CurrentPath => _currentPath?.Value;
public bool CanLogout => _canLogout.Value;
public bool IsLoading => _isLoading.Value;
public bool HasErrors => _hasErrors.Value;
@ -167,6 +179,8 @@ namespace Camelotia.Presentation.ViewModels
public string Size => _provider.Size;
public ICommand Refresh => _refresh;
public ICommand Logout => _logout;
public ICommand Back => _back;

Просмотреть файл

@ -29,5 +29,7 @@ namespace Camelotia.Services.Interfaces
Task DirectAuth(string login, string password);
Task OAuth();
Task Logout();
}
}

Просмотреть файл

@ -13,7 +13,7 @@ namespace Camelotia.Services.Providers
{
public string Size => GetSizeOnAllDisks();
public string Name => nameof(LocalFileSystemProvider);
public string Name => "Local File System";
public string Description => "Provides access to files stored locally.";
@ -23,10 +23,12 @@ namespace Camelotia.Services.Providers
public bool SupportsOAuth => false;
public Task DirectAuth(string login, string password) => Task.CompletedTask;
public Task OAuth() => Task.CompletedTask;
public Task Logout() => Task.CompletedTask;
public Task DirectAuth(string login, string password) => Task.CompletedTask;
public Task<IEnumerable<FileModel>> Get(string path) => Task.Run(() =>
{
if (!Directory.Exists(path))

Просмотреть файл

@ -15,7 +15,7 @@ namespace Camelotia.Services.Providers
public sealed class VkontakteFileSystemProvider : IProvider
{
private readonly ReplaySubject<bool> _isAuthorized;
private readonly VkApi _api;
private VkApi _api;
public VkontakteFileSystemProvider()
{
@ -26,7 +26,7 @@ namespace Camelotia.Services.Providers
public string Size => "Unknown";
public string Name => nameof(VkontakteFileSystemProvider);
public string Name => "Vkontakte Documents";
public string Description => "Vkontakte documents provider";
@ -49,6 +49,13 @@ namespace Camelotia.Services.Providers
});
_isAuthorized.OnNext(_api.IsAuthorized);
}
public Task Logout()
{
_api = new VkApi();
_isAuthorized.OnNext(_api.IsAuthorized);
return Task.CompletedTask;
}
public async Task<IEnumerable<FileModel>> Get(string path)
{

Просмотреть файл

@ -16,30 +16,3 @@ On Windows, run the `./run.bat` file.
### Adding Custom Providers
File system providers are located at `./Camelotia.Services/Providers/`. To add a custom file system provider, you need to create a separate class and implement the [IProvider](https://github.com/worldbeater/Camelotia/blob/master/Camelotia.Services/Interfaces/IProvider.cs) interface. It'll get integrated into the UI automagically.
```cs
public interface IProvider
{
string Size { get; }
string Name { get; }
string Description { get; }
Task<IEnumerable<FileModel>> Get(string path);
Task DownloadFile(string from, Stream to);
Task UploadFile(string to, Stream from);
IObservable<bool> IsAuthorized { get; }
bool SupportsDirectAuth { get; }
bool SupportsOAuth { get; }
Task DirectAuth(string login, string password);
Task OAuth();
}
```