csharp_style_namespace_declarations = file_scoped

This commit is contained in:
2dust
2025-04-02 11:44:23 +08:00
parent d92540121f
commit 4d3db56065
186 changed files with 23574 additions and 23759 deletions

View File

@@ -2,95 +2,94 @@ using System.Reactive;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
namespace ServiceLib.ViewModels
namespace ServiceLib.ViewModels;
public class AddServerViewModel : MyReactiveObject
{
public class AddServerViewModel : MyReactiveObject
[Reactive]
public ProfileItem SelectedSource { get; set; }
[Reactive]
public string? CoreType { get; set; }
public ReactiveCommand<Unit, Unit> SaveCmd { get; }
public AddServerViewModel(ProfileItem profileItem, Func<EViewAction, object?, Task<bool>>? updateView)
{
[Reactive]
public ProfileItem SelectedSource { get; set; }
_config = AppHandler.Instance.Config;
_updateView = updateView;
[Reactive]
public string? CoreType { get; set; }
public ReactiveCommand<Unit, Unit> SaveCmd { get; }
public AddServerViewModel(ProfileItem profileItem, Func<EViewAction, object?, Task<bool>>? updateView)
SaveCmd = ReactiveCommand.CreateFromTask(async () =>
{
_config = AppHandler.Instance.Config;
_updateView = updateView;
await SaveServerAsync();
});
SaveCmd = ReactiveCommand.CreateFromTask(async () =>
{
await SaveServerAsync();
});
if (profileItem.IndexId.IsNullOrEmpty())
{
profileItem.Network = Global.DefaultNetwork;
profileItem.HeaderType = Global.None;
profileItem.RequestHost = "";
profileItem.StreamSecurity = "";
SelectedSource = profileItem;
}
else
{
SelectedSource = JsonUtils.DeepCopy(profileItem);
}
CoreType = SelectedSource?.CoreType?.ToString();
}
if (profileItem.IndexId.IsNullOrEmpty())
{
profileItem.Network = Global.DefaultNetwork;
profileItem.HeaderType = Global.None;
profileItem.RequestHost = "";
profileItem.StreamSecurity = "";
SelectedSource = profileItem;
}
else
{
SelectedSource = JsonUtils.DeepCopy(profileItem);
}
CoreType = SelectedSource?.CoreType?.ToString();
private async Task SaveServerAsync()
{
if (SelectedSource.Remarks.IsNullOrEmpty())
{
NoticeHandler.Instance.Enqueue(ResUI.PleaseFillRemarks);
return;
}
private async Task SaveServerAsync()
if (SelectedSource.Address.IsNullOrEmpty())
{
if (SelectedSource.Remarks.IsNullOrEmpty())
NoticeHandler.Instance.Enqueue(ResUI.FillServerAddress);
return;
}
var port = SelectedSource.Port.ToString();
if (port.IsNullOrEmpty() || !Utils.IsNumeric(port)
|| SelectedSource.Port <= 0 || SelectedSource.Port >= Global.MaxPort)
{
NoticeHandler.Instance.Enqueue(ResUI.FillCorrectServerPort);
return;
}
if (SelectedSource.ConfigType == EConfigType.Shadowsocks)
{
if (SelectedSource.Id.IsNullOrEmpty())
{
NoticeHandler.Instance.Enqueue(ResUI.PleaseFillRemarks);
NoticeHandler.Instance.Enqueue(ResUI.FillPassword);
return;
}
if (SelectedSource.Security.IsNullOrEmpty())
{
NoticeHandler.Instance.Enqueue(ResUI.PleaseSelectEncryption);
return;
}
}
if (SelectedSource.ConfigType is not EConfigType.SOCKS and not EConfigType.HTTP)
{
if (SelectedSource.Id.IsNullOrEmpty())
{
NoticeHandler.Instance.Enqueue(ResUI.FillUUID);
return;
}
}
SelectedSource.CoreType = CoreType.IsNullOrEmpty() ? null : (ECoreType)Enum.Parse(typeof(ECoreType), CoreType);
if (SelectedSource.Address.IsNullOrEmpty())
{
NoticeHandler.Instance.Enqueue(ResUI.FillServerAddress);
return;
}
var port = SelectedSource.Port.ToString();
if (port.IsNullOrEmpty() || !Utils.IsNumeric(port)
|| SelectedSource.Port <= 0 || SelectedSource.Port >= Global.MaxPort)
{
NoticeHandler.Instance.Enqueue(ResUI.FillCorrectServerPort);
return;
}
if (SelectedSource.ConfigType == EConfigType.Shadowsocks)
{
if (SelectedSource.Id.IsNullOrEmpty())
{
NoticeHandler.Instance.Enqueue(ResUI.FillPassword);
return;
}
if (SelectedSource.Security.IsNullOrEmpty())
{
NoticeHandler.Instance.Enqueue(ResUI.PleaseSelectEncryption);
return;
}
}
if (SelectedSource.ConfigType is not EConfigType.SOCKS and not EConfigType.HTTP)
{
if (SelectedSource.Id.IsNullOrEmpty())
{
NoticeHandler.Instance.Enqueue(ResUI.FillUUID);
return;
}
}
SelectedSource.CoreType = CoreType.IsNullOrEmpty() ? null : (ECoreType)Enum.Parse(typeof(ECoreType), CoreType);
if (await ConfigHandler.AddServer(_config, SelectedSource) == 0)
{
NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
_updateView?.Invoke(EViewAction.CloseWindow, null);
}
else
{
NoticeHandler.Instance.Enqueue(ResUI.OperationFailed);
}
if (await ConfigHandler.AddServer(_config, SelectedSource) == 0)
{
NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess);
_updateView?.Invoke(EViewAction.CloseWindow, null);
}
else
{
NoticeHandler.Instance.Enqueue(ResUI.OperationFailed);
}
}
}