mirror of
https://git.oceanpay.cc/danial/kami_itunes_june.git
synced 2025-12-18 22:31:24 +00:00
189 lines
5.4 KiB
C#
189 lines
5.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using AppleBatch_June.Model;
|
|
using AppleBatch_June.StartTaskModel;
|
|
using AppleBatch_June.Utils;
|
|
|
|
namespace AppleBatch_June.ExecuteTasks
|
|
{
|
|
public class GameTask : BaseTask
|
|
{
|
|
public static GameTask Instance { get; private set; }
|
|
|
|
static GameTask()
|
|
{
|
|
Instance = new GameTask("获取游戏");
|
|
}
|
|
|
|
public GameTask(string _taskName)
|
|
: base(_taskName)
|
|
{
|
|
}
|
|
|
|
private int passGetGameByUrl(bool ckQueryMOdel, GetGameUtils itunes, string gameUrl, AppleItunesLogin itunesLogin)
|
|
{
|
|
int num = 0;
|
|
if (ckQueryMOdel)
|
|
{
|
|
return itunes.getNewGameByUrl3(gameUrl, itunesLogin);
|
|
}
|
|
return itunes.getGameByUrl(gameUrl, itunesLogin);
|
|
}
|
|
|
|
public void AppleGameTask(int TaskSize, List<string> gameUrls, bool openVpn, bool ckQueryMOdel, List<AppleAcount> lvItems, Action startAct, Action endTakAct, Action<string> sucessAct, Action<string, DisplyType, string> _action)
|
|
{
|
|
TaskSize = Tools.getTaskSize(openVpn, lvItems.Count);
|
|
if (!base.isRun)
|
|
{
|
|
AppleExecuteTask.TaskRunAppleIdCount = 0L;
|
|
AppleExecuteTask.TaskRunModels.Clear();
|
|
startAct?.Invoke();
|
|
base.isRun = true;
|
|
base.baseEndTakAct = endTakAct;
|
|
Task.Run(delegate
|
|
{
|
|
ApiNetReq.startNowFun = 10;
|
|
base.TaskIsRun = true;
|
|
Task[] array = new Task[TaskSize];
|
|
for (int i = 0; i < TaskSize; i++)
|
|
{
|
|
array[i] = Task.Run(delegate
|
|
{
|
|
string guid = Guid.NewGuid().ToString("n");
|
|
TaskRunModel taskRunModel = new TaskRunModel
|
|
{
|
|
guid = guid,
|
|
isRuning = false
|
|
};
|
|
AppleExecuteTask.TaskRunModels.Add(taskRunModel);
|
|
while (base.isRun)
|
|
{
|
|
AppleAcount appleAcount = null;
|
|
try
|
|
{
|
|
lock (lvItems)
|
|
{
|
|
appleAcount = lvItems.Where((AppleAcount c) => !c.isAct).FirstOrDefault();
|
|
if (appleAcount == null)
|
|
{
|
|
break;
|
|
}
|
|
appleAcount.isAct = true;
|
|
}
|
|
string guidTag = appleAcount.guidTag;
|
|
if (BaseTask.startRuning(taskRunModel, _action, guidTag))
|
|
{
|
|
GetGameUtils getGameUtils = new GetGameUtils(this, guidTag, _action, openVpn)
|
|
{
|
|
appleId = appleAcount.appleId
|
|
};
|
|
AppleItunesLogin itunesLogin = getItunesLogin(appleAcount, 10, _action, getGameUtils, 1);
|
|
if (itunesLogin != null)
|
|
{
|
|
_action?.Invoke(guidTag, DisplyType.area, itunesLogin.Area);
|
|
_action?.Invoke(guidTag, DisplyType.gameCount, gameUrls.Count.ToString());
|
|
_action?.Invoke(guidTag, DisplyType.gameFire, "");
|
|
_action?.Invoke(guidTag, DisplyType.gameSuccess, "");
|
|
_action?.Invoke(guidTag, DisplyType.xinxi, "正在获取应用");
|
|
int num = 1;
|
|
int num2 = 0;
|
|
int num3 = 0;
|
|
foreach (string gameUrl in gameUrls)
|
|
{
|
|
if (base.isRun)
|
|
{
|
|
_action?.Invoke(guidTag, DisplyType.xinxi, "正在获取第" + num + "个应用");
|
|
Stopwatch stopwatch = new Stopwatch();
|
|
stopwatch.Start();
|
|
num3 = passGetGameByUrl(ckQueryMOdel, getGameUtils, gameUrl, itunesLogin);
|
|
stopwatch.Stop();
|
|
if (num3 == 99)
|
|
{
|
|
itunesLogin = getItunesLogin(appleAcount, 10, _action, getGameUtils, 2);
|
|
if (itunesLogin == null)
|
|
{
|
|
_action?.Invoke(guidTag, DisplyType.gameFire, "账号登录失败");
|
|
break;
|
|
}
|
|
_action?.Invoke(guidTag, DisplyType.xinxi, "正在获取第" + num + "个应用");
|
|
num3 = passGetGameByUrl(ckQueryMOdel, getGameUtils, gameUrl, itunesLogin);
|
|
_action?.Invoke(guidTag, DisplyType.gameCount, gameUrls.Count.ToString());
|
|
}
|
|
if (num3 == 1)
|
|
{
|
|
num2++;
|
|
_action?.Invoke(guidTag, DisplyType.gameSuccess, "获取成功");
|
|
}
|
|
else
|
|
{
|
|
_action?.Invoke(guidTag, DisplyType.gameFire, "获取失败");
|
|
}
|
|
num++;
|
|
}
|
|
}
|
|
getGameUtils.endGetGame(itunesLogin);
|
|
if (num2 > 0)
|
|
{
|
|
if (num3 != 99)
|
|
{
|
|
_action?.Invoke(guidTag, DisplyType.xinxi, "获取完成");
|
|
ApiApplyAct(10, "Apple获取游戏");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_action?.Invoke(guidTag, DisplyType.xinxi, "获取失败");
|
|
}
|
|
sucessAct?.Invoke(guidTag);
|
|
}
|
|
goto IL_03f9;
|
|
}
|
|
}
|
|
catch (Exception ex2)
|
|
{
|
|
APIUtlis.ApiSeriveError(ex2);
|
|
if (appleAcount != null)
|
|
{
|
|
_action?.Invoke(appleAcount.guidTag, DisplyType.xinxi, "请求失败:" + ex2.Message);
|
|
}
|
|
goto IL_03f9;
|
|
}
|
|
continue;
|
|
IL_03f9:
|
|
BaseTask.endRuning(taskRunModel);
|
|
}
|
|
});
|
|
}
|
|
Task.WaitAll(array);
|
|
try
|
|
{
|
|
Task[] array2 = array;
|
|
foreach (Task task in array2)
|
|
{
|
|
if (task.Status == TaskStatus.RanToCompletion)
|
|
{
|
|
task.Dispose();
|
|
}
|
|
}
|
|
array = null;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
AppleExecuteTask.TaskRunModels.Clear();
|
|
base.TaskIsRun = false;
|
|
base.isRun = false;
|
|
endTakAct?.Invoke();
|
|
});
|
|
}
|
|
else
|
|
{
|
|
endTakAct?.Invoke();
|
|
}
|
|
}
|
|
}
|
|
}
|