mirror of
https://git.oceanpay.cc/danial/kami_itunes_june.git
synced 2025-12-18 22:31:24 +00:00
123 lines
2.8 KiB
C#
123 lines
2.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using AppleBatch_June.Model;
|
|
|
|
namespace AppleBatch_June
|
|
{
|
|
public class AppleExecuteTask
|
|
{
|
|
private static Dictionary<string, bool> TaskIsRunAlls = new Dictionary<string, bool>();
|
|
|
|
public static List<TaskRunModel> TaskRunModels = new List<TaskRunModel>();
|
|
|
|
public static readonly object obj = new object();
|
|
|
|
public static long TaskRunAppleIdCount = 0L;
|
|
|
|
public static bool isRun { get; set; } = false;
|
|
|
|
|
|
public static string[] TaskIsRun
|
|
{
|
|
get
|
|
{
|
|
try
|
|
{
|
|
return (from c in TaskIsRunAlls
|
|
where c.Value
|
|
select c.Key).ToArray();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return new string[0];
|
|
}
|
|
}
|
|
}
|
|
|
|
public static bool SetTaskIsRun(string name, bool state)
|
|
{
|
|
try
|
|
{
|
|
lock (TaskIsRunAlls)
|
|
{
|
|
if (TaskIsRunAlls.ContainsKey(name))
|
|
{
|
|
TaskIsRunAlls[name] = state;
|
|
}
|
|
else
|
|
{
|
|
TaskIsRunAlls.Add(name, state);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private bool startRuning(TaskRunModel runModel, Action<string, DisplyType, string> _action, string appleId)
|
|
{
|
|
if (Tools.ToNetWorkInt(ConfigUtlis.getConfigValue("comNetworkConfig"), 0) == 3)
|
|
{
|
|
int num = Tools.ToInt(ConfigUtlis.getConfigValue("txtAdslIdCount"), 10);
|
|
if (TaskRunAppleIdCount >= num)
|
|
{
|
|
_action?.Invoke(appleId, DisplyType.xinxi, "等待拨号...");
|
|
bool flag = false;
|
|
do
|
|
{
|
|
flag = false;
|
|
foreach (TaskRunModel taskRunModel in TaskRunModels)
|
|
{
|
|
if (taskRunModel.isRuning)
|
|
{
|
|
flag = true;
|
|
break;
|
|
}
|
|
}
|
|
Thread.Sleep(new Random().Next(100, 300));
|
|
}
|
|
while (flag);
|
|
lock (obj)
|
|
{
|
|
if (TaskRunAppleIdCount >= num)
|
|
{
|
|
string configValue = ConfigUtlis.getConfigValue("txtAdslUserName");
|
|
string configValue2 = ConfigUtlis.getConfigValue("txtAdslPwd");
|
|
Thread.Sleep(new Random().Next(500, 1000));
|
|
_action?.Invoke(appleId, DisplyType.xinxi, "断开宽带连接");
|
|
RasTools.Disconnect();
|
|
Thread.Sleep(new Random().Next(200, 500));
|
|
_action?.Invoke(appleId, DisplyType.xinxi, "开始宽带重新拨号");
|
|
if (!RasTools.Connect(configValue, configValue2, out var errMsg))
|
|
{
|
|
_action?.Invoke(appleId, DisplyType.xinxi, "拨号失败:" + errMsg);
|
|
return false;
|
|
}
|
|
_action?.Invoke(appleId, DisplyType.xinxi, "重新拨号成功");
|
|
Thread.Sleep(new Random().Next(500, 1000));
|
|
TaskRunAppleIdCount = 0L;
|
|
}
|
|
}
|
|
}
|
|
TaskRunAppleIdCount++;
|
|
}
|
|
runModel.isRuning = true;
|
|
return true;
|
|
}
|
|
|
|
private void endRuning(TaskRunModel runModel)
|
|
{
|
|
runModel.isRuning = false;
|
|
}
|
|
|
|
public static void Stop()
|
|
{
|
|
isRun = false;
|
|
}
|
|
}
|
|
}
|