1
0
mirror of https://github.com/proxysu/ProxySU.git synced 2024-11-26 15:16:08 +03:00
ProxySU/ProxySuper.Core/Models/Record.cs

102 lines
2.8 KiB
C#
Raw Normal View History

2021-05-16 04:12:47 +03:00
using MvvmCross;
using MvvmCross.Commands;
using MvvmCross.Navigation;
using MvvmCross.ViewModels;
using Newtonsoft.Json;
2021-05-14 14:07:19 +03:00
using Newtonsoft.Json.Linq;
using ProxySuper.Core.Models.Hosts;
using ProxySuper.Core.Models.Projects;
2021-05-16 04:12:47 +03:00
using ProxySuper.Core.ViewModels;
2021-05-14 14:07:19 +03:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProxySuper.Core.Models
{
2021-05-16 04:12:47 +03:00
public class Record : MvxViewModel
2021-05-14 14:07:19 +03:00
{
2021-05-16 04:12:47 +03:00
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("host")]
2021-05-14 14:07:19 +03:00
public Host Host { get; set; }
[JsonProperty("settings")]
2021-05-16 04:12:47 +03:00
public XraySettings XraySettings { get; set; }
[JsonProperty("trojanGoSettings")]
public TrojanGoSettings TrojanGoSettings { get; set; }
2021-05-14 14:07:19 +03:00
2021-05-16 04:12:47 +03:00
[JsonIgnore]
public ProjectType Type
2021-05-14 14:07:19 +03:00
{
get
{
2021-05-16 04:12:47 +03:00
if (XraySettings != null) return ProjectType.Xray;
return ProjectType.TrojanGo;
}
}
2021-05-20 13:32:17 +03:00
[JsonIgnore]
public IMvxNavigationService _navigationService;
[JsonIgnore]
public IMvxNavigationService NavigationService
{
get
{
if (_navigationService == null)
{
_navigationService = Mvx.IoCProvider.Resolve<IMvxNavigationService>();
}
return _navigationService;
}
}
[JsonIgnore]
public IMvxCommand NavToInstallerCommand => new MvxAsyncCommand(NavigateToInstaller);
2021-05-16 04:12:47 +03:00
2021-05-20 13:32:17 +03:00
[JsonIgnore]
2021-05-16 04:12:47 +03:00
public IMvxCommand NavToEditorCommand => new MvxAsyncCommand(NavigateToEditor);
public async Task NavigateToEditor()
{
if (Type == ProjectType.Xray)
{
2021-05-20 13:32:17 +03:00
var result = await NavigationService.Navigate<XrayEditorViewModel, Record, Record>(this);
2021-05-16 04:12:47 +03:00
if (result == null) return;
this.Host = result.Host;
this.XraySettings = result.XraySettings;
await RaisePropertyChanged("Host");
2021-05-14 14:07:19 +03:00
}
2021-05-16 11:29:37 +03:00
if (Type == ProjectType.TrojanGo)
{
2021-05-20 13:32:17 +03:00
var result = await NavigationService.Navigate<TrojanGoEditorViewModel, Record, Record>(this);
2021-05-16 11:29:37 +03:00
if (result == null) return;
this.Host = result.Host;
this.TrojanGoSettings = result.TrojanGoSettings;
}
2021-05-14 14:07:19 +03:00
}
2021-05-20 13:32:17 +03:00
public async Task NavigateToInstaller()
{
if (Type == ProjectType.Xray)
{
await NavigationService.Navigate<XrayInstallerViewModel, Record>(this);
}
if (Type == ProjectType.TrojanGo)
{
await NavigationService.Navigate<TrojanGoInstallerViewModel, Record>(this);
}
}
2021-05-14 14:07:19 +03:00
}
}