//切换任务流程 public void TaskChangeProcess() { AutoVote.Init(); ProgressCore.KillProcess(GetStopIndicator()); //重启资源管理器 Notification.Refresh(); NetCore.DisConnect(); TaskName = ConfigCore.GetTaskName(); TaskChange = ConfigCore.GetTaskChange(); ChangeTask(); }
//NAME检测 public bool NameCheck() { TaskChange = ConfigCore.GetTaskChange(); if (TaskChange.Equals("1")) { TaskName = ConfigCore.GetTaskName(); if (!TaskName.Equals(ProjectName)) { TaskChangeProcess(); return(false); } } return(true); }
//任务初始化 public void InitTask() { string now = DateTime.Now.ToLocalTime().ToString(); String cacheMemory = ConfigCore.GetCacheMemory(); if (ConfigCore.GetTaskChange().Equals("1")) { //切换任务 TaskChangeProcess(); } else if (!StringUtil.isEmpty(cacheMemory)) { //缓存任务启动 string[] arr = cacheMemory.Split('`'); TaskChange = "0"; TaskName = arr[0].Substring(9); TaskPath = arr[1].Substring(9); String workerId = arr[2].Substring(7); if (!StringUtil.isEmpty(workerId)) { ConfigCore.InitWorker(""); } CustomPath = TaskPath; if (!StringUtil.isEmpty(TaskPath) && ProcessUtil.SearchProcA(TaskPath.Substring(TaskPath.LastIndexOf("\\") + 1))) { Notification.Show(TaskName + "运行中,进入维护状态", ToolTipIcon.Info); } else { Notification.Show("发现项目缓存,通过自定义路径启动" + TaskName, ToolTipIcon.Info); ChangeTask(); return; } ConfigCore.ClearCacheMemory(); } else { //无缓存待命 TaskName = TASK_SYS_WAIT_ORDER; NetCore.NetCheck(); Thread.Sleep(1000); NetCore.DisConnect(); Notification.Show("未发现项目缓存,待命中...\n请通过控制与监控端启动" + ConfigCore.Sort + "号虚拟机", ToolTipIcon.Info); } }
//任务监控 public void TaskMonitor() { //最大超时数 int overTime = 30; //最大流量 int maxKb = 200; try { overTime = ConfigCore.GetOverTime(); maxKb = ConfigCore.GetMaxKb(); } catch (Exception e) { Console.WriteLine(e); } //延时 int delay = 1000; if (ConfigCore.IsAdsl) { overTime *= 2; delay /= 2; } //连续在线、离线次数 int p = 0; //计数 int s = 0; //拨号次数 int circle = 0; bool isOnline = false; do { DaemonCore.KeepAlive(); isOnline = Net.IsOnline(); NetCore.CloseException(); if (isOnline && !ConfigCore.IsAdsl && IsAutoVote) { if (Net.GetNetStatic(ConfigCore.AdslName) > maxKb) { LogCore.Write($"{TaskName}流量大于{maxKb}KB,拉黑!"); AutoVote.AddVoteProjectNameDroped(false); SwitchWaitOrder(); } } if (ConfigCore.GetTaskChange().Equals("1")) { TaskChangeProcess(); return; } if (IsSysTask()) { if (ConfigCore.IsAdsl && !isOnline) { LogCore.Write("ADSL待命断网拨号!"); NetCore.NetCheck(); } p = 0; } if (IsAutoVote && AutoVote.FailTooMuch) { LogCore.Write("连续两分钟成功过低,拉黑!"); AutoVote.AddVoteProjectNameDroped(false); SwitchWaitOrder(); } if (TaskName.Equals(TASK_VOTE_JIUTIAN) && p > 0) { if (JiuTian.OverCheck(ref s) || JiuTian.RestrictCheck() || JiuTian.IsIdentifyCode() || JiuTian.VmBanCheck()) { SwitchWaitOrder(); } } else if (TaskName.Equals(TASK_VOTE_MM)) { if (MM.OverCheck() || MM.ExcpCheck() || MM.ErrCheck()) { ProgressCore.KillProcess(false); SwitchWaitOrder(); } } else if (TaskName.Equals(TASK_VOTE_YUANQIU)) { if (YuanQiu.OverCheck()) { ProgressCore.KillProcess(false); SwitchWaitOrder(); } } else if (TaskName.Equals(TASK_VOTE_JT)) { if (JT.OverCheck()) { ProgressCore.KillProcess(false); SwitchWaitOrder(); } } else if (TaskName.Equals(TASK_VOTE_ML)) { //ML到票检测 } else if (TaskName.Equals(TASK_VOTE_DM)) { //DM到票检测 } else if (TaskName.Equals(TASK_VOTE_JZ)) { if (JZ.OverCheck()) { ProgressCore.KillProcess(false); SwitchWaitOrder(); } } else if (TaskName.Equals(TASK_VOTE_HY)) { if (HY.OverCheck()) { ProgressCore.KillProcess(false); SwitchWaitOrder(); } } else if (TaskName.Equals(TASK_VOTE_OUTDO)) { //OUTDO到票检测 } if (isOnline) { p = p < 0 ? 1 : ++p; } else { circle++; p = p > 0 ? -1 : --p; } Thread.Sleep(delay); } while (p == 0 || (p > 0 && p < overTime) || (p < 0 && p > -overTime)); overTimeCount++; LogCore.Write($"超时{overTimeCount}次!"); TaskChangeProcess(); }