Esempio n. 1
0
        public void CheckFailTooMuch()
        {
            if (IsVoteTask())
            {
                int succ = 0;
                if (TaskName.Equals(TASK_VOTE_JIUTIAN))
                {
                    TimerChecked++;
                    succ = JiuTian.GetSucc();
                }
                else if (TaskName.Equals(TASK_VOTE_MM))
                {
                    TimerChecked++;
                    succ = MM.GetSucc();
                }
                else if (TaskName.Equals(TASK_VOTE_YUANQIU))
                {
                    TimerChecked++;
                    succ = YuanQiu.GetSucc();
                }

                if (succ - SuccCount < 2 && TimerChecked >= 2)
                {
                    FailTooMuch = true;
                }

                LogCore.Write("success:" + succ + " last:" + SuccCount);
                SuccCount = succ;
            }
        }
Esempio n. 2
0
        public static void CheckSucc()
        {
            TaskCore taskCore = MonitorCore.GetTaskCore();
            string   taskName = taskCore.TaskName;

            if (taskCore.IsVoteTask())
            {
                var succ = 0;
                if (taskName.Equals(TaskCore.TASK_VOTE_JIUTIAN))
                {
                    succ = JiuTian.GetSucc();
                }
                else if (taskName.Equals(TaskCore.TASK_VOTE_MM))
                {
                    succ = MM.GetSucc();
                }
                else if (taskName.Equals(TaskCore.TASK_VOTE_YUANQIU))
                {
                    succ = YuanQiu.GetSucc();
                }

                if (succ == 0)
                {
                    succ = succCount;
                }

                double price = 0;
                try
                {
                    price = double.Parse(ConfigCore.GetAutoVote("Price"));
                }
                catch (Exception)
                {
                }

                var name       = ConfigCore.GetAutoVote("ProjectName");
                var validCount = price >= 1 ? 1 : 2;
                var diff       = succ - succCount;
                if (diff < validCount)
                {
                    timerChecked++;
                    if (timerChecked >= 2)
                    {
                        FailTooMuch = true;
                    }
                }
                else
                {
                    timerChecked = 0;
                }

                if (diff > 0)
                {
                    Statistics.Add(name, price, diff);
                }
                LogCore.Write("成功:" + succ + " 上次成功:" + succCount);
                succCount = succ;
            }
        }
Esempio n. 3
0
        private static void ErrReconnect()
        {
            IntPtr adslErr = HwndUtil.FindWindow("#32770", "连接到 " + ConfigCore.AdslName + " 时出错");

            if (adslErr != IntPtr.Zero)
            {
                IntPtr hwndEx = HwndUtil.FindWindowEx(adslErr, IntPtr.Zero, "Button", null);
                string title  = HwndUtil.GetControlText(hwndEx);
                if (title.IndexOf("重拨") != -1)
                {
                    LogCore.Write($"{ConfigCore.AdslName}拨号出错,重播");
                    HwndUtil.clickHwnd(hwndEx);
                }
            }
        }
Esempio n. 4
0
        //添加黑名单项目 临
        public static void AddVoteProjectNameDropedTemp()
        {
            string   projectName = ConfigCore.GetAutoVote("ProjectName");
            TaskInfo taskInfo    = TaskInfos.Get();

            if (taskInfo != null && taskInfo.ProjectName != projectName)
            {
                return;
            }

            string voteProjectNameDroped = ConfigCore.GetAutoVote("voteProjectNameDropedTemp");
            int    dropVote = 0;

            try
            {
                dropVote = int.Parse(ConfigCore.GetAutoVote("dropVote"));
            }
            catch (Exception)
            {
            }
            finally
            {
                dropVote++;
            }

            ConfigCore.WriteAutoVote("dropVote", dropVote.ToString());
            if (StringUtil.isEmpty(voteProjectNameDroped) || voteProjectNameDroped.IndexOf(projectName) == -1)
            {
                int validDrop;
                try
                {
                    validDrop = int.Parse(ConfigCore.GetAutoVote("validDrop"));
                }
                catch (Exception)
                {
                    validDrop = 1;
                }

                if (dropVote >= validDrop)
                {
                    LogCore.Write($"{projectName}到票临时拉黑5分钟");
                    voteProjectNameDroped +=
                        StringUtil.isEmpty(voteProjectNameDroped) ? projectName : "|" + projectName;
                    ConfigCore.WriteAutoVote("voteProjectNameDropedTemp", voteProjectNameDroped);
                }
            }
        }
Esempio n. 5
0
        public static bool WaitOnline()
        {
            int count    = 0;
            int maxCount = 60000 / 20;

            while (!IsOnline())
            {
                Thread.Sleep(20);
                count++;
                if (count > maxCount)
                {
                    LogCore.Write("等待拨号完成超时,强制结束!");
                    return(true);
                }
            }
            return(true);
        }
Esempio n. 6
0
        public static bool InitConfig()
        {
            if (File.Exists(BaseConfig))
            {
                string pathShare = InitPathShare();
                if (StringUtil.isEmpty(pathShare))
                {
                    MessageBox.Show("共享不能为空!");
                    return(false);
                }

                string sort  = IniReadWriter.ReadIniKeys("Command", "bianhao", BaseConfig);
                string delay = IniReadWriter.ReadIniKeys("Command", "yanchi", BaseConfig);
                if (StringUtil.isEmpty(sort))
                {
                    MessageBox.Show("编号不能为空!");
                    return(false);
                }

                try
                {
                    Sort  = int.Parse(sort);
                    Delay = int.Parse(delay);
                }
                catch (Exception)
                {
                    MessageBox.Show("编号及延时只能是数字,请重新设置!");
                    return(false);
                }

                Form1.SetFormData(Sort, Delay, pathShare);
                AdslName = RasName.GetAdslName();
                IsAdsl   = AdslName == "宽带连接";
                LogCore.Write($"获取默认ADSL拨号名称:{AdslName}");
                return(true);
            }
            else
            {
                MessageBox.Show("请设置后在启动!");
                return(false);
            }
        }
Esempio n. 7
0
 public static void Protect()
 {
     if (!alive)
     {
         if (count < 2)
         {
             count += 1;
             LogCore.Write("【守护线程】超过2分钟无活动,重置监控线程");
             ComCore.ReMake();
             ProgressCore.KillProcess(false);
             ConfigCore.SwitchNetTest();
             TaskInfos.Clear();
             Form1.MainRestart();
         }
         else
         {
             Process.Start("shutdown.exe", "-r -t 0");
             Form1.MainClose();
         }
     }
     alive = false;
 }
Esempio n. 8
0
 public static void MonitorThread()
 {
     Notification.Show("启动监控程序", ToolTipIcon.Info);
     try
     {
         ComCore.ReMake();
         TaskCore taskCore = GetTaskCore();
         taskCore.InitTask();
         while (true)
         {
             taskCore.TaskMonitor();
         }
     }
     catch (ThreadAbortException)
     {
     }
     catch (Exception e)
     {
         LogCore.Write(e.StackTrace);
         MessageBox.Show(e.StackTrace);
     }
 }
Esempio n. 9
0
        private static void ThreadProcess(object obj)
        {
            string pathName = obj.ToString();

            try
            {
                ProcessStartInfo info = new ProcessStartInfo();
                info.FileName         = pathName;
                info.Arguments        = "";
                info.WorkingDirectory = pathName.Substring(0, pathName.LastIndexOf("\\"));
                info.WindowStyle      = ProcessWindowStyle.Normal;
                Process pro = Process.Start(info);
                pro.WaitForExit();
                pro.Close();
                Thread.Sleep(500);
            }
            catch (Exception e)
            {
                LogCore.Write("拒绝访问,待命");
                MonitorCore.GetTaskCore().WaitOrder();
                //Process.Start("shutdown.exe", "-r -t 0");
            }
        }
Esempio n. 10
0
        //关闭进程
        public static void KillProcess(bool stopIndicator)
        {
            TaskCore taskCore = MonitorCore.GetTaskCore();
            string   taskName = taskCore.TaskName;

            //传票结束
            if (stopIndicator && taskCore.IsVoteTask() && !taskName.Equals(TaskCore.TASK_VOTE_PROJECT))
            {
                LogCore.Write($"{taskCore.ProjectName}传票结束!");
                if (taskName.Equals(TaskCore.TASK_VOTE_JIUTIAN))
                {
                    JiuTian.StopAndUpload();
                }
                else if (taskName.Equals(TaskCore.TASK_VOTE_YUANQIU))
                {
                    YuanQiu.StopAndUpload();
                }
                else if (taskName.Equals(TaskCore.TASK_VOTE_JZ))
                {
                    JZ.StopAndUpload();
                }
                else if (taskName.Equals(TaskCore.TASK_VOTE_JT))
                {
                    JT.StopAndUpload();
                }
                else if (taskName.Equals(TaskCore.TASK_VOTE_HY))
                {
                    HY.StopAndUpload();
                }
                else if (taskName.Equals(TaskCore.TASK_VOTE_MM))
                {
                    MM.StopAndUpload();
                }
            }
            Kill();
        }
Esempio n. 11
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();
        }
Esempio n. 12
0
        //切换任务
        private void ChangeTask()
        {
            if (TaskChange.Equals("1"))
            {
                overTimeCount = 0;
                ConfigCore.InitWorker("");
                CustomPath = ConfigCore.GetCustomPath();
                if (CustomPath != "")
                {
                    LogCore.Write($"切换任务:{CustomPath}");
                }

                if (IsVoteTask() && IsAutoVote)
                {
                    string projectName = ConfigCore.GetAutoVote("ProjectName");
                    string drop        = "";
                    try
                    {
                        drop = IniReadWriter.ReadIniKeys("Command", "drop", "./handler.ini");
                    }
                    catch (Exception)
                    {
                    }

                    if (drop != projectName)
                    {
                        IniReadWriter.WriteIniKeys("Command", "drop", "", "./handler.ini");
                    }
                }
            }

            if (TaskName.Equals(TASK_SYS_WAIT_ORDER)) //待命
            {
                NetCore.DisConnect();
                TaskName = ConfigCore.GetTaskName();
                if (TaskName.Equals(TASK_SYS_WAIT_ORDER))
                {
                    WaitOrder();
                }
            }
            else if (TaskName.Equals(TASK_SYS_NET_TEST)) //网络TEST
            {
                NetCore.NetCheck();
                if (Net.IsOnline())
                {
                    NetCore.DisConnect();
                    WaitOrder();
                }
            }
            else if (TaskName.Equals(TASK_SYS_SHUTDOWN)) //关机
            {
                WaitOrder();
                Process.Start("shutdown.exe", "-s -t 0");
                Form1.MainClose();
            }
            else if (TaskName.Equals(TASK_SYS_RESTART)) //重启
            {
                string computerRename = ConfigCore.GetComputerRename();
                if (!StringUtil.isEmpty(computerRename))
                {
                    Computer.apiSetComputerNameEx(5, computerRename + "-" + ConfigCore.Sort);
                }

                WaitOrder();
                Process.Start("shutdown.exe", "-r -t 0");
                Form1.MainClose();
            }
            else if (TaskName.Equals(TASK_SYS_UPDATE)) //升级
            {
                WaitOrder();
                Upgrade.Update();
                Form1.MainClose();
            }
            else if (TaskName.Equals(TASK_SYS_CLEAN)) //清理
            {
                WaitOrder();
                FileUtil.DeleteFolder(PathCore.WorkingPath + "\\投票项目");
            }
            else if (IsVoteTask()) //投票
            {
                NetCore.NetCheck();
                if (CustomPath.Equals(""))
                {
                    WaitOrder();
                    TaskChangeProcess();
                    return;
                }

                if (TaskChange.Equals("1"))
                {
                    if (CustomPath.LastIndexOf("\\") + 1 <= CustomPath.Length && CustomPath.Substring(CustomPath.LastIndexOf("\\") + 1) == "vote.exe")
                    {
                        ProgressCore.StartProcess(CustomPath.Substring(0, CustomPath.Length - 9) + @"\启动九天.bat");
                        TaskName = TASK_VOTE_JIUTIAN;
                    }
                    else
                    {
                        IniReadWriter.WriteIniKeys("setsoft", "ghid", ConfigCore.Id, "c:\\gonghao.ini");
                        ProgressCore.StartProcess(CustomPath);
                        TaskName = TASK_VOTE_PROJECT;
                        IntPtr hwnd0, hwnd1, hwnd2, hwnd3, hwnd4;
                        do
                        {
                            hwnd0 = HwndUtil.FindWindow("WTWindow", null);
                            hwnd1 = HwndUtil.FindWindow("TForm1", null);
                            hwnd2 = HwndUtil.FindWindow("ThunderRT6FormDC", null);
                            hwnd3 = HwndUtil.FindWindow("obj_Form", null);
                            hwnd4 = HwndUtil.FindWindow("TMainForm", null);
                            if (hwnd0 != IntPtr.Zero)
                            {
                                string title = HwndUtil.GetControlText(hwnd0);
                                if (title.Length >= 6 && title.Substring(0, 6) == "自动投票工具")
                                {
                                    TaskName = TASK_VOTE_MM;
                                }
                                else if (title.Length >= 8 && title.Substring(0, 8) == "VOTE2016")
                                {
                                    TaskName = TASK_VOTE_ML;
                                }
                                else if (title.IndexOf("自动投票软件") != -1)
                                {
                                    TaskName = TASK_VOTE_HY;
                                }
                            }
                            else if (hwnd1 != IntPtr.Zero)
                            {
                                TaskName = TASK_VOTE_YUANQIU;
                            }
                            else if (hwnd2 != IntPtr.Zero)
                            {
                                TaskName = TASK_VOTE_JT;
                            }
                            else if (hwnd3 != IntPtr.Zero)
                            {
                                TaskName = TASK_VOTE_DM;
                            }
                            else if (hwnd4 != IntPtr.Zero)
                            {
                                TaskName = TASK_VOTE_JZ;
                            }

                            Thread.Sleep(500);
                        } while (TaskName.Trim().Equals(TASK_VOTE_PROJECT));
                    }

                    bool safeWrite = false;
                    Thread.Sleep(ConfigCore.Sort % 10 * 50);
                    do
                    {
                        try
                        {
                            ConfigCore.WriteTaskName(TaskName);
                            Thread.Sleep(200);
                            string taskNameCheck = ConfigCore.GetTaskName();
                            if (StringUtil.isEmpty(taskNameCheck) || !taskNameCheck.Equals(TaskName))
                            {
                                LogCore.Write("TaskName Write Error!");
                                ConfigCore.WriteTaskName(TaskName);
                                throw new Exception();
                            }

                            safeWrite = true;
                        }
                        catch (Exception)
                        {
                            Thread.Sleep(ConfigCore.Sort % 10 * 50);
                        }
                    } while (!safeWrite);
                }

                if (TaskName.Equals(TASK_VOTE_JIUTIAN))
                {
                    if (!TaskChange.Equals("1"))
                    {
                        ProgressCore.StartProcess(CustomPath.Substring(0, CustomPath.Length - 9) + @"\启动九天.bat");
                        Thread.Sleep(500);
                    }

                    JiuTian.Start();
                }
                else
                {
                    if (!TaskChange.Equals("1"))
                    {
                        ProgressCore.StartProcess(CustomPath);
                        Thread.Sleep(500);
                    }

                    if (TaskName.Equals(TASK_VOTE_MM))
                    {
                        MM.Start();
                    }
                    else if (TaskName.Equals(TASK_VOTE_ML))
                    {
                        //ML开始程序
                    }
                    else if (TaskName.Equals(TASK_VOTE_YUANQIU))
                    {
                        YuanQiu.Start();
                    }
                    else if (TaskName.Equals(TASK_VOTE_JT))
                    {
                        JT.start();
                    }
                    else if (TaskName.Equals(TASK_VOTE_DM))
                    {
                        //DM开始程序
                    }
                    else if (TaskName.Equals(TASK_VOTE_JZ))
                    {
                        JZ.start();
                    }
                    else if (TaskName.Equals(TASK_VOTE_HY))
                    {
                        HY.Start();
                    }
                }

                TaskPath = CustomPath;
            }
            else
            {
                TaskName = TASK_SYS_WAIT_ORDER;
            }
        }
Esempio n. 13
0
        public static List <VoteProject> GetVoteProjects()
        {
            HttpManager httpUtil = HttpManager.getInstance();
            string      result   = "";

            do
            {
                try
                {
                    result = httpUtil.requestHttpGet(
                        "http://butingzhuan.com/tasks.php?t=" + DateTime.Now.Millisecond.ToString(), "", "");
                }
                catch (Exception)
                {
                    LogCore.Write("Request Fail!Retry in 10s...");
                    Thread.Sleep(10000);
                }
            } while (result == "");

            result = result.Substring(result.IndexOf("时间</td>"));
            result = result.Substring(0, result.IndexOf("qzd_yj"));
            result = result.Substring(result.IndexOf("<tr class='blank'>"));
            result = result.Substring(0, result.LastIndexOf("<tr class='blank'>"));
            if (DateTime.Now.Minute % 30 == 0)
            {
                LogCore.Write("AutoVote: Keep Alive! Finished Request!     " + DateTime.Now.ToString());
            }

            Regex              regTR           = new Regex(@"(?is)<tr[^>]*>(?:(?!</tr>).)*</tr>");
            Regex              regTD           = new Regex(@"(?is)<t[dh][^>]*>((?:(?!</td>).)*)</t[dh]>");
            MatchCollection    mcTR            = regTR.Matches(result);
            List <VoteProject> voteProjectList = new List <VoteProject>();

            foreach (Match mTR in mcTR)
            {
                if (mTR.Value.IndexOf("不换") == -1)
                {
                    MatchCollection mcTD        = regTD.Matches(mTR.Value);
                    int             index       = 0;
                    VoteProject     voteProject = new VoteProject();
                    foreach (Match mTD in mcTD)
                    {
                        string innerTd = mTD.Groups[1].Value;
                        //Log.writeLogs("./log.txt", "***"+index);
                        //Log.writeLogs("./log.txt", mTD.Value);
                        switch (index)
                        {
                        case 2:
                            voteProject.ProjectName = HtmlMatch.GetContent(innerTd, "a");
                            break;

                        case 5:
                            voteProject.Price = double.Parse(innerTd);
                            break;

                        case 7:
                            String[] quantityInfo = mTD.Value.Split('"');
                            quantityInfo = quantityInfo[1].Split('/');
                            try
                            {
                                voteProject.Remains = long.Parse(innerTd.Trim());
                                if (!StringUtil.isEmpty(quantityInfo[0].Trim()))
                                {
                                    voteProject.FinishQuantity = long.Parse(quantityInfo[0]);
                                }

                                voteProject.TotalRequire =
                                    long.Parse(quantityInfo[1].Substring(0, quantityInfo[1].IndexOf(" ")));
                            }
                            catch (Exception)
                            {
                            }

                            break;

                        case 8:
                            voteProject.BackgroundAddress = HtmlMatch.GetAttr(innerTd, "a", "href");
                            break;

                        case 9:
                            voteProject.DownloadAddress = HtmlMatch.GetAttr(innerTd, "a", "href");
                            break;

                        case 10:
                            try
                            {
                                voteProject.IdType = HtmlMatch.GetAttr(innerTd, "input", "value").Substring(0, 2);
                            }
                            catch (Exception)
                            {
                                if (innerTd.IndexOf("BT-") != -1)
                                {
                                    voteProject.IdType = "BT";
                                }
                                else if (innerTd.IndexOf("AQ-") != -1)
                                {
                                    voteProject.IdType = "AQ";
                                }
                                else if (innerTd.IndexOf("Q7-") != -1)
                                {
                                    voteProject.IdType = "Q7";
                                }
                            }

                            break;

                        case 12:
                            voteProject.BackgroundNo = innerTd;
                            break;

                        case 13:
                            voteProject.RefreshDate = Convert.ToDateTime(DateTime.Now.Year + "-" + innerTd + ":00");
                            break;
                        }

                        index++;
                    }

                    voteProject.IsRestrict = voteProject.BackgroundNo.IndexOf("限制") != -1;
                    voteProjectList.Add(voteProject);
                }
            }

            return(voteProjectList);
        }
Esempio n. 14
0
        public static void testVoteProjectMonitorList()
        {
            for (int i = 0; i < voteProjectMonitorList.Count; i++)
            {
                VoteProject voteProject = voteProjectMonitorList[i];
                if (voteProject.Remains > 0 && (voteProject.Remains * voteProject.Price) > 100 &&
                    !voteProject.IsRestrict)
                {
                    Console.WriteLine("projectName:" + voteProject.ProjectName + ",price:" + voteProject.Price +
                                      ",remains:" + voteProject.Remains);
                    HttpManager httpManager = HttpManager.getInstance();
                    string      pathName    = "c:/downloads/" +
                                              voteProject.DownloadAddress.Substring(
                        voteProject.DownloadAddress.LastIndexOf("/") + 1);
                    string url = voteProject.DownloadAddress;
                    string now = DateTime.Now.ToLocalTime().ToString();
                    LogCore.Write("开始下载:" + url);
                    downLoadCount = 0;
                    bool isDownloading = true;
                    do
                    {
                        try
                        {
                            httpManager.HttpDownloadFile(url, pathName);
                            isDownloading = false;
                        }
                        catch (Exception)
                        {
                            LogCore.Write(voteProject.ProjectName + "  下载异常,重新下载");
                            File.Delete(pathName);
                            Thread.Sleep(1000);
                        }
                    } while (isDownloading);

                    LogCore.Write(pathName + "  下载完成");
                    Winrar.UnCompressRar("c:/projects/" + voteProject.ProjectName,
                                         pathName,
                                         voteProject.DownloadAddress.Substring(voteProject.DownloadAddress.LastIndexOf("/") + 1));
                    if (!File.Exists("c:/projects/" + voteProject.ProjectName + "/启动九天.bat"))
                    {
                        String[] Lines = { @"start vote.exe" };
                        File.WriteAllLines("c:/projects/" + voteProject.ProjectName + "/启动九天.bat",
                                           Lines, Encoding.GetEncoding("GBK"));
                    }

                    try
                    {
                        File.Delete(pathName);
                    }
                    catch (IOException)
                    {
                        LogCore.Write(pathName + "-->文件占用中,无法删除!");
                    }

                    activeVoteProject = voteProject;
                    LogCore.Write("AutoVote: " + voteProject.ProjectName + " " + voteProject.BackgroundNo + "    " +
                                  DateTime.Now.ToLocalTime().ToString());
                    break;
                }
            }
        }
Esempio n. 15
0
        //添加黑名单项目
        public static void AddVoteProjectNameDroped(bool isAllProject)
        {
            string projectName = ConfigCore.GetAutoVote("ProjectName");
            //一机器只允许拉黑投票一次
            string   drop     = IniReadWriter.ReadIniKeys("Command", "drop", "./handler.ini");
            TaskInfo taskInfo = TaskInfos.Get();

            if ((taskInfo != null && taskInfo.ProjectName != projectName) || drop == projectName)
            {
                return;
            }

            IniReadWriter.WriteIniKeys("Command", "drop", projectName, "./handler.ini");
            string voteProjectNameDroped = ConfigCore.GetAutoVote("voteProjectNameDroped");
            int    dropVote = 0;

            try
            {
                dropVote = int.Parse(ConfigCore.GetAutoVote("dropVote"));
            }
            catch (Exception)
            {
            }
            finally
            {
                dropVote++;
            }

            if (isAllProject)
            {
                if (projectName.IndexOf("_") > 0)
                {
                    projectName = projectName.Substring(0, projectName.IndexOf("_"));
                }
            }

            ConfigCore.WriteAutoVote("dropVote", dropVote.ToString());
            if (StringUtil.isEmpty(voteProjectNameDroped) || voteProjectNameDroped.IndexOf(projectName) == -1)
            {
                int    validDrop = 1;
                double blackRate = 1;
                try
                {
                    validDrop = int.Parse(ConfigCore.GetAutoVote("validDrop"));
                }
                catch { }
                try
                {
                    blackRate = int.Parse(ConfigCore.GetAutoVote("blackRate"));
                }
                catch { }
                if (dropVote >= validDrop)
                {
                    IniReadWriter.WriteIniKeys("Command", "drop", "", "./handler.ini");
                    LogCore.Write($"{projectName}拉黑{blackRate * 20}分钟");
                    voteProjectNameDroped +=
                        StringUtil.isEmpty(voteProjectNameDroped) ? projectName : "|" + projectName;
                    ConfigCore.WriteAutoVote("voteProjectNameDroped", voteProjectNameDroped);
                }
            }
        }