From 5597c0b354f881994a75878731c3a02183e9c970 Mon Sep 17 00:00:00 2001
From: asmrobot <asmrobot@hotmail.com>
Date: Wed, 16 Oct 2019 00:58:07 +0000
Subject: [PATCH] format project

---
 src/RichCreator/Jobs/JobMonitor.cs |  153 +++++++++++++++++---------------------------------
 1 files changed, 53 insertions(+), 100 deletions(-)

diff --git a/src/RichCreator/Jobs/JobMonitor.cs b/src/RichCreator/Jobs/JobMonitor.cs
index 58b7dd4..9dd7238 100644
--- a/src/RichCreator/Jobs/JobMonitor.cs
+++ b/src/RichCreator/Jobs/JobMonitor.cs
@@ -32,6 +32,8 @@
 
         private Int32 taskIndex;
 
+        Int32 runningStep = RunningStep.None;
+
         public JobMonitor(Int32 taskIndex)
         {
             this.config = ConfigHelper.GetInstance<RichCreatorConfig>();
@@ -60,10 +62,14 @@
             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)
@@ -72,136 +78,84 @@
                 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>
@@ -218,10 +172,9 @@
                 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");
         }
     }
 }

--
Gitblit v1.9.3