Beispiel #1
0
 static void Main(string[] args)
 {
     try
     {
         //为防止程序长时间运行,一定时间后自动结束自己,另外SuWar3Tools也启动了线程超过60秒也会结束掉这个外部进程
         int second = ExtLogic.GetTimeOutSecond();
         if (second <= 0)
         {
             second = 60;
         }
         System.Threading.Tasks.Task.Run(async() =>
         {
             await System.Threading.Tasks.Task.Delay(second * 1000);
             System.Environment.Exit(0);
         });
         //读取参数json
         ExtInputArgs inputArgs = null;
         string       runPath   = Assembly.GetEntryAssembly().Location;
         string       jsonFile  = Path.Combine(Path.GetDirectoryName(runPath), Path.GetFileNameWithoutExtension(runPath) + "_ing.json");
         if (File.Exists(jsonFile))
         {
             string jsonStr = GetTextFromFile(jsonFile);
             if (!string.IsNullOrEmpty(jsonStr))
             {
                 try { inputArgs = ParseJson <ExtInputArgs>(jsonStr); } catch { }
             }
             File.Delete(jsonFile);
         }
         if (inputArgs == null)
         {
             string tipMsg = ExtLogic.GetTipMsgWhenHasNoArgs();
             if (!string.IsNullOrEmpty(tipMsg))
             {
                 Console.WriteLine(DefaultTipMsg + "\n" + SepString + "\n" + tipMsg + "\n" + SepString);
             }
             else
             {
                 Console.WriteLine(DefaultTipMsg + "\n" + SepString);
             }
             Console.WriteLine("\n按“y”继续执行将生成返回参数的json文件,否则退出(" + second + "秒后也会自动退出):");
             if (Console.ReadKey().Key.ToString().ToLower() == "y")
             {
                 Task t = MainAsync(args, inputArgs);
                 t.Wait();
             }
         }
         else
         {
             Task t = MainAsync(args, inputArgs);
             t.Wait();
         }
     }
     catch
     {
         return;
     }
 }
Beispiel #2
0
 static async Task MainAsync(string[] launchArgs, ExtInputArgs inputArgs)
 {
     try
     {
         QuitWithArgs(await ExtLogic.ProcessLogic(launchArgs, inputArgs ?? new ExtInputArgs(), new ExtOutputArgs()));
     }
     catch
     {
         System.Environment.Exit(0);
     }
 }
Beispiel #3
0
 /// <summary>
 /// 使用说明: https://github.com/hegelsu/SuWar3Tools
 /// </summary>
 /// <param name="launchArgs">程序启动参数</param>
 /// <param name="inputArgs">由SuWar3Tools生成的Json文本参数</param>
 /// <param name="outputArgs">输出的参数,将由SuWar3Tools进行处理</param>
 /// <returns></returns>
 public static async Task <ExtOutputArgs> ProcessLogic(string[] launchArgs, ExtInputArgs inputArgs, ExtOutputArgs outputArgs)
 {
     try
     {
         outputArgs.Msg = string.Format("[{0}]我接收到了从SuWar3Tools传来的魔兽版本号:{1}", DateTime.Now.ToString("yyyyMMdd HH:mm:ss"), inputArgs.Version);
     }
     catch (Exception ex)
     {
         outputArgs.Msg = ex.Message;
     }
     return(outputArgs);
 }
Beispiel #4
0
 /// <summary>
 /// 复制本代码文件替换“SuWar3ToolsExt\ExtLogic.cs”后编译生成程序即可使用
 /// </summary>
 /// <param name="launchArgs">程序启动参数</param>
 /// <param name="inputArgs">由SuWar3Tools生成的Json文本参数</param>
 /// <param name="outputArgs">输出的参数,将由SuWar3Tools进行处理</param>
 /// <returns></returns>
 public static async Task <ExtOutputArgs> ProcessLogic(string[] launchArgs, ExtInputArgs inputArgs, ExtOutputArgs outputArgs)
 {
     try
     {
         List <string> names = new List <string>();
         inputArgs.Joiners?.ForEach(n => names.Add(n.Name));
         inputArgs.Players?.ForEach(n => names.Add(n.Name));
         string gameType = launchArgs != null && launchArgs.Length > 0 ? launchArgs[0] : "1";
         if (string.IsNullOrEmpty(gameType))
         {
             gameType = "1";
         }
         outputArgs.Msg = GetGameTypeDesc(gameType) + "胜率->";
         //下面以批量查询09战绩为例
         if (names.Count > 0)
         {
             Task <string>[] tasks = new Task <string> [names.Count];
             for (int i = 0; i < tasks.Length; i++)
             {
                 tasks[i] = GetPlayData(gameType, names[i]);
             }
             Task.WaitAll(tasks);
             for (int i = 0; i < tasks.Length; i++)
             {
                 string result = await tasks[i];
                 if (!string.IsNullOrEmpty(result))
                 {
                     outputArgs.Msg += result + " ";
                 }
             }
         }
         if (!string.IsNullOrEmpty(outputArgs.Msg))
         {
             outputArgs.Msg = outputArgs.Msg.Trim();
         }
     }
     catch (Exception ex)
     {
         outputArgs.Msg = ex.Message;
     }
     return(outputArgs);
 }
Beispiel #5
0
        /// <summary>
        /// 复制本代码文件替换“SuWar3ToolsExt\ExtLogic.cs”后编译生成程序即可使用
        /// </summary>
        /// <param name="launchArgs">程序启动参数</param>
        /// <param name="inputArgs">由SuWar3Tools生成的Json文本参数</param>
        /// <param name="outputArgs">输出的参数,将由SuWar3Tools进行处理</param>
        /// <returns></returns>
        public static async Task <ExtOutputArgs> ProcessLogic(string[] launchArgs, ExtInputArgs inputArgs, ExtOutputArgs outputArgs)
        {
            try
            {
                List <string> names = new List <string>();
                inputArgs.Joiners?.ForEach(n => names.Add(n.Name));
                inputArgs.Players?.ForEach(n => names.Add(n.Name));
                string gameType   = launchArgs != null && launchArgs.Length > 0 ? launchArgs[0] : "1";
                string userName   = launchArgs != null && launchArgs.Length > 1 ? launchArgs[1] : "";
                string passWord   = launchArgs != null && launchArgs.Length > 2 ? launchArgs[2] : "";
                string tryCount   = launchArgs != null && launchArgs.Length > 3 ? launchArgs[3] : "3";
                int    retryCount = 3;
                int.TryParse(tryCount, out retryCount);
                if (string.IsNullOrEmpty(gameType) || string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(passWord))
                {
                    throw new Exception("请配置账号和密码");
                }
                List <Cookie> cookies = GetCookies();
                if (cookies == null || cookies.Count < 1)
                {
                    LoginResult loginResult = await GetLoginResultAsync(userName, passWord);

                    if (loginResult == null || loginResult.code != 1 || loginResult.data == null)
                    {
                        throw new Exception("账号登录失败" + (loginResult != null && !string.IsNullOrEmpty(loginResult.msg) ? (":" + loginResult.msg) : ""));
                    }
                    cookies = await GetPassCookieAsync(loginResult.data);
                }
                if (cookies == null || cookies.Count < 1)
                {
                    throw new Exception("获取Cookie失败");
                }
                //outputArgs.Msg = GetGameTypeDesc(gameType) + "天梯:";
                //批量查询11天梯胜率
                names.RemoveAll(n => n == "蜀国" || n == "魏国" || n == userName);
                if (names.Count > 0)
                {
                    Task <TaskResult>[] tasks = new Task <TaskResult> [names.Count];
                    for (int i = 0; i < tasks.Length; i++)
                    {
                        tasks[i] = GetPlayData(gameType, names[i], cookies, retryCount);
                    }
                    Task.WaitAll(tasks);
                    List <TaskResult> results = new List <TaskResult>();
                    for (int i = 0; i < tasks.Length; i++)
                    {
                        results.Add(await tasks[i]);
                    }
                    bool existSuccess = results.Exists(n => n.success);
                    SaveCookies(existSuccess ? cookies : null);
                    for (int i = 0; i < results.Count; i++)
                    {
                        if ((!existSuccess || results[i].success) && !string.IsNullOrEmpty(results[i].result))
                        {
                            if (string.IsNullOrEmpty(outputArgs.Msg))
                            {
                                outputArgs.Msg = results[i].result;
                            }
                            else
                            {
                                outputArgs.Msg += "\n" + results[i].result;
                            }
                        }
                    }
                }
                if (!string.IsNullOrEmpty(outputArgs.Msg))
                {
                    outputArgs.Msg = outputArgs.Msg.Trim();
                }
            }
            catch (Exception ex)
            {
                outputArgs.Msg = ex.Message;
            }
            return(outputArgs);
        }