1
0
mirror of https://github.com/proxysu/ProxySU.git synced 2024-11-29 00:26:09 +03:00
ProxySU/ProxySU_Core/ViewModels/HostViewModel.cs

145 lines
3.1 KiB
C#
Raw Normal View History

2021-02-25 04:59:06 +03:00
using Microsoft.Win32;
using Newtonsoft.Json;
2021-03-04 11:25:36 +03:00
using ProxySU_Core.Models;
2021-02-25 04:59:06 +03:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows;
using System.Windows.Input;
namespace ProxySU_Core.ViewModels
{
2021-03-04 11:25:36 +03:00
public class HostViewModel : BaseViewModel
2021-02-25 04:59:06 +03:00
{
2021-03-04 11:25:36 +03:00
public Host host;
2021-02-25 04:59:06 +03:00
private readonly ICommand _selectKeyCommand;
2021-03-17 06:58:56 +03:00
2021-03-04 11:25:36 +03:00
public HostViewModel(Host host)
2021-02-25 04:59:06 +03:00
{
_selectKeyCommand = new BaseCommand(obj => OpenFileDialog(obj));
2021-03-04 11:25:36 +03:00
this.host = host;
2021-02-25 04:59:06 +03:00
}
public string Tag
{
2021-03-04 11:25:36 +03:00
get => host.Tag;
set
2021-02-25 04:59:06 +03:00
{
2021-03-04 11:25:36 +03:00
host.Tag = value;
2021-02-25 04:59:06 +03:00
Notify("Tag");
}
}
public string Address
{
2021-03-04 11:25:36 +03:00
get => host.Address;
2021-02-25 04:59:06 +03:00
set
{
2021-03-04 11:25:36 +03:00
host.Address = value;
2021-02-25 04:59:06 +03:00
Notify("Address");
}
}
2021-03-04 11:25:36 +03:00
public string UserName
{
get => host.UserName;
set => host.UserName = value;
}
2021-02-25 04:59:06 +03:00
2021-03-04 11:25:36 +03:00
public string Password
{
get => host.Password;
set => host.Password = value;
}
2021-02-25 04:59:06 +03:00
2021-03-04 11:25:36 +03:00
public int Port
{
get => host.Port;
set => host.Port = value;
}
2021-02-25 04:59:06 +03:00
2021-03-04 11:25:36 +03:00
public string PrivateKeyPath
{
get => host.PrivateKeyPath;
set => host.PrivateKeyPath = value;
}
2021-02-25 04:59:06 +03:00
public LocalProxy Proxy
{
2021-03-04 11:25:36 +03:00
get => host.Proxy;
set
2021-02-25 04:59:06 +03:00
{
2021-03-04 11:25:36 +03:00
host.Proxy = value;
2021-02-25 04:59:06 +03:00
Notify("Proxy");
}
}
public LoginSecretType SecretType
{
2021-03-04 11:25:36 +03:00
get => host.SecretType;
2021-02-25 04:59:06 +03:00
set
{
2021-03-04 11:25:36 +03:00
host.SecretType = value;
2021-02-25 04:59:06 +03:00
Notify("SecretType");
Notify("KeyUploaderVisiblity");
Notify("PasswordVisiblity");
}
}
[JsonIgnore]
public Visibility PasswordVisiblity
{
get
{
if (SecretType == LoginSecretType.Password)
{
return Visibility.Visible;
}
return Visibility.Collapsed;
}
}
[JsonIgnore]
public Visibility KeyUploaderVisiblity
{
get
{
if (SecretType == LoginSecretType.PrivateKey)
{
return Visibility.Visible;
}
return Visibility.Collapsed;
}
}
[JsonIgnore]
public ICommand SelectKeyCommand
{
get
{
return _selectKeyCommand;
}
}
private void OpenFileDialog(object obj)
{
var fileDialog = new OpenFileDialog();
fileDialog.FileOk += OnFileOk;
fileDialog.ShowDialog();
}
private void OnFileOk(object sender, CancelEventArgs e)
{
var file = sender as OpenFileDialog;
PrivateKeyPath = file.FileName;
}
}
}