| | |
| | | |
| | | private Int32 taskIndex; |
| | | |
| | | Int32 runningStep = RunningStep.None; |
| | | |
| | | public JobMonitor(Int32 taskIndex) |
| | | { |
| | | this.config = ConfigHelper.GetInstance<RichCreatorConfig>(); |
| | |
| | | this.cancelTokenSource = new CancellationTokenSource(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 业务逻辑线程 |
| | | /// </summary> |
| | | /// <param name="obj"></param> |
| | | private void MonitorBusinessThread(object obj) |
| | | { |
| | | Int32 accountCount = GetAccountCount(); |
| | | Int32 runningStep = RunningStep.GetStep(); |
| | | Int32 accountCount = this.config.GetAccountCount(); |
| | | runningStep = RunningStep.GetStep(); |
| | | G.Instance.InfoWriter("当前步骤:" + runningStep.ToString()); |
| | | RunningModel runModel = ConfigHelper.GetInstance<RunningModel>(); |
| | | if (runModel.AccountIndex > accountCount) |
| | |
| | | return; |
| | | } |
| | | |
| | | bool tryAgain = false; |
| | | |
| | | int accountIndex = runModel.AccountIndex > 0 ? runModel.AccountIndex - 1 : 0; |
| | | ZTResult jobResult = ZTResult.Success; |
| | | for (; accountIndex < accountCount; accountIndex++) |
| | | { |
| | | RunningModel.UpdateAccountIndex(accountIndex+1); |
| | | if (runningStep < RunningStep.SelectRole) |
| | | { |
| | | string username, password; |
| | | GetAccount(accountIndex, out username, out password); |
| | | this.config.GetAccount(accountIndex, out username, out password); |
| | | |
| | | this.wegameJob = new WeGameJob(this.config, username, password); |
| | | if (!this.wegameJob.DoWork(out tryAgain,this.cancelTokenSource.Token, runningStep)) |
| | | jobResult = this.wegameJob.Do(this.cancelTokenSource.Token, runningStep); |
| | | if (jobResult != ZTResult.Success) |
| | | { |
| | | if (G.Instance.CancelConfirm("需要重试吗?", 8000)) |
| | | if (jobResult != ZTResult.Cancel) |
| | | { |
| | | if (config.NotificationWechat) |
| | | if (G.Instance.CancelConfirm("需要重试吗?", 8000)) |
| | | { |
| | | if (!ServiceMonitor.Instance.NotificationWechat("失败,正在重新尝试")) |
| | | { |
| | | ZTImage.Log.Trace.Error("发送消息失败"); |
| | | } |
| | | ServiceProvider.Instance.NotificationWechat("失败,正在重新尝试"); |
| | | accountIndex--; |
| | | ShutdownGameProgram(); |
| | | continue; |
| | | } |
| | | accountIndex--; |
| | | runningStep = RunningStep.None; |
| | | ProcessUtils.CloseDnf(); |
| | | ProcessUtils.CloseWeGame(); |
| | | continue; |
| | | } |
| | | else |
| | | { |
| | | break; |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | |
| | | //设为顶层 |
| | | WindowUtils.SetDnfToTop(); |
| | | this.dnfJob = GetDNFJob(); |
| | | if (this.dnfJob == null) |
| | | jobResult = this.dnfJob.Do(this.cancelTokenSource.Token, runningStep); |
| | | if (jobResult != ZTResult.Success) |
| | | { |
| | | if (jobResult != ZTResult.Cancel) |
| | | { |
| | | if (G.Instance.CancelConfirm("需要重试吗?", 8000)) |
| | | { |
| | | ServiceProvider.Instance.NotificationWechat("失败,正在重新尝试"); |
| | | accountIndex--; |
| | | ShutdownGameProgram(); |
| | | continue; |
| | | } |
| | | } |
| | | break; |
| | | } |
| | | if (!this.dnfJob.DoWork(out tryAgain,this.cancelTokenSource.Token, runningStep)) |
| | | { |
| | | if (G.Instance.CancelConfirm("需要重试吗?", 8000)) |
| | | { |
| | | if (config.NotificationWechat) |
| | | { |
| | | if (!ServiceMonitor.Instance.NotificationWechat("失败,正在重新尝试")) |
| | | { |
| | | ZTImage.Log.Trace.Error("发送消息失败"); |
| | | } |
| | | } |
| | | accountIndex--; |
| | | runningStep = RunningStep.None; |
| | | ProcessUtils.CloseDnf(); |
| | | ProcessUtils.CloseWeGame(); |
| | | continue; |
| | | } |
| | | else |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | runningStep = RunningStep.None; |
| | | ProcessUtils.CloseDnf(); |
| | | ProcessUtils.CloseWeGame(); |
| | | |
| | | ShutdownGameProgram(); |
| | | Thread.Sleep(5000); |
| | | } |
| | | |
| | | if (config.NotificationWechat) |
| | | if (jobResult == ZTResult.Success) |
| | | { |
| | | if (!ServiceMonitor.Instance.NotificationWechat("任务完成")) |
| | | { |
| | | ZTImage.Log.Trace.Error("发送消息失败"); |
| | | } |
| | | G.Instance.InfoWriter("任务完成"); |
| | | ServiceProvider.Instance.NotificationWechat("任务完成"); |
| | | runModel.RoleIndex = 1; |
| | | runModel.AccountIndex = 1; |
| | | ConfigHelper.SetInstance<RunningModel>(runModel); |
| | | } |
| | | |
| | | runModel.RoleIndex = 1; |
| | | runModel.AccountIndex = 1; |
| | | ConfigHelper.SetInstance<RunningModel>(runModel); |
| | | else |
| | | { |
| | | G.Instance.InfoWriter("任务中止"); |
| | | } |
| | | |
| | | this.Stop(); |
| | | G.Instance.StopTaskUI(); |
| | | G.Instance.InfoWriter("任务成功完成"); |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取配置文件中账号的数量 |
| | | /// 关闭游戏程序 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | private Int32 GetAccountCount() |
| | | private void ShutdownGameProgram() |
| | | { |
| | | Int32 accountCount = 0; |
| | | if (!string.IsNullOrEmpty(this.config.UserName1)) |
| | | { |
| | | accountCount = 1; |
| | | if (!string.IsNullOrEmpty(this.config.UserName2)) |
| | | { |
| | | accountCount = 2; |
| | | if (!string.IsNullOrEmpty(this.config.UserName3)) |
| | | { |
| | | accountCount = 3; |
| | | } |
| | | } |
| | | } |
| | | |
| | | return accountCount; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取指定编号 |
| | | /// </summary> |
| | | /// <param name="accountIndex">从0开始</param> |
| | | /// <param name="username"></param> |
| | | /// <param name="password"></param> |
| | | private void GetAccount(Int32 accountIndex, out string username, out string password) |
| | | { |
| | | username = this.config.UserName1; |
| | | password = this.config.Password1; |
| | | if (accountIndex == 1) |
| | | { |
| | | username = this.config.UserName2; |
| | | password = this.config.Password2; |
| | | } |
| | | |
| | | if (accountIndex == 2) |
| | | { |
| | | username = this.config.UserName3; |
| | | password = this.config.Password3; |
| | | } |
| | | runningStep = RunningStep.None; |
| | | ProcessUtils.CloseDnf(); |
| | | ProcessUtils.CloseWeGame(); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | case 1: |
| | | return new DNFJob<SkillMap>(this.config); |
| | | case 2: |
| | | return new DNFJob<GroupMap>(this.config); |
| | | default: |
| | | return null; |
| | | return new DNFJob<TestMap>(this.config); |
| | | } |
| | | throw new Exception("this task index is error"); |
| | | } |
| | | } |
| | | } |