mirror of https://github.com/2dust/v2rayN
Refactor some service
parent
3bdef4d6d8
commit
d5c6a42a9a
|
@ -36,7 +36,7 @@ namespace ServiceLib.Common
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
using var downloader = new DownloadService(downloadOpt);
|
using var downloader = new Downloader.DownloadService(downloadOpt);
|
||||||
downloader.DownloadFileCompleted += (sender, value) =>
|
downloader.DownloadFileCompleted += (sender, value) =>
|
||||||
{
|
{
|
||||||
if (value.Error != null)
|
if (value.Error != null)
|
||||||
|
@ -76,7 +76,7 @@ namespace ServiceLib.Common
|
||||||
int totalSecond = 0;
|
int totalSecond = 0;
|
||||||
var hasValue = false;
|
var hasValue = false;
|
||||||
double maxSpeed = 0;
|
double maxSpeed = 0;
|
||||||
using var downloader = new DownloadService(downloadOpt);
|
using var downloader = new Downloader.DownloadService(downloadOpt);
|
||||||
//downloader.DownloadStarted += (sender, value) =>
|
//downloader.DownloadStarted += (sender, value) =>
|
||||||
//{
|
//{
|
||||||
// if (progress != null)
|
// if (progress != null)
|
||||||
|
@ -145,7 +145,7 @@ namespace ServiceLib.Common
|
||||||
|
|
||||||
var progressPercentage = 0;
|
var progressPercentage = 0;
|
||||||
var hasValue = false;
|
var hasValue = false;
|
||||||
using var downloader = new DownloadService(downloadOpt);
|
using var downloader = new Downloader.DownloadService(downloadOpt);
|
||||||
downloader.DownloadStarted += (sender, value) =>
|
downloader.DownloadStarted += (sender, value) =>
|
||||||
{
|
{
|
||||||
progress?.Report(0);
|
progress?.Report(0);
|
||||||
|
|
|
@ -2,8 +2,9 @@
|
||||||
global using ServiceLib.Common;
|
global using ServiceLib.Common;
|
||||||
global using ServiceLib.Enums;
|
global using ServiceLib.Enums;
|
||||||
global using ServiceLib.Handler;
|
global using ServiceLib.Handler;
|
||||||
global using ServiceLib.Handler.CoreConfig;
|
|
||||||
global using ServiceLib.Handler.Fmt;
|
global using ServiceLib.Handler.Fmt;
|
||||||
global using ServiceLib.Handler.Statistics;
|
global using ServiceLib.Services;
|
||||||
|
global using ServiceLib.Services.Statistics;
|
||||||
|
global using ServiceLib.Services.CoreConfig;
|
||||||
global using ServiceLib.Models;
|
global using ServiceLib.Models;
|
||||||
global using ServiceLib.Resx;
|
global using ServiceLib.Resx;
|
|
@ -1,4 +1,6 @@
|
||||||
namespace ServiceLib.Handler.CoreConfig
|
using ServiceLib.Services.CoreConfig;
|
||||||
|
|
||||||
|
namespace ServiceLib.Handler
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Core configuration file processing class
|
/// Core configuration file processing class
|
||||||
|
@ -20,14 +22,14 @@
|
||||||
msg = ResUI.InitialConfiguration;
|
msg = ResUI.InitialConfiguration;
|
||||||
if (node.configType == EConfigType.Custom)
|
if (node.configType == EConfigType.Custom)
|
||||||
{
|
{
|
||||||
if (node.coreType is ECoreType.mihomo)
|
if (node.coreType is ECoreType.mihomo)
|
||||||
{
|
{
|
||||||
var configGenClash = new CoreConfigClash(config);
|
var configGenClash = new CoreConfigClashService(config);
|
||||||
return configGenClash.GenerateClientCustomConfig(node, fileName, out msg);
|
return configGenClash.GenerateClientCustomConfig(node, fileName, out msg);
|
||||||
}
|
}
|
||||||
if (node.coreType is ECoreType.sing_box)
|
if (node.coreType is ECoreType.sing_box)
|
||||||
{
|
{
|
||||||
var configGenSingbox = new CoreConfigSingbox(config);
|
var configGenSingbox = new CoreConfigSingboxService(config);
|
||||||
return configGenSingbox.GenerateClientCustomConfig(node, fileName, out msg);
|
return configGenSingbox.GenerateClientCustomConfig(node, fileName, out msg);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -37,7 +39,7 @@
|
||||||
}
|
}
|
||||||
else if (AppHandler.Instance.GetCoreType(node, node.configType) == ECoreType.sing_box)
|
else if (AppHandler.Instance.GetCoreType(node, node.configType) == ECoreType.sing_box)
|
||||||
{
|
{
|
||||||
var configGenSingbox = new CoreConfigSingbox(config);
|
var configGenSingbox = new CoreConfigSingboxService(config);
|
||||||
if (configGenSingbox.GenerateClientConfigContent(node, out SingboxConfig? singboxConfig, out msg) != 0)
|
if (configGenSingbox.GenerateClientConfigContent(node, out SingboxConfig? singboxConfig, out msg) != 0)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -53,7 +55,7 @@
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var coreConfigV2ray = new CoreConfigV2ray(config);
|
var coreConfigV2ray = new CoreConfigV2rayService(config);
|
||||||
if (coreConfigV2ray.GenerateClientConfigContent(node, out V2rayConfig? v2rayConfig, out msg) != 0)
|
if (coreConfigV2ray.GenerateClientConfigContent(node, out V2rayConfig? v2rayConfig, out msg) != 0)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -128,7 +130,7 @@
|
||||||
{
|
{
|
||||||
if (coreType == ECoreType.sing_box)
|
if (coreType == ECoreType.sing_box)
|
||||||
{
|
{
|
||||||
if (new CoreConfigSingbox(config).GenerateClientSpeedtestConfig(selecteds, out SingboxConfig? singboxConfig, out msg) != 0)
|
if (new CoreConfigSingboxService(config).GenerateClientSpeedtestConfig(selecteds, out SingboxConfig? singboxConfig, out msg) != 0)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -136,7 +138,7 @@
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (new CoreConfigV2ray(config).GenerateClientSpeedtestConfig(selecteds, out V2rayConfig? v2rayConfig, out msg) != 0)
|
if (new CoreConfigV2rayService(config).GenerateClientSpeedtestConfig(selecteds, out V2rayConfig? v2rayConfig, out msg) != 0)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -150,7 +152,7 @@
|
||||||
msg = ResUI.CheckServerSettings;
|
msg = ResUI.CheckServerSettings;
|
||||||
if (coreType == ECoreType.sing_box)
|
if (coreType == ECoreType.sing_box)
|
||||||
{
|
{
|
||||||
if (new CoreConfigSingbox(config).GenerateClientMultipleLoadConfig(selecteds, out SingboxConfig? singboxConfig, out msg) != 0)
|
if (new CoreConfigSingboxService(config).GenerateClientMultipleLoadConfig(selecteds, out SingboxConfig? singboxConfig, out msg) != 0)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -158,7 +160,7 @@
|
||||||
}
|
}
|
||||||
else if (coreType == ECoreType.Xray)
|
else if (coreType == ECoreType.Xray)
|
||||||
{
|
{
|
||||||
if (new CoreConfigV2ray(config).GenerateClientMultipleLoadConfig(selecteds, out V2rayConfig? v2rayConfig, out msg) != 0)
|
if (new CoreConfigV2rayService(config).GenerateClientMultipleLoadConfig(selecteds, out V2rayConfig? v2rayConfig, out msg) != 0)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
|
@ -1,4 +1,6 @@
|
||||||
namespace ServiceLib.Handler.Statistics
|
using ServiceLib.Services.Statistics;
|
||||||
|
|
||||||
|
namespace ServiceLib.Handler
|
||||||
{
|
{
|
||||||
public class StatisticsHandler
|
public class StatisticsHandler
|
||||||
{
|
{
|
||||||
|
@ -9,8 +11,8 @@
|
||||||
private ServerStatItem? _serverStatItem;
|
private ServerStatItem? _serverStatItem;
|
||||||
private List<ServerStatItem> _lstServerStat;
|
private List<ServerStatItem> _lstServerStat;
|
||||||
private Action<ServerSpeedItem> _updateFunc;
|
private Action<ServerSpeedItem> _updateFunc;
|
||||||
private StatisticsV2ray? _statisticsV2Ray;
|
private StatisticsV2rayService? _statisticsV2Ray;
|
||||||
private StatisticsSingbox? _statisticsSingbox;
|
private StatisticsSingboxService? _statisticsSingbox;
|
||||||
|
|
||||||
public List<ServerStatItem> ServerStat => _lstServerStat;
|
public List<ServerStatItem> ServerStat => _lstServerStat;
|
||||||
|
|
||||||
|
@ -25,8 +27,8 @@
|
||||||
|
|
||||||
InitData();
|
InitData();
|
||||||
|
|
||||||
_statisticsV2Ray = new StatisticsV2ray(config, UpdateServerStat);
|
_statisticsV2Ray = new StatisticsV2rayService(config, UpdateServerStat);
|
||||||
_statisticsSingbox = new StatisticsSingbox(config, UpdateServerStat);
|
_statisticsSingbox = new StatisticsSingboxService(config, UpdateServerStat);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Close()
|
public void Close()
|
|
@ -1,4 +1,6 @@
|
||||||
namespace ServiceLib.Handler
|
using ServiceLib.Services;
|
||||||
|
|
||||||
|
namespace ServiceLib.Handler
|
||||||
{
|
{
|
||||||
public class TaskHandler
|
public class TaskHandler
|
||||||
{
|
{
|
||||||
|
@ -20,7 +22,7 @@
|
||||||
await Task.Delay(60000);
|
await Task.Delay(60000);
|
||||||
Logging.SaveLog("UpdateTaskRunSubscription");
|
Logging.SaveLog("UpdateTaskRunSubscription");
|
||||||
|
|
||||||
var updateHandle = new UpdateHandler();
|
var updateHandle = new UpdateService();
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
var updateTime = ((DateTimeOffset)DateTime.Now).ToUnixTimeSeconds();
|
var updateTime = ((DateTimeOffset)DateTime.Now).ToUnixTimeSeconds();
|
||||||
|
@ -53,7 +55,7 @@
|
||||||
//await Task.Delay(1000 * 120);
|
//await Task.Delay(1000 * 120);
|
||||||
Logging.SaveLog("UpdateTaskRunGeo");
|
Logging.SaveLog("UpdateTaskRunGeo");
|
||||||
|
|
||||||
var updateHandle = new UpdateHandler();
|
var updateHandle = new UpdateService();
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
await Task.Delay(1000 * 3600);
|
await Task.Delay(1000 * 3600);
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
namespace ServiceLib.Handler.CoreConfig
|
namespace ServiceLib.Services.CoreConfig
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Core configuration file processing class
|
/// Core configuration file processing class
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class CoreConfigClash
|
public class CoreConfigClashService
|
||||||
{
|
{
|
||||||
private Config _config;
|
private Config _config;
|
||||||
|
|
||||||
public CoreConfigClash(Config config)
|
public CoreConfigClashService(Config config)
|
||||||
{
|
{
|
||||||
_config = config;
|
_config = config;
|
||||||
}
|
}
|
|
@ -2,13 +2,13 @@
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.NetworkInformation;
|
using System.Net.NetworkInformation;
|
||||||
|
|
||||||
namespace ServiceLib.Handler.CoreConfig
|
namespace ServiceLib.Services.CoreConfig
|
||||||
{
|
{
|
||||||
public class CoreConfigSingbox
|
public class CoreConfigSingboxService
|
||||||
{
|
{
|
||||||
private Config _config;
|
private Config _config;
|
||||||
|
|
||||||
public CoreConfigSingbox(Config config)
|
public CoreConfigSingboxService(Config config)
|
||||||
{
|
{
|
||||||
_config = config;
|
_config = config;
|
||||||
}
|
}
|
||||||
|
@ -192,7 +192,7 @@ namespace ServiceLib.Handler.CoreConfig
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ((it.configType is EConfigType.VLESS or EConfigType.Trojan)
|
if (it.configType is EConfigType.VLESS or EConfigType.Trojan
|
||||||
&& item.streamSecurity == Global.StreamSecurityReality
|
&& item.streamSecurity == Global.StreamSecurityReality
|
||||||
&& item.publicKey.IsNullOrEmpty())
|
&& item.publicKey.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
|
@ -476,7 +476,7 @@ namespace ServiceLib.Handler.CoreConfig
|
||||||
singboxConfig.inbounds = [];
|
singboxConfig.inbounds = [];
|
||||||
|
|
||||||
if (!_config.tunModeItem.enableTun
|
if (!_config.tunModeItem.enableTun
|
||||||
|| (_config.tunModeItem.enableTun && _config.tunModeItem.enableExInbound && _config.runningCoreType == ECoreType.sing_box))
|
|| _config.tunModeItem.enableTun && _config.tunModeItem.enableExInbound && _config.runningCoreType == ECoreType.sing_box)
|
||||||
{
|
{
|
||||||
var inbound = new Inbound4Sbox()
|
var inbound = new Inbound4Sbox()
|
||||||
{
|
{
|
|
@ -2,13 +2,13 @@
|
||||||
using System.Net.NetworkInformation;
|
using System.Net.NetworkInformation;
|
||||||
using System.Text.Json.Nodes;
|
using System.Text.Json.Nodes;
|
||||||
|
|
||||||
namespace ServiceLib.Handler.CoreConfig
|
namespace ServiceLib.Services.CoreConfig
|
||||||
{
|
{
|
||||||
public class CoreConfigV2ray
|
public class CoreConfigV2rayService
|
||||||
{
|
{
|
||||||
private Config _config;
|
private Config _config;
|
||||||
|
|
||||||
public CoreConfigV2ray(Config config)
|
public CoreConfigV2rayService(Config config)
|
||||||
{
|
{
|
||||||
_config = config;
|
_config = config;
|
||||||
}
|
}
|
||||||
|
@ -308,7 +308,7 @@ namespace ServiceLib.Handler.CoreConfig
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ((it.configType is EConfigType.VLESS or EConfigType.Trojan)
|
if (it.configType is EConfigType.VLESS or EConfigType.Trojan
|
||||||
&& item.streamSecurity == Global.StreamSecurityReality
|
&& item.streamSecurity == Global.StreamSecurityReality
|
||||||
&& item.publicKey.IsNullOrEmpty())
|
&& item.publicKey.IsNullOrEmpty())
|
||||||
{
|
{
|
|
@ -3,12 +3,12 @@ using System.Net;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
|
|
||||||
namespace ServiceLib.Handler
|
namespace ServiceLib.Services
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///Download
|
///Download
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class DownloadHandler
|
public class DownloadService
|
||||||
{
|
{
|
||||||
public event EventHandler<ResultEventArgs>? UpdateCompleted;
|
public event EventHandler<ResultEventArgs>? UpdateCompleted;
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
|
|
||||||
namespace ServiceLib.Handler
|
namespace ServiceLib.Services
|
||||||
{
|
{
|
||||||
public class SpeedtestHandler
|
public class SpeedtestService
|
||||||
{
|
{
|
||||||
private Config? _config;
|
private Config? _config;
|
||||||
private CoreHandler _coreHandler;
|
private CoreHandler _coreHandler;
|
||||||
|
@ -13,7 +13,7 @@ namespace ServiceLib.Handler
|
||||||
private Action<SpeedTestResult> _updateFunc;
|
private Action<SpeedTestResult> _updateFunc;
|
||||||
private bool _exitLoop = false;
|
private bool _exitLoop = false;
|
||||||
|
|
||||||
public SpeedtestHandler(Config config, CoreHandler coreHandler, List<ProfileItem> selecteds, ESpeedActionType actionType, Action<SpeedTestResult> update)
|
public SpeedtestService(Config config, CoreHandler coreHandler, List<ProfileItem> selecteds, ESpeedActionType actionType, Action<SpeedTestResult> update)
|
||||||
{
|
{
|
||||||
_config = config;
|
_config = config;
|
||||||
_coreHandler = coreHandler;
|
_coreHandler = coreHandler;
|
||||||
|
@ -144,7 +144,7 @@ namespace ServiceLib.Handler
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
DownloadHandler downloadHandle = new DownloadHandler();
|
DownloadService downloadHandle = new DownloadService();
|
||||||
|
|
||||||
List<Task> tasks = new();
|
List<Task> tasks = new();
|
||||||
foreach (var it in _selecteds)
|
foreach (var it in _selecteds)
|
||||||
|
@ -211,7 +211,7 @@ namespace ServiceLib.Handler
|
||||||
string url = _config.speedTestItem.speedTestUrl;
|
string url = _config.speedTestItem.speedTestUrl;
|
||||||
var timeout = _config.speedTestItem.speedTestTimeout;
|
var timeout = _config.speedTestItem.speedTestTimeout;
|
||||||
|
|
||||||
DownloadHandler downloadHandle = new();
|
DownloadService downloadHandle = new();
|
||||||
|
|
||||||
foreach (var it in _selecteds)
|
foreach (var it in _selecteds)
|
||||||
{
|
{
|
||||||
|
@ -241,7 +241,7 @@ namespace ServiceLib.Handler
|
||||||
|
|
||||||
WebProxy webProxy = new(Global.Loopback, it.port);
|
WebProxy webProxy = new(Global.Loopback, it.port);
|
||||||
|
|
||||||
await downloadHandle.DownloadDataAsync(url, webProxy, timeout, (bool success, string msg) =>
|
await downloadHandle.DownloadDataAsync(url, webProxy, timeout, (success, msg) =>
|
||||||
{
|
{
|
||||||
decimal.TryParse(msg, out decimal dec);
|
decimal.TryParse(msg, out decimal dec);
|
||||||
if (dec > 0)
|
if (dec > 0)
|
||||||
|
@ -273,7 +273,7 @@ namespace ServiceLib.Handler
|
||||||
string url = _config.speedTestItem.speedTestUrl;
|
string url = _config.speedTestItem.speedTestUrl;
|
||||||
var timeout = _config.speedTestItem.speedTestTimeout;
|
var timeout = _config.speedTestItem.speedTestTimeout;
|
||||||
|
|
||||||
DownloadHandler downloadHandle = new();
|
DownloadService downloadHandle = new();
|
||||||
|
|
||||||
foreach (var it in _selecteds)
|
foreach (var it in _selecteds)
|
||||||
{
|
{
|
||||||
|
@ -303,7 +303,7 @@ namespace ServiceLib.Handler
|
||||||
if (item is null) continue;
|
if (item is null) continue;
|
||||||
|
|
||||||
WebProxy webProxy = new(Global.Loopback, it.port);
|
WebProxy webProxy = new(Global.Loopback, it.port);
|
||||||
_ = downloadHandle.DownloadDataAsync(url, webProxy, timeout, (bool success, string msg) =>
|
_ = downloadHandle.DownloadDataAsync(url, webProxy, timeout, (success, msg) =>
|
||||||
{
|
{
|
||||||
decimal.TryParse(msg, out decimal dec);
|
decimal.TryParse(msg, out decimal dec);
|
||||||
if (dec > 0)
|
if (dec > 0)
|
||||||
|
@ -334,7 +334,7 @@ namespace ServiceLib.Handler
|
||||||
await RunSpeedTestMulti();
|
await RunSpeedTestMulti();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<string> GetRealPingTime(DownloadHandler downloadHandle, IWebProxy webProxy)
|
private async Task<string> GetRealPingTime(DownloadService downloadHandle, IWebProxy webProxy)
|
||||||
{
|
{
|
||||||
int responseTime = await downloadHandle.GetRealPingTime(_config.speedTestItem.speedPingTestUrl, webProxy, 10);
|
int responseTime = await downloadHandle.GetRealPingTime(_config.speedTestItem.speedPingTestUrl, webProxy, 10);
|
||||||
//string output = Utile.IsNullOrEmpty(status) ? FormatOut(responseTime, "ms") : status;
|
//string output = Utile.IsNullOrEmpty(status) ? FormatOut(responseTime, "ms") : status;
|
||||||
|
@ -349,7 +349,7 @@ namespace ServiceLib.Handler
|
||||||
{
|
{
|
||||||
if (!IPAddress.TryParse(url, out IPAddress? ipAddress))
|
if (!IPAddress.TryParse(url, out IPAddress? ipAddress))
|
||||||
{
|
{
|
||||||
IPHostEntry ipHostInfo = System.Net.Dns.GetHostEntry(url);
|
IPHostEntry ipHostInfo = Dns.GetHostEntry(url);
|
||||||
ipAddress = ipHostInfo.AddressList[0];
|
ipAddress = ipHostInfo.AddressList[0];
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
using System.Net.WebSockets;
|
using System.Net.WebSockets;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace ServiceLib.Handler.Statistics
|
namespace ServiceLib.Services.Statistics
|
||||||
{
|
{
|
||||||
public class StatisticsSingbox
|
public class StatisticsSingboxService
|
||||||
{
|
{
|
||||||
private Config _config;
|
private Config _config;
|
||||||
private bool _exitFlag;
|
private bool _exitFlag;
|
||||||
|
@ -11,7 +11,7 @@ namespace ServiceLib.Handler.Statistics
|
||||||
private string url = string.Empty;
|
private string url = string.Empty;
|
||||||
private Action<ServerSpeedItem> _updateFunc;
|
private Action<ServerSpeedItem> _updateFunc;
|
||||||
|
|
||||||
public StatisticsSingbox(Config config, Action<ServerSpeedItem> update)
|
public StatisticsSingboxService(Config config, Action<ServerSpeedItem> update)
|
||||||
{
|
{
|
||||||
_config = config;
|
_config = config;
|
||||||
_updateFunc = update;
|
_updateFunc = update;
|
||||||
|
@ -63,7 +63,7 @@ namespace ServiceLib.Handler.Statistics
|
||||||
await Task.Delay(1000);
|
await Task.Delay(1000);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!(_config.IsRunningCore(ECoreType.sing_box)))
|
if (!_config.IsRunningCore(ECoreType.sing_box))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
|
@ -2,9 +2,9 @@
|
||||||
using Grpc.Net.Client;
|
using Grpc.Net.Client;
|
||||||
using ProtosLib.Statistics;
|
using ProtosLib.Statistics;
|
||||||
|
|
||||||
namespace ServiceLib.Handler.Statistics
|
namespace ServiceLib.Services.Statistics
|
||||||
{
|
{
|
||||||
public class StatisticsV2ray
|
public class StatisticsV2rayService
|
||||||
{
|
{
|
||||||
private Models.Config _config;
|
private Models.Config _config;
|
||||||
private GrpcChannel? _channel;
|
private GrpcChannel? _channel;
|
||||||
|
@ -12,7 +12,7 @@ namespace ServiceLib.Handler.Statistics
|
||||||
private bool _exitFlag;
|
private bool _exitFlag;
|
||||||
private Action<ServerSpeedItem> _updateFunc;
|
private Action<ServerSpeedItem> _updateFunc;
|
||||||
|
|
||||||
public StatisticsV2ray(Models.Config config, Action<ServerSpeedItem> update)
|
public StatisticsV2rayService(Models.Config config, Action<ServerSpeedItem> update)
|
||||||
{
|
{
|
||||||
_config = config;
|
_config = config;
|
||||||
_updateFunc = update;
|
_updateFunc = update;
|
||||||
|
@ -51,7 +51,7 @@ namespace ServiceLib.Handler.Statistics
|
||||||
await Task.Delay(1000);
|
await Task.Delay(1000);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!(_config.IsRunningCore(ECoreType.Xray)))
|
if (!_config.IsRunningCore(ECoreType.Xray))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
|
@ -3,9 +3,9 @@ using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace ServiceLib.Handler
|
namespace ServiceLib.Services
|
||||||
{
|
{
|
||||||
public class UpdateHandler
|
public class UpdateService
|
||||||
{
|
{
|
||||||
private Action<bool, string> _updateFunc;
|
private Action<bool, string> _updateFunc;
|
||||||
private Config _config;
|
private Config _config;
|
||||||
|
@ -32,7 +32,7 @@ namespace ServiceLib.Handler
|
||||||
var url = string.Empty;
|
var url = string.Empty;
|
||||||
var fileName = string.Empty;
|
var fileName = string.Empty;
|
||||||
|
|
||||||
DownloadHandler downloadHandle = new();
|
DownloadService downloadHandle = new();
|
||||||
downloadHandle.UpdateCompleted += (sender2, args) =>
|
downloadHandle.UpdateCompleted += (sender2, args) =>
|
||||||
{
|
{
|
||||||
if (args.Success)
|
if (args.Success)
|
||||||
|
@ -74,7 +74,7 @@ namespace ServiceLib.Handler
|
||||||
var url = string.Empty;
|
var url = string.Empty;
|
||||||
var fileName = string.Empty;
|
var fileName = string.Empty;
|
||||||
|
|
||||||
DownloadHandler downloadHandle = new();
|
DownloadService downloadHandle = new();
|
||||||
downloadHandle.UpdateCompleted += (sender2, args) =>
|
downloadHandle.UpdateCompleted += (sender2, args) =>
|
||||||
{
|
{
|
||||||
if (args.Success)
|
if (args.Success)
|
||||||
|
@ -110,7 +110,7 @@ namespace ServiceLib.Handler
|
||||||
|
|
||||||
url = args.Url;
|
url = args.Url;
|
||||||
var ext = Path.GetExtension(url);
|
var ext = Path.GetExtension(url);
|
||||||
fileName = Utils.GetTempPath(Utils.GetGUID()+ ext);
|
fileName = Utils.GetTempPath(Utils.GetGUID() + ext);
|
||||||
await downloadHandle.DownloadFileAsync(url, fileName, true, _timeout);
|
await downloadHandle.DownloadFileAsync(url, fileName, true, _timeout);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -144,7 +144,7 @@ namespace ServiceLib.Handler
|
||||||
string url = item.url.TrimEx();
|
string url = item.url.TrimEx();
|
||||||
string userAgent = item.userAgent.TrimEx();
|
string userAgent = item.userAgent.TrimEx();
|
||||||
string hashCode = $"{item.remarks}->";
|
string hashCode = $"{item.remarks}->";
|
||||||
if (Utils.IsNullOrEmpty(id) || Utils.IsNullOrEmpty(url) || (Utils.IsNotEmpty(subId) && item.id != subId))
|
if (Utils.IsNullOrEmpty(id) || Utils.IsNullOrEmpty(url) || Utils.IsNotEmpty(subId) && item.id != subId)
|
||||||
{
|
{
|
||||||
//_updateFunc(false, $"{hashCode}{ResUI.MsgNoValidSubscription}");
|
//_updateFunc(false, $"{hashCode}{ResUI.MsgNoValidSubscription}");
|
||||||
continue;
|
continue;
|
||||||
|
@ -159,7 +159,7 @@ namespace ServiceLib.Handler
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var downloadHandle = new DownloadHandler();
|
var downloadHandle = new DownloadService();
|
||||||
downloadHandle.Error += (sender2, args) =>
|
downloadHandle.Error += (sender2, args) =>
|
||||||
{
|
{
|
||||||
_updateFunc(false, $"{hashCode}{args.GetException().Message}");
|
_updateFunc(false, $"{hashCode}{args.GetException().Message}");
|
||||||
|
@ -264,13 +264,13 @@ namespace ServiceLib.Handler
|
||||||
|
|
||||||
public async Task RunAvailabilityCheck(Action<bool, string> update)
|
public async Task RunAvailabilityCheck(Action<bool, string> update)
|
||||||
{
|
{
|
||||||
var time = await (new DownloadHandler()).RunAvailabilityCheck(null);
|
var time = await new DownloadService().RunAvailabilityCheck(null);
|
||||||
update(false, string.Format(ResUI.TestMeOutput, time));
|
update(false, string.Format(ResUI.TestMeOutput, time));
|
||||||
}
|
}
|
||||||
|
|
||||||
#region private
|
#region private
|
||||||
|
|
||||||
private async Task<ResultEventArgs> CheckUpdateAsync(DownloadHandler downloadHandle, ECoreType type, bool preRelease)
|
private async Task<ResultEventArgs> CheckUpdateAsync(DownloadService downloadHandle, ECoreType type, bool preRelease)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -465,7 +465,7 @@ namespace ServiceLib.Handler
|
||||||
var url = string.Format(Global.GeoUrl, geoName);
|
var url = string.Format(Global.GeoUrl, geoName);
|
||||||
var fileName = Utils.GetTempPath(Utils.GetGUID());
|
var fileName = Utils.GetTempPath(Utils.GetGUID());
|
||||||
|
|
||||||
DownloadHandler downloadHandle = new();
|
DownloadService downloadHandle = new();
|
||||||
downloadHandle.UpdateCompleted += (sender2, args) =>
|
downloadHandle.UpdateCompleted += (sender2, args) =>
|
||||||
{
|
{
|
||||||
if (args.Success)
|
if (args.Success)
|
|
@ -141,7 +141,7 @@ namespace ServiceLib.ViewModels
|
||||||
UpdatedPlusPlus(_geo, "");
|
UpdatedPlusPlus(_geo, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await (new UpdateHandler()).UpdateGeoFileAll(_config, _updateUI)
|
await (new UpdateService()).UpdateGeoFileAll(_config, _updateUI)
|
||||||
.ContinueWith(t =>
|
.ContinueWith(t =>
|
||||||
{
|
{
|
||||||
UpdatedPlusPlus(_geo, "");
|
UpdatedPlusPlus(_geo, "");
|
||||||
|
@ -169,7 +169,7 @@ namespace ServiceLib.ViewModels
|
||||||
UpdatedPlusPlus(_v2rayN, msg);
|
UpdatedPlusPlus(_v2rayN, msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await (new UpdateHandler()).CheckUpdateGuiN(_config, _updateUI, preRelease)
|
await (new UpdateService()).CheckUpdateGuiN(_config, _updateUI, preRelease)
|
||||||
.ContinueWith(t =>
|
.ContinueWith(t =>
|
||||||
{
|
{
|
||||||
UpdatedPlusPlus(_v2rayN, "");
|
UpdatedPlusPlus(_v2rayN, "");
|
||||||
|
@ -189,7 +189,7 @@ namespace ServiceLib.ViewModels
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var type = (ECoreType)Enum.Parse(typeof(ECoreType), item.coreType);
|
var type = (ECoreType)Enum.Parse(typeof(ECoreType), item.coreType);
|
||||||
await (new UpdateHandler()).CheckUpdateCore(type, _config, _updateUI, preRelease)
|
await (new UpdateService()).CheckUpdateCore(type, _config, _updateUI, preRelease)
|
||||||
.ContinueWith(t =>
|
.ContinueWith(t =>
|
||||||
{
|
{
|
||||||
UpdatedPlusPlus(item.coreType, "");
|
UpdatedPlusPlus(item.coreType, "");
|
||||||
|
|
|
@ -629,7 +629,7 @@ namespace ServiceLib.ViewModels
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await (new UpdateHandler()).RunAvailabilityCheck(async (bool success, string msg) =>
|
await (new UpdateService()).RunAvailabilityCheck(async (bool success, string msg) =>
|
||||||
{
|
{
|
||||||
_noticeHandler?.SendMessageEx(msg);
|
_noticeHandler?.SendMessageEx(msg);
|
||||||
await _updateView?.Invoke(EViewAction.DispatcherServerAvailability, msg);
|
await _updateView?.Invoke(EViewAction.DispatcherServerAvailability, msg);
|
||||||
|
@ -655,7 +655,7 @@ namespace ServiceLib.ViewModels
|
||||||
|
|
||||||
public void UpdateSubscriptionProcess(string subId, bool blProxy)
|
public void UpdateSubscriptionProcess(string subId, bool blProxy)
|
||||||
{
|
{
|
||||||
(new UpdateHandler()).UpdateSubscriptionProcess(_config, subId, blProxy, UpdateTaskHandler);
|
(new UpdateService()).UpdateSubscriptionProcess(_config, subId, blProxy, UpdateTaskHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion Subscription
|
#endregion Subscription
|
||||||
|
|
|
@ -2,6 +2,7 @@ using DynamicData;
|
||||||
using DynamicData.Binding;
|
using DynamicData.Binding;
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
using ReactiveUI.Fody.Helpers;
|
using ReactiveUI.Fody.Helpers;
|
||||||
|
using ServiceLib.Services;
|
||||||
using Splat;
|
using Splat;
|
||||||
using System.Reactive;
|
using System.Reactive;
|
||||||
using System.Reactive.Linq;
|
using System.Reactive.Linq;
|
||||||
|
@ -17,7 +18,7 @@ namespace ServiceLib.ViewModels
|
||||||
private string _serverFilter = string.Empty;
|
private string _serverFilter = string.Empty;
|
||||||
|
|
||||||
private Dictionary<string, bool> _dicHeaderSort = new();
|
private Dictionary<string, bool> _dicHeaderSort = new();
|
||||||
private SpeedtestHandler? _speedtestHandler;
|
private SpeedtestService? _speedtestHandler;
|
||||||
|
|
||||||
#endregion private prop
|
#endregion private prop
|
||||||
|
|
||||||
|
@ -670,7 +671,7 @@ namespace ServiceLib.ViewModels
|
||||||
var coreHandler = Locator.Current.GetService<CoreHandler>();
|
var coreHandler = Locator.Current.GetService<CoreHandler>();
|
||||||
if (coreHandler != null)
|
if (coreHandler != null)
|
||||||
{
|
{
|
||||||
_speedtestHandler = new SpeedtestHandler(_config, coreHandler, lstSelecteds, actionType, UpdateSpeedtestHandler);
|
_speedtestHandler = new SpeedtestService(_config, coreHandler, lstSelecteds, actionType, UpdateSpeedtestHandler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using DynamicData.Binding;
|
using DynamicData.Binding;
|
||||||
using ReactiveUI;
|
using ReactiveUI;
|
||||||
using ReactiveUI.Fody.Helpers;
|
using ReactiveUI.Fody.Helpers;
|
||||||
|
using ServiceLib.Services;
|
||||||
using Splat;
|
using Splat;
|
||||||
using System.Reactive;
|
using System.Reactive;
|
||||||
|
|
||||||
|
@ -295,7 +296,7 @@ namespace ServiceLib.ViewModels
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DownloadHandler downloadHandle = new DownloadHandler();
|
DownloadService downloadHandle = new DownloadService();
|
||||||
var result = await downloadHandle.TryDownloadString(url, true, "");
|
var result = await downloadHandle.TryDownloadString(url, true, "");
|
||||||
var ret = await AddBatchRoutingRulesAsync(SelectedRouting, result);
|
var ret = await AddBatchRoutingRulesAsync(SelectedRouting, result);
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
|
|
Loading…
Reference in New Issue