2023-01-01 11:42:01 +00:00
|
|
|
|
using ReactiveUI;
|
|
|
|
|
using ReactiveUI.Fody.Helpers;
|
|
|
|
|
using Splat;
|
|
|
|
|
using System.Reactive;
|
|
|
|
|
|
2024-08-20 06:15:29 +00:00
|
|
|
|
namespace ServiceLib.ViewModels
|
2023-01-01 11:42:01 +00:00
|
|
|
|
{
|
2024-08-10 02:02:00 +00:00
|
|
|
|
public class RoutingRuleDetailsViewModel : MyReactiveObject
|
2023-01-01 11:42:01 +00:00
|
|
|
|
{
|
|
|
|
|
public IList<string> ProtocolItems { get; set; }
|
|
|
|
|
public IList<string> InboundTagItems { get; set; }
|
|
|
|
|
|
|
|
|
|
[Reactive]
|
|
|
|
|
public RulesItem SelectedSource { get; set; }
|
|
|
|
|
|
|
|
|
|
[Reactive]
|
|
|
|
|
public string Domain { get; set; }
|
|
|
|
|
|
|
|
|
|
[Reactive]
|
|
|
|
|
public string IP { get; set; }
|
2023-05-09 10:44:04 +00:00
|
|
|
|
|
2023-05-07 11:09:13 +00:00
|
|
|
|
[Reactive]
|
|
|
|
|
public string Process { get; set; }
|
2023-01-01 11:42:01 +00:00
|
|
|
|
|
|
|
|
|
[Reactive]
|
|
|
|
|
public bool AutoSort { get; set; }
|
|
|
|
|
|
|
|
|
|
public ReactiveCommand<Unit, Unit> SaveCmd { get; }
|
|
|
|
|
|
2024-08-10 06:44:25 +00:00
|
|
|
|
public RoutingRuleDetailsViewModel(RulesItem rulesItem, Func<EViewAction, object?, bool>? updateView)
|
2023-01-01 11:42:01 +00:00
|
|
|
|
{
|
2024-08-15 13:03:00 +00:00
|
|
|
|
_config = LazyConfig.Instance.Config;
|
2023-01-01 11:42:01 +00:00
|
|
|
|
_noticeHandler = Locator.Current.GetService<NoticeHandler>();
|
2024-08-10 02:02:00 +00:00
|
|
|
|
_updateView = updateView;
|
2023-01-01 11:42:01 +00:00
|
|
|
|
|
|
|
|
|
if (rulesItem.id.IsNullOrEmpty())
|
|
|
|
|
{
|
2024-03-26 06:26:03 +00:00
|
|
|
|
rulesItem.id = Utils.GetGUID(false);
|
2023-12-19 08:49:45 +00:00
|
|
|
|
rulesItem.outboundTag = Global.ProxyTag;
|
2023-01-01 11:42:01 +00:00
|
|
|
|
rulesItem.enabled = true;
|
|
|
|
|
SelectedSource = rulesItem;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SelectedSource = rulesItem;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-26 06:26:03 +00:00
|
|
|
|
Domain = Utils.List2String(SelectedSource.domain, true);
|
|
|
|
|
IP = Utils.List2String(SelectedSource.ip, true);
|
|
|
|
|
Process = Utils.List2String(SelectedSource.process, true);
|
2023-01-01 11:42:01 +00:00
|
|
|
|
|
|
|
|
|
SaveCmd = ReactiveCommand.Create(() =>
|
|
|
|
|
{
|
|
|
|
|
SaveRules();
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-04-14 12:49:36 +00:00
|
|
|
|
|
2023-01-01 11:42:01 +00:00
|
|
|
|
private void SaveRules()
|
|
|
|
|
{
|
2024-03-26 06:26:03 +00:00
|
|
|
|
Domain = Utils.Convert2Comma(Domain);
|
|
|
|
|
IP = Utils.Convert2Comma(IP);
|
|
|
|
|
Process = Utils.Convert2Comma(Process);
|
2023-04-28 02:22:55 +00:00
|
|
|
|
|
2023-01-01 11:42:01 +00:00
|
|
|
|
if (AutoSort)
|
|
|
|
|
{
|
2024-03-26 06:26:03 +00:00
|
|
|
|
SelectedSource.domain = Utils.String2ListSorted(Domain);
|
|
|
|
|
SelectedSource.ip = Utils.String2ListSorted(IP);
|
|
|
|
|
SelectedSource.process = Utils.String2ListSorted(Process);
|
2023-01-01 11:42:01 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-03-26 06:26:03 +00:00
|
|
|
|
SelectedSource.domain = Utils.String2List(Domain);
|
|
|
|
|
SelectedSource.ip = Utils.String2List(IP);
|
|
|
|
|
SelectedSource.process = Utils.String2List(Process);
|
2023-01-01 11:42:01 +00:00
|
|
|
|
}
|
|
|
|
|
SelectedSource.protocol = ProtocolItems?.ToList();
|
|
|
|
|
SelectedSource.inboundTag = InboundTagItems?.ToList();
|
|
|
|
|
|
2023-05-21 06:43:07 +00:00
|
|
|
|
bool hasRule = SelectedSource.domain?.Count > 0
|
|
|
|
|
|| SelectedSource.ip?.Count > 0
|
|
|
|
|
|| SelectedSource.protocol?.Count > 0
|
|
|
|
|
|| SelectedSource.process?.Count > 0
|
2024-03-26 06:26:03 +00:00
|
|
|
|
|| !Utils.IsNullOrEmpty(SelectedSource.port);
|
2023-01-01 11:42:01 +00:00
|
|
|
|
|
|
|
|
|
if (!hasRule)
|
|
|
|
|
{
|
2024-03-04 02:41:42 +00:00
|
|
|
|
_noticeHandler?.Enqueue(string.Format(ResUI.RoutingRuleDetailRequiredTips, "Port/Protocol/Domain/IP/Process"));
|
2023-01-01 11:42:01 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//_noticeHandler?.Enqueue(ResUI.OperationSuccess);
|
2024-08-10 06:44:25 +00:00
|
|
|
|
_updateView?.Invoke(EViewAction.CloseWindow, null);
|
2023-01-01 11:42:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-14 12:49:36 +00:00
|
|
|
|
}
|