mirror of
https://github.com/2dust/v2rayN.git
synced 2026-10-09 23:58:22 +03:00
Refactor models into sub-namespaces
Move many model classes into new sub-namespaces (ServiceLib.Models.CoreConfigs, ServiceLib.Models.Configs, ServiceLib.Models.Dto, ServiceLib.Models.Entities). Update GlobalUsings in ServiceLib, v2rayN.Desktop, v2rayN and add a tests GlobalUsings file to reference the new namespaces. Adjust static using directives in ClashApiManager and ClashProxiesViewModel to use ServiceLib.Models.Dto. This is a reorganization/rename of files and namespaces with no functional changes.
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
namespace ServiceLib.Models.Entities;
|
||||
|
||||
[Serializable]
|
||||
public class DNSItem
|
||||
{
|
||||
[PrimaryKey]
|
||||
public string Id { get; set; }
|
||||
|
||||
public string Remarks { get; set; }
|
||||
public bool Enabled { get; set; } = false;
|
||||
public ECoreType CoreType { get; set; }
|
||||
public bool UseSystemHosts { get; set; }
|
||||
public string? NormalDNS { get; set; }
|
||||
public string? TunDNS { get; set; }
|
||||
public string? DomainStrategy4Freedom { get; set; }
|
||||
public string? DomainDNSAddress { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace ServiceLib.Models.Entities;
|
||||
|
||||
[Serializable]
|
||||
public class FullConfigTemplateItem
|
||||
{
|
||||
[PrimaryKey]
|
||||
public string Id { get; set; }
|
||||
|
||||
public string Remarks { get; set; }
|
||||
public bool Enabled { get; set; } = false;
|
||||
public ECoreType CoreType { get; set; }
|
||||
public string? Config { get; set; }
|
||||
public string? TunConfig { get; set; }
|
||||
public bool? AddProxyOnly { get; set; } = false;
|
||||
public string? ProxyDetour { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace ServiceLib.Models.Entities;
|
||||
|
||||
[Serializable]
|
||||
public class ProfileExItem
|
||||
{
|
||||
[PrimaryKey]
|
||||
public string IndexId { get; set; }
|
||||
|
||||
public int Delay { get; set; }
|
||||
public decimal Speed { get; set; }
|
||||
public int Sort { get; set; }
|
||||
public string? Message { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace ServiceLib.Models.Entities;
|
||||
|
||||
[Obsolete("Use ProtocolExtraItem instead.")]
|
||||
[Serializable]
|
||||
public class ProfileGroupItem
|
||||
{
|
||||
[PrimaryKey]
|
||||
public string IndexId { get; set; }
|
||||
|
||||
public string ChildItems { get; set; }
|
||||
|
||||
public string? SubChildItems { get; set; }
|
||||
|
||||
public string? Filter { get; set; }
|
||||
|
||||
public EMultipleLoad MultipleLoad { get; set; } = EMultipleLoad.LeastPing;
|
||||
|
||||
public bool NotHasChild()
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(ChildItems) && string.IsNullOrWhiteSpace(SubChildItems);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
namespace ServiceLib.Models.Entities;
|
||||
|
||||
[Serializable]
|
||||
public class ProfileItem
|
||||
{
|
||||
private ProtocolExtraItem? _protocolExtraCache;
|
||||
private TransportExtraItem? _transportExtraCache;
|
||||
|
||||
public ProfileItem()
|
||||
{
|
||||
IndexId = string.Empty;
|
||||
ConfigType = EConfigType.VMess;
|
||||
ConfigVersion = 4;
|
||||
Subid = string.Empty;
|
||||
Address = string.Empty;
|
||||
Port = 0;
|
||||
Password = string.Empty;
|
||||
Username = string.Empty;
|
||||
Network = string.Empty;
|
||||
Remarks = string.Empty;
|
||||
StreamSecurity = string.Empty;
|
||||
AllowInsecure = string.Empty;
|
||||
}
|
||||
|
||||
#region function
|
||||
|
||||
public string GetSummary()
|
||||
{
|
||||
var summary = $"[{ConfigType.ToString()}] ";
|
||||
if (IsComplex())
|
||||
{
|
||||
summary += $"[{CoreType.ToString()}]{Remarks}";
|
||||
}
|
||||
else
|
||||
{
|
||||
var arrAddr = Address.Contains(':') ? Address.Split(':') : Address.Split('.');
|
||||
var addr = arrAddr.Length switch
|
||||
{
|
||||
> 2 => $"{arrAddr.First()}***{arrAddr.Last()}",
|
||||
> 1 => $"***{arrAddr.Last()}",
|
||||
_ => Address
|
||||
};
|
||||
summary += $"{Remarks}({addr}:{Port})";
|
||||
}
|
||||
return summary;
|
||||
}
|
||||
|
||||
public List<string>? GetAlpn()
|
||||
{
|
||||
return Alpn.IsNullOrEmpty() ? null : Utils.String2List(Alpn);
|
||||
}
|
||||
|
||||
public string GetNetwork()
|
||||
{
|
||||
if (Network.IsNullOrEmpty() || !Global.Networks.Contains(Network))
|
||||
{
|
||||
return Global.DefaultNetwork;
|
||||
}
|
||||
return Network.TrimEx();
|
||||
}
|
||||
|
||||
public bool IsComplex()
|
||||
{
|
||||
return ConfigType.IsComplexType();
|
||||
}
|
||||
|
||||
public bool IsValid()
|
||||
{
|
||||
if (IsComplex())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Address.IsNullOrEmpty() || Port is <= 0 or >= 65536)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (ConfigType)
|
||||
{
|
||||
case EConfigType.VMess:
|
||||
if (Password.IsNullOrEmpty() || !Utils.IsGuidByParse(Password))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case EConfigType.VLESS:
|
||||
if (Password.IsNullOrEmpty() || (!Utils.IsGuidByParse(Password) && Password.Length > 30))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Global.Flows.Contains(GetProtocolExtra().Flow ?? string.Empty))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case EConfigType.Shadowsocks:
|
||||
if (Password.IsNullOrEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(GetProtocolExtra().SsMethod)
|
||||
|| !Global.SsSecuritiesInSingbox.Contains(GetProtocolExtra().SsMethod))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if ((ConfigType is EConfigType.VLESS or EConfigType.Trojan)
|
||||
&& StreamSecurity == Global.StreamSecurityReality
|
||||
&& PublicKey.IsNullOrEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public ProtocolExtraItem GetProtocolExtra()
|
||||
{
|
||||
return _protocolExtraCache ??= JsonUtils.Deserialize<ProtocolExtraItem>(ProtoExtra) ?? new ProtocolExtraItem();
|
||||
}
|
||||
|
||||
public void SetProtocolExtra(ProtocolExtraItem extraItem)
|
||||
{
|
||||
_protocolExtraCache = extraItem;
|
||||
ProtoExtra = JsonUtils.Serialize(extraItem, false);
|
||||
}
|
||||
|
||||
public TransportExtraItem GetTransportExtra()
|
||||
{
|
||||
return _transportExtraCache ??= JsonUtils.Deserialize<TransportExtraItem>(TransportExtra) ?? new TransportExtraItem();
|
||||
}
|
||||
|
||||
public void SetTransportExtra(TransportExtraItem transportExtra)
|
||||
{
|
||||
_transportExtraCache = transportExtra;
|
||||
TransportExtra = JsonUtils.Serialize(transportExtra, false);
|
||||
}
|
||||
|
||||
#endregion function
|
||||
|
||||
[PrimaryKey]
|
||||
public string IndexId { get; set; }
|
||||
|
||||
public EConfigType ConfigType { get; set; }
|
||||
public ECoreType? CoreType { get; set; }
|
||||
public int ConfigVersion { get; set; }
|
||||
public string Subid { get; set; }
|
||||
public bool IsSub { get; set; } = true;
|
||||
public int? PreSocksPort { get; set; }
|
||||
public bool DisplayLog { get; set; } = true;
|
||||
public string Remarks { get; set; }
|
||||
public string Address { get; set; }
|
||||
public int Port { get; set; }
|
||||
public string Password { get; set; }
|
||||
public string Username { get; set; }
|
||||
public string Network { get; set; }
|
||||
|
||||
[Obsolete("Use TransportExtra.RawHeaderType/XhttpMode/GrpcMode/KcpHeaderType instead.")]
|
||||
public string HeaderType { get; set; }
|
||||
|
||||
[Obsolete("Use TransportExtra.Host/GrpcAuthority instead.")]
|
||||
public string RequestHost { get; set; }
|
||||
|
||||
[Obsolete("Use TransportExtra.Path/GrpcServiceName/KcpSeed instead.")]
|
||||
public string Path { get; set; }
|
||||
|
||||
public string StreamSecurity { get; set; }
|
||||
public string AllowInsecure { get; set; }
|
||||
public string Sni { get; set; }
|
||||
public string Alpn { get; set; } = string.Empty;
|
||||
public string Fingerprint { get; set; }
|
||||
public string PublicKey { get; set; }
|
||||
public string ShortId { get; set; }
|
||||
public string SpiderX { get; set; }
|
||||
public string Mldsa65Verify { get; set; }
|
||||
|
||||
[Obsolete("Use TransportExtra.XhttpExtra instead.")]
|
||||
public string Extra { get; set; }
|
||||
|
||||
public bool? MuxEnabled { get; set; }
|
||||
public string Cert { get; set; }
|
||||
public string CertSha { get; set; }
|
||||
public string EchConfigList { get; set; }
|
||||
public string Finalmask { get; set; }
|
||||
|
||||
public string ProtoExtra { get; set; }
|
||||
public string TransportExtra { get; set; }
|
||||
|
||||
[Obsolete("Use ProtocolExtraItem.Ports instead.")]
|
||||
public string Ports { get; set; }
|
||||
|
||||
[Obsolete("Use ProtocolExtraItem.AlterId instead.")]
|
||||
public int AlterId { get; set; }
|
||||
|
||||
[Obsolete("Use ProtocolExtraItem.Flow instead.")]
|
||||
public string Flow { get; set; }
|
||||
|
||||
[Obsolete("Use ProfileItem.Password instead.")]
|
||||
public string Id { get; set; }
|
||||
|
||||
[Obsolete("Use ProtocolExtraItem.xxx instead.")]
|
||||
public string Security { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
namespace ServiceLib.Models.Entities;
|
||||
|
||||
public record ProtocolExtraItem
|
||||
{
|
||||
public bool? Uot { get; init; }
|
||||
public string? CongestionControl { get; init; }
|
||||
|
||||
// vmess
|
||||
public string? AlterId { get; init; }
|
||||
public string? VmessSecurity { get; init; }
|
||||
|
||||
// vless
|
||||
public string? Flow { get; init; }
|
||||
public string? VlessEncryption { get; init; }
|
||||
//public string? VisionSeed { get; init; }
|
||||
|
||||
// shadowsocks
|
||||
//public string? PluginArgs { get; init; }
|
||||
public string? SsMethod { get; init; }
|
||||
|
||||
// wireguard
|
||||
public string? WgPublicKey { get; init; }
|
||||
public string? WgPresharedKey { get; init; }
|
||||
public string? WgInterfaceAddress { get; init; }
|
||||
public string? WgReserved { get; init; }
|
||||
public int? WgMtu { get; init; }
|
||||
|
||||
// hysteria2
|
||||
public string? SalamanderPass { get; init; }
|
||||
public int? UpMbps { get; init; }
|
||||
public int? DownMbps { get; init; }
|
||||
public string? Ports { get; init; }
|
||||
public string? HopInterval { get; init; }
|
||||
|
||||
// naiveproxy
|
||||
public int? InsecureConcurrency { get; init; }
|
||||
public bool? NaiveQuic { get; init; }
|
||||
|
||||
// group profile
|
||||
public string? GroupType { get; init; }
|
||||
public string? ChildItems { get; init; }
|
||||
public string? SubChildItems { get; init; }
|
||||
public string? Filter { get; init; }
|
||||
public EMultipleLoad? MultipleLoad { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
namespace ServiceLib.Models.Entities;
|
||||
|
||||
[Serializable]
|
||||
public class RoutingItem
|
||||
{
|
||||
[PrimaryKey]
|
||||
public string Id { get; set; }
|
||||
|
||||
public string Remarks { get; set; }
|
||||
public string Url { get; set; }
|
||||
public string RuleSet { get; set; }
|
||||
public int RuleNum { get; set; }
|
||||
public bool Enabled { get; set; } = true;
|
||||
public bool Locked { get; set; }
|
||||
public string CustomIcon { get; set; }
|
||||
public string CustomRulesetPath4Singbox { get; set; }
|
||||
public string DomainStrategy { get; set; }
|
||||
public string DomainStrategy4Singbox { get; set; }
|
||||
public int Sort { get; set; }
|
||||
public bool IsActive { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace ServiceLib.Models.Entities;
|
||||
|
||||
[Serializable]
|
||||
public class RulesItem
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string? Type { get; set; }
|
||||
public string? Port { get; set; }
|
||||
public string? Network { get; set; }
|
||||
public List<string>? InboundTag { get; set; }
|
||||
public string? OutboundTag { get; set; }
|
||||
public List<string>? Ip { get; set; }
|
||||
public List<string>? Domain { get; set; }
|
||||
public List<string>? Protocol { get; set; }
|
||||
public List<string>? Process { get; set; }
|
||||
public bool Enabled { get; set; } = true;
|
||||
public string? Remarks { get; set; }
|
||||
public ERuleType? RuleType { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
namespace ServiceLib.Models.Entities;
|
||||
|
||||
[Serializable]
|
||||
public class ServerStatItem
|
||||
{
|
||||
[PrimaryKey]
|
||||
public string IndexId { get; set; }
|
||||
|
||||
public long TotalUp { get; set; }
|
||||
|
||||
public long TotalDown { get; set; }
|
||||
|
||||
public long TodayUp { get; set; }
|
||||
|
||||
public long TodayDown { get; set; }
|
||||
|
||||
public long DateNow { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
namespace ServiceLib.Models.Entities;
|
||||
|
||||
[Serializable]
|
||||
public class SubItem
|
||||
{
|
||||
[PrimaryKey]
|
||||
public string Id { get; set; }
|
||||
|
||||
public string Remarks { get; set; }
|
||||
|
||||
public string Url { get; set; }
|
||||
|
||||
public string MoreUrl { get; set; }
|
||||
|
||||
public bool Enabled { get; set; } = true;
|
||||
|
||||
public string UserAgent { get; set; } = string.Empty;
|
||||
|
||||
public int Sort { get; set; }
|
||||
|
||||
public string? Filter { get; set; }
|
||||
|
||||
public int AutoUpdateInterval { get; set; }
|
||||
|
||||
public long UpdateTime { get; set; }
|
||||
|
||||
public string? ConvertTarget { get; set; }
|
||||
|
||||
public string? PrevProfile { get; set; }
|
||||
|
||||
public string? NextProfile { get; set; }
|
||||
|
||||
public int? PreSocksPort { get; set; }
|
||||
|
||||
public string? Memo { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace ServiceLib.Models.Entities;
|
||||
|
||||
public record TransportExtraItem
|
||||
{
|
||||
public string? RawHeaderType { get; init; }
|
||||
|
||||
public string? Host { get; init; }
|
||||
public string? Path { get; init; }
|
||||
public string? XhttpMode { get; init; }
|
||||
public string? XhttpExtra { get; init; }
|
||||
|
||||
public string? GrpcAuthority { get; init; }
|
||||
public string? GrpcServiceName { get; init; }
|
||||
public string? GrpcMode { get; init; }
|
||||
|
||||
public string? KcpHeaderType { get; init; }
|
||||
public string? KcpSeed { get; init; }
|
||||
public int? KcpMtu { get; init; }
|
||||
}
|
||||
Reference in New Issue
Block a user