Files
kami_itunes_june/AppleBatch_June.ExecuteTasks/AddRemoveFamilyMemberTask.cs
2024-07-22 00:43:14 +08:00

156 lines
4.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AppleBatch_June.Model;
using AppleBatch_June.StartTaskModel;
namespace AppleBatch_June.ExecuteTasks
{
public class AddRemoveFamilyMemberTask : BaseTask
{
public static AddRemoveFamilyMemberTask Instance { get; private set; }
static AddRemoveFamilyMemberTask()
{
Instance = new AddRemoveFamilyMemberTask("添加或移除家庭成员");
}
public AddRemoveFamilyMemberTask(string _taskName)
: base(_taskName)
{
}
public void ExecuteAddRemoveFamilyMember(int TaskSize, bool openVpn, List<AppleAcount> lvItems, Action startAct, Action endTakAct, Action<string> sucessAct, Action<string, DisplyType, string> _action)
{
TaskSize = Tools.getTaskSize(openVpn, lvItems.Count);
if (!ShopBalanceTask.Instance.isRun)
{
AppleExecuteTask.TaskRunAppleIdCount = 0L;
AppleExecuteTask.TaskRunModels.Clear();
startAct?.Invoke();
Instance.isRun = true;
Instance.TaskIsRun = true;
base.baseEndTakAct = endTakAct;
Task.Run(delegate
{
ApiNetReq.startNowFun = 31;
Task[] array = new Task[1];
for (int i = 0; i < array.Length; 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 (Instance.isRun)
{
AppleAcount appleAcount = null;
try
{
lock (lvItems)
{
appleAcount = lvItems.Where((AppleAcount c) => !c.isAct).FirstOrDefault();
if (appleAcount == null)
{
break;
}
appleAcount.isAct = true;
}
if (BaseTask.startRuning(taskRunModel, _action, appleAcount.lvItemGuid))
{
int type = 31;
iCloundUtils iCloundUtils2 = new iCloundUtils(this, appleAcount.lvItemGuid, _action, openVpn);
_action?.Invoke(appleAcount.lvItemGuid, DisplyType.chongzhi, "");
iCloundUtils2.appleId = appleAcount.appleId;
AppleiCloundLogin appleiCloundLogin = iCloundUtils2.loginDelegates(appleAcount.appleId, appleAcount.applePwd, type);
if (appleiCloundLogin != null)
{
iCloundUtils2.getFamilyDetails(appleiCloundLogin, iCloundUtils2);
if (iCloundUtils2.parentAccount.ToLower() == appleAcount.appleId.ToLower())
{
long result;
if (appleAcount.overflow != "del")
{
appleiCloundLogin.account = appleAcount.appleId;
iCloudVerifyCVVModel iCloudVerifyCVVModel = iCloundUtils2.getiTunesAccountPaymentInfo(appleiCloundLogin);
if (iCloudVerifyCVVModel != null)
{
iCloudVerifyCVVModel.securityCode = appleAcount.overflow;
string text = iCloundUtils2.verifyCVV(appleiCloundLogin, iCloudVerifyCVVModel);
if (!string.IsNullOrEmpty(text) && iCloundUtils2.addFamilyMember(appleiCloundLogin, appleAcount.newAppleId, appleAcount.newApplePopPwd, text))
{
ApiApplyAct(type, "添加或删除家庭成员");
}
}
}
else if (long.TryParse(appleAcount.newAppleId, out result))
{
if (iCloundUtils2.removeFamilyMember(appleiCloundLogin, appleAcount.newAppleId))
{
ApiApplyAct(type, "添加或删除家庭成员");
}
}
else
{
_action?.Invoke(appleAcount.lvItemGuid, DisplyType.xinxi, "失败移除请输入成员的Dsid");
}
}
else
{
_action?.Invoke(appleAcount.lvItemGuid, DisplyType.xinxi, "失败:请使用组织者账号添加或移除成员");
}
}
sucessAct?.Invoke(appleAcount.lvItemGuid);
goto IL_02a2;
}
}
catch (Exception ex2)
{
APIUtlis.ApiSeriveError(ex2);
if (appleAcount != null)
{
_action?.Invoke(appleAcount.lvItemGuid, DisplyType.xinxi, "请求失败:" + ex2.Message);
}
goto IL_02a2;
}
continue;
IL_02a2:
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();
Instance.TaskIsRun = false;
Instance.isRun = false;
endTakAct?.Invoke();
});
}
else
{
endTakAct?.Invoke();
}
}
}
}