-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#137 Draft of Avalonia realization. Not completed, but partial realiz…
…ed. Has some bugs of bindings Uri and empty data.
- Loading branch information
Showing
9 changed files
with
333 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<UserControl xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" | ||
x:Class="MangaReader.Avalonia.View.ProxySetting"> | ||
<StackPanel> | ||
<Grid> | ||
<Grid.Styles> | ||
<Style Selector="TextBlock"> | ||
<Setter Property="VerticalAlignment" Value="Center"/> | ||
<Setter Property="Margin" Value="4"/> | ||
</Style> | ||
<Style Selector="TextBox"> | ||
<Setter Property="VerticalAlignment" Value="Center"/> | ||
<Setter Property="Margin" Value="4"/> | ||
</Style> | ||
<Style Selector="TextBox:disabled"> | ||
<Setter Property="Opacity" Value="{DynamicResource ThemeDisabledOpacity}"/> | ||
</Style> | ||
</Grid.Styles> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="Auto"/> | ||
<ColumnDefinition Width="*"/> | ||
</Grid.ColumnDefinitions> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="*"/> | ||
<RowDefinition Height="Auto"/> | ||
</Grid.RowDefinitions> | ||
<ListBox Grid.Column="0" Grid.Row="0" | ||
Items="{Binding ProxySettingModels}" SelectedItem="{Binding SelectedProxySettingModel}"> | ||
<ListBox.ItemTemplate> | ||
<DataTemplate> | ||
<TextBlock Text="{Binding Name}"/> | ||
</DataTemplate> | ||
</ListBox.ItemTemplate> | ||
</ListBox> | ||
<StackPanel Grid.Column="0" Grid.Row="1" | ||
Orientation="Horizontal"> | ||
<Button Content="+" Command="{Binding Add}"/> | ||
<Button Content="-" Command="{Binding Remove}"/> | ||
</StackPanel> | ||
<Grid Grid.Column="1" Grid.Row="0" DataContext="{Binding SelectedProxySettingModel}"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="2*"></RowDefinition> | ||
<RowDefinition Height="2*"></RowDefinition> | ||
<RowDefinition Height="2*"></RowDefinition> | ||
<RowDefinition Height="2*"></RowDefinition> | ||
</Grid.RowDefinitions> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="Auto"></ColumnDefinition> | ||
<ColumnDefinition Width="30*"></ColumnDefinition> | ||
</Grid.ColumnDefinitions> | ||
|
||
<TextBlock Grid.Row="0" Grid.Column="0" Text="Название: " /> | ||
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Name}" IsEnabled="{Binding IsManual}"/> | ||
|
||
|
||
<TextBlock Grid.Row="1" Grid.Column="0" Text="Адрес прокси: " /> | ||
<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Address}" IsEnabled="{Binding IsManual}"/> | ||
|
||
<TextBlock Grid.Row="2" Grid.Column="0" Text="Имя пользователя: " /> | ||
<TextBox Grid.Row="2" Grid.Column="1" Text="{Binding UserName}" IsEnabled="{Binding IsManual}"/> | ||
|
||
<TextBlock Grid.Row="3" Grid.Column="0" | ||
Text="Пароль: " /> | ||
<TextBox Grid.Row="3" Grid.Column="1" Text="{Binding Password}" IsEnabled="{Binding IsManual}"/> | ||
</Grid> | ||
<Grid Grid.Column="1" Grid.Row="1"> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="*"/> | ||
<ColumnDefinition Width="Auto"/> | ||
</Grid.ColumnDefinitions> | ||
<TextBox Grid.Column="0" Text="{Binding TestAddress}"/> | ||
<Button Grid.Column="1" | ||
Command="{Binding Test}" | ||
Content="Проверить"/> | ||
</Grid> | ||
</Grid> | ||
</StackPanel> | ||
</UserControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Markup.Xaml; | ||
|
||
namespace MangaReader.Avalonia.View | ||
{ | ||
public class ProxySetting : UserControl | ||
{ | ||
public ProxySetting() | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
|
||
private void InitializeComponent() | ||
{ | ||
AvaloniaXamlLoader.Load(this); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
MangaReader.Avalonia/ViewModel/Explorer/ProxySettingModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using MangaReader.Core.Account; | ||
|
||
namespace MangaReader.Avalonia.ViewModel.Explorer | ||
{ | ||
public class ProxySettingModel : ViewModelBase | ||
{ | ||
public ProxySettingType SettingType { get; set; } | ||
|
||
public int Id | ||
{ | ||
get => id; | ||
set => this.RaiseAndSetIfChanged(ref id, value); | ||
} | ||
|
||
private int id; | ||
|
||
public string Name | ||
{ | ||
get => name; | ||
set => this.RaiseAndSetIfChanged(ref name, value); | ||
} | ||
|
||
private string name; | ||
|
||
public Uri Address | ||
{ | ||
get => address; | ||
set => this.RaiseAndSetIfChanged(ref address, value); | ||
} | ||
|
||
private Uri address; | ||
|
||
public string UserName | ||
{ | ||
get => userName; | ||
set => this.RaiseAndSetIfChanged(ref userName, value); | ||
} | ||
|
||
private string userName; | ||
|
||
public string Password | ||
{ | ||
get => password; | ||
set => this.RaiseAndSetIfChanged(ref password, value); | ||
} | ||
|
||
private string password; | ||
|
||
public bool IsManual { get; private set; } | ||
|
||
public ProxySettingModel(ProxySetting setting) | ||
{ | ||
Id = setting.Id; | ||
Name = setting.Name; | ||
Address = setting.Address; | ||
UserName = setting.UserName; | ||
Password = setting.Password; | ||
SettingType = setting.SettingType; | ||
IsManual = setting.SettingType == ProxySettingType.Manual; | ||
} | ||
|
||
} | ||
} |
144 changes: 144 additions & 0 deletions
144
MangaReader.Avalonia/ViewModel/Explorer/ProxySettingSelectorModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
using System; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using System.Windows.Input; | ||
using MangaReader.Avalonia.ViewModel.Command; | ||
using MangaReader.Core.Account; | ||
using MangaReader.Core.NHibernate; | ||
using MangaReader.Core.Services; | ||
|
||
namespace MangaReader.Avalonia.ViewModel.Explorer | ||
{ | ||
public class ProxySettingSelectorModel : ExplorerTabViewModel | ||
{ | ||
|
||
public ProxySettingModel SelectedProxySettingModel | ||
{ | ||
get => selectedProxySettingModel; | ||
set => this.RaiseAndSetIfChanged(ref selectedProxySettingModel, value); | ||
} | ||
|
||
private ProxySettingModel selectedProxySettingModel; | ||
|
||
public ObservableCollection<ProxySettingModel> ProxySettingModels | ||
{ | ||
get => proxySettingModels; | ||
set => this.RaiseAndSetIfChanged(ref proxySettingModels, value); | ||
} | ||
|
||
private ObservableCollection<ProxySettingModel> proxySettingModels; | ||
|
||
public string TestAddress | ||
{ | ||
get => testAddress; | ||
set => this.RaiseAndSetIfChanged(ref testAddress, value); | ||
} | ||
|
||
private string testAddress; | ||
|
||
public DelegateCommand Add { get; } | ||
|
||
public DelegateCommand Remove { get; } | ||
|
||
public DelegateCommand Test { get; } | ||
|
||
public ICommand Save { get; } | ||
|
||
public ICommand Undo { get; } | ||
|
||
public override Task OnSelected(ExplorerTabViewModel previousModel) | ||
{ | ||
using (var context = Repository.GetEntityContext()) | ||
{ | ||
this.ProxySettingModels = new ObservableCollection<ProxySettingModel>(context | ||
.Get<ProxySetting>() | ||
.Select(s => new ProxySettingModel(s))); | ||
this.SelectedProxySettingModel = this.ProxySettingModels.FirstOrDefault(); | ||
} | ||
return base.OnSelected(previousModel); | ||
} | ||
|
||
public ProxySettingSelectorModel() | ||
{ | ||
this.Name = "Прокси"; | ||
this.Priority = 600; | ||
this.Add = new DelegateCommand(() => | ||
{ | ||
var newProxy = new ProxySettingModel(new ProxySetting(ProxySettingType.Manual)); | ||
this.ProxySettingModels.Add(newProxy); | ||
this.SelectedProxySettingModel = newProxy; | ||
}); | ||
this.Remove = new DelegateCommand(() => | ||
{ | ||
var selected = this.SelectedProxySettingModel; | ||
var models = this.ProxySettingModels; | ||
var index = models.IndexOf(selected); | ||
var next = models.Count > index + 1 ? models[index + 1] : models[index - 1]; | ||
models.Remove(selected); | ||
this.SelectedProxySettingModel = next; | ||
return Task.CompletedTask; | ||
}, () => this.SelectedProxySettingModel?.IsManual == true, SubscribeToCommand(nameof(SelectedProxySettingModel))); | ||
this.Test = new DelegateCommand(TestAddressImpl, () => !string.IsNullOrWhiteSpace(this.TestAddress), SubscribeToCommand(nameof(TestAddress))); | ||
this.Save = new DelegateCommand(SaveImpl, () => true); | ||
this.testAddress = "https://github.com/MonkAlex/MangaReader"; | ||
} | ||
|
||
private async Task SaveImpl() | ||
{ | ||
if (ProxySettingModels == null) | ||
return; | ||
|
||
using (var context = Repository.GetEntityContext()) | ||
{ | ||
var manualProxies = await context.Get<ProxySetting>().ToListAsync().ConfigureAwait(true); | ||
foreach (var model in ProxySettingModels.Where(m => m.IsManual)) | ||
{ | ||
var setting = model.Id == 0 ? new ProxySetting(ProxySettingType.Manual) : manualProxies.Single(p => p.Id == model.Id); | ||
setting.Name = model.Name; | ||
setting.Address = model.Address; | ||
setting.UserName = model.UserName; | ||
setting.Password = model.Password; | ||
setting.SettingType = model.SettingType; | ||
await context.Save(setting).ConfigureAwait(true); | ||
model.Id = setting.Id; | ||
} | ||
|
||
var toRemove = manualProxies.Where(p => ProxySettingModels.All(m => m.Id != p.Id)).ToList(); | ||
foreach (var setting in toRemove) | ||
{ | ||
await context.Delete(setting).ConfigureAwait(true); | ||
} | ||
} | ||
} | ||
|
||
private async Task TestAddressImpl() | ||
{ | ||
try | ||
{ | ||
var selected = this.SelectedProxySettingModel; | ||
var address = this.TestAddress; | ||
|
||
var setting = new ProxySetting(selected.SettingType) | ||
{ | ||
Address = selected.Address, | ||
UserName = selected.UserName, | ||
Password = selected.Password | ||
}; | ||
var proxy = setting.GetProxy(); | ||
var client = new TestCoockieClient() { Proxy = proxy }; | ||
await client.DownloadStringTaskAsync(address).ConfigureAwait(true); | ||
Log.Add("Успешно."); | ||
} | ||
catch (Exception e) | ||
{ | ||
Log.Exception(e, "Произошла ошибка."); | ||
} | ||
} | ||
|
||
private class TestCoockieClient : CookieClient | ||
{ | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters