示例#1
0
        //任务监控
        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();
        }