mirror of
https://github.com/2dust/v2rayN.git
synced 2026-10-28 08:04:58 +03:00
Improved Action Invoke
This commit is contained in:
@@ -10,12 +10,12 @@ namespace ServiceLib.Handler
|
||||
private Dictionary<String, ProxiesItem>? _proxies;
|
||||
public Dictionary<string, object> ProfileContent { get; set; }
|
||||
|
||||
public void GetClashProxies(Config config, Action<ClashProxies, ClashProviders> update)
|
||||
public void GetClashProxies(Config config, Action<ClashProxies, ClashProviders> updateFunc)
|
||||
{
|
||||
Task.Run(() => GetClashProxiesAsync(config, update));
|
||||
Task.Run(() => GetClashProxiesAsync(config, updateFunc));
|
||||
}
|
||||
|
||||
private async Task GetClashProxiesAsync(Config config, Action<ClashProxies, ClashProviders> update)
|
||||
private async Task GetClashProxiesAsync(Config config, Action<ClashProxies, ClashProviders> updateFunc)
|
||||
{
|
||||
for (var i = 0; i < 5; i++)
|
||||
{
|
||||
@@ -30,15 +30,15 @@ namespace ServiceLib.Handler
|
||||
if (clashProxies != null || clashProviders != null)
|
||||
{
|
||||
_proxies = clashProxies?.proxies;
|
||||
update(clashProxies, clashProviders);
|
||||
updateFunc?.Invoke(clashProxies, clashProviders);
|
||||
return;
|
||||
}
|
||||
Task.Delay(5000).Wait();
|
||||
}
|
||||
update(null, null);
|
||||
updateFunc?.Invoke(null, null);
|
||||
}
|
||||
|
||||
public void ClashProxiesDelayTest(bool blAll, List<ClashProxyModel> lstProxy, Action<ClashProxyModel?, string> update)
|
||||
public void ClashProxiesDelayTest(bool blAll, List<ClashProxyModel> lstProxy, Action<ClashProxyModel?, string> updateFunc)
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
@@ -90,13 +90,13 @@ namespace ServiceLib.Handler
|
||||
tasks.Add(Task.Run(async () =>
|
||||
{
|
||||
var result = await HttpClientHelper.Instance.TryGetAsync(url);
|
||||
update(it, result);
|
||||
updateFunc?.Invoke(it, result);
|
||||
}));
|
||||
}
|
||||
Task.WaitAll(tasks.ToArray());
|
||||
|
||||
Task.Delay(1000).Wait();
|
||||
update(null, "");
|
||||
updateFunc?.Invoke(null, "");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -164,12 +164,12 @@ namespace ServiceLib.Handler
|
||||
}
|
||||
}
|
||||
|
||||
public void GetClashConnections(Config config, Action<ClashConnections> update)
|
||||
public void GetClashConnections(Config config, Action<ClashConnections> updateFunc)
|
||||
{
|
||||
Task.Run(() => GetClashConnectionsAsync(config, update));
|
||||
Task.Run(() => GetClashConnectionsAsync(config, updateFunc));
|
||||
}
|
||||
|
||||
private async Task GetClashConnectionsAsync(Config config, Action<ClashConnections> update)
|
||||
private async Task GetClashConnectionsAsync(Config config, Action<ClashConnections> updateFunc)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -177,7 +177,7 @@ namespace ServiceLib.Handler
|
||||
var result = await HttpClientHelper.Instance.TryGetAsync(url);
|
||||
var clashConnections = JsonUtils.Deserialize<ClashConnections>(result);
|
||||
|
||||
update(clashConnections);
|
||||
updateFunc?.Invoke(clashConnections);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -13,12 +13,12 @@ namespace ServiceLib.Handler
|
||||
private Config _config;
|
||||
private Process? _process;
|
||||
private Process? _processPre;
|
||||
private Action<bool, string> _updateFunc;
|
||||
private Action<bool, string>? _updateFunc;
|
||||
|
||||
public void Init(Config config, Action<bool, string> update)
|
||||
public void Init(Config config, Action<bool, string> updateFunc)
|
||||
{
|
||||
_config = config;
|
||||
_updateFunc = update;
|
||||
_updateFunc = updateFunc;
|
||||
|
||||
Environment.SetEnvironmentVariable("v2ray.location.asset", Utils.GetBinPath(""), EnvironmentVariableTarget.Process);
|
||||
Environment.SetEnvironmentVariable("xray.location.asset", Utils.GetBinPath(""), EnvironmentVariableTarget.Process);
|
||||
@@ -267,7 +267,7 @@ namespace ServiceLib.Handler
|
||||
|
||||
private void ShowMsg(bool notify, string msg)
|
||||
{
|
||||
_updateFunc(notify, msg);
|
||||
_updateFunc?.Invoke(notify, msg);
|
||||
}
|
||||
|
||||
#endregion Private
|
||||
|
||||
@@ -8,16 +8,16 @@
|
||||
private Config _config;
|
||||
private ServerStatItem? _serverStatItem;
|
||||
private List<ServerStatItem> _lstServerStat;
|
||||
private Action<ServerSpeedItem> _updateFunc;
|
||||
private Action<ServerSpeedItem>? _updateFunc;
|
||||
private StatisticsV2rayService? _statisticsV2Ray;
|
||||
private StatisticsSingboxService? _statisticsSingbox;
|
||||
|
||||
public List<ServerStatItem> ServerStat => _lstServerStat;
|
||||
|
||||
public void Init(Config config, Action<ServerSpeedItem> update)
|
||||
public void Init(Config config, Action<ServerSpeedItem> updateFunc)
|
||||
{
|
||||
_config = config;
|
||||
_updateFunc = update;
|
||||
_updateFunc = updateFunc;
|
||||
if (!config.guiItem.enableStatistics)
|
||||
{
|
||||
return;
|
||||
@@ -95,7 +95,7 @@
|
||||
server.todayDown = _serverStatItem.todayDown;
|
||||
server.totalUp = _serverStatItem.totalUp;
|
||||
server.totalDown = _serverStatItem.totalDown;
|
||||
_updateFunc(server);
|
||||
_updateFunc?.Invoke(server);
|
||||
}
|
||||
|
||||
private void GetServerStatItem(string indexId)
|
||||
|
||||
@@ -9,13 +9,13 @@
|
||||
{
|
||||
}
|
||||
|
||||
public void RegUpdateTask(Config config, Action<bool, string> update)
|
||||
public void RegUpdateTask(Config config, Action<bool, string> updateFunc)
|
||||
{
|
||||
Task.Run(() => UpdateTaskRunSubscription(config, update));
|
||||
Task.Run(() => UpdateTaskRunGeo(config, update));
|
||||
Task.Run(() => UpdateTaskRunSubscription(config, updateFunc));
|
||||
Task.Run(() => UpdateTaskRunGeo(config, updateFunc));
|
||||
}
|
||||
|
||||
private async Task UpdateTaskRunSubscription(Config config, Action<bool, string> update)
|
||||
private async Task UpdateTaskRunSubscription(Config config, Action<bool, string> updateFunc)
|
||||
{
|
||||
await Task.Delay(60000);
|
||||
Logging.SaveLog("UpdateTaskRunSubscription");
|
||||
@@ -33,7 +33,7 @@
|
||||
{
|
||||
updateHandle.UpdateSubscriptionProcess(config, item.id, true, (bool success, string msg) =>
|
||||
{
|
||||
update(success, msg);
|
||||
updateFunc?.Invoke(success, msg);
|
||||
if (success)
|
||||
Logging.SaveLog("subscription" + msg);
|
||||
});
|
||||
@@ -46,7 +46,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
private async Task UpdateTaskRunGeo(Config config, Action<bool, string> update)
|
||||
private async Task UpdateTaskRunGeo(Config config, Action<bool, string> updateFunc)
|
||||
{
|
||||
var autoUpdateGeoTime = DateTime.Now;
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
{
|
||||
await updateHandle.UpdateGeoFileAll(config, (bool success, string msg) =>
|
||||
{
|
||||
update(false, msg);
|
||||
updateFunc?.Invoke(false, msg);
|
||||
});
|
||||
autoUpdateGeoTime = dtNow;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user