Beispiel #1
0
        /// <summary>
        /// 定时控制
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timerClick_Tick(object sender, EventArgs e)
        {
            weiboTimer.Enabled = false;

            weiboProgressBar.Value = Math.Min(weiboProgressBar.Maximum, timerAct.getIndex());

            Act act = timerAct.getNowAct();

            if (act == null)
            {
                showStatus("没有任务可执行了。定时任务结束");
                weiboTimer.Interval = 50;
                onoffTimerToolStripMenuItem.Text = "启动定时";

                return;
            }

            stepLab.Text = act.getContent().Replace("\t", " ");
            this.Refresh();

            //延时一定时间
            if (!act.isSleep)
            {
                weiboTimer.Interval = act.interval;
                act.isSleep         = true;
                //showTimerStatus("延时:" + act.interval);

                weiboTimer.Enabled = true;
                return;
            }
            else
            {
                if (act.act == "set")//设置内容
                {
                    switch (act.mainArg)
                    {
                    case "用户名": userTxt.Text = act.viceArg; break;

                    case "密码": pwdTxt.Text = act.viceArg; break;

                    case "搜索内容": searchTxt.Text = act.viceArg; break;

                    case "页码":
                        if (act.viceArg == "++")
                        {
                            pageTxt.Text = int.Parse(pageTxt.Text) + 1 + "";
                        }
                        else
                        {
                            pageTxt.Text = act.viceArg;
                        }
                        break;

                    case "评论第几个":
                        if (act.viceArg == "++")
                        {
                            noTxt.Text = int.Parse(noTxt.Text) + 1 + "";
                        }
                        else
                        {
                            noTxt.Text = act.viceArg;
                        }
                        break;

                    case "评论内容":
                        string comment = "";
                        try
                        {
                            if (act.viceArg.Trim() == "随机")
                            {
                                Random r = new Random();
                                comment = comments[r.Next(comments.Count)];
                            }
                            else
                            {
                                comment = comments[int.Parse(act.viceArg)];
                            }
                        }
                        catch (Exception e1)
                        {
                            showStatus("出错了:" + e1.Message);
                            comment = act.viceArg;
                        }
                        contentTxt.Text = comment;
                        break;
                    }
                    showStatus(act.getContent().Replace("\t", " "));
                    timerAct.addIndex();
                }
                else if (act.act == "click")//执行点击
                {
                    switch (act.mainArg)
                    {
                    case "打开微博": openWeiboBtn_Click(sender, e); break;

                    case "登录": loginBtn_Click(sender, e); break;

                    case "搜索": searchBtn2_Click(sender, e); break;

                    case "翻页": pageBtn_Click(sender, e); break;

                    case "打开评论": openFeedBtn_Click(sender, e); break;

                    case "发表评论": submitBtn_Click(sender, e); break;
                    }
                    showStatus(act.getContent().Replace("\t", " "));
                    timerAct.addIndex();
                }
                else if (act.act == "other")
                {
                    timerAct.addIndex();
                }
                else if (act.act == "gostep")
                {
                    //gostep条件判断
                    string condition = act.viceArg;
                    string a         = "";
                    if (condition.Contains("页码"))
                    {
                        a         = pageTxt.Text;
                        condition = condition.Replace("页码", "");
                    }
                    else if (condition.Contains("评论第几个"))
                    {
                        a         = noTxt.Text;
                        condition = condition.Replace("评论第几个", "");
                    }

                    if (condition.Trim() == "已评论过")
                    {
                        haveComment(act);
                    }
                    else if (condition.Trim() == "不是指定来自")
                    {
                        filterFrom(act);
                    }
                    else
                    {
                        bool res = false;
                        if (a == "")
                        {
                            showStatus("gostep 判断A为空,跳过");
                            timerAct.addIndex();
                        }
                        else
                        {
                            if (condition.Contains(">="))
                            {
                                if (int.Parse(a) >= int.Parse(condition.Replace(">=", "").Trim()))
                                {
                                    res = true;
                                }
                            }
                            else if (condition.Contains("<="))
                            {
                                if (int.Parse(a) <= int.Parse(condition.Replace("<=", "").Trim()))
                                {
                                    res = true;
                                }
                            }
                            else if (condition.Contains(">"))
                            {
                                if (int.Parse(a) > int.Parse(condition.Replace(">", "").Trim()))
                                {
                                    res = true;
                                }
                            }
                            else if (condition.Contains("<"))
                            {
                                if (int.Parse(a) < int.Parse(condition.Replace("<", "").Trim()))
                                {
                                    res = true;
                                }
                            }
                            else if (condition.Contains("="))
                            {
                                if (int.Parse(a) == int.Parse(condition.Replace("=", "").Trim()))
                                {
                                    res = true;
                                }
                            }
                            //条件满足,跳转
                            if (res)
                            {
                                int s = 0;
                                try
                                {
                                    s = int.Parse(act.mainArg);
                                    showStatus("满足条件:" + act.viceArg + " 跳转:" + int.Parse(act.mainArg));
                                    timerAct.setIndex(int.Parse(act.mainArg));
                                }
                                catch { showStatus("主参数跳转布编号,需要为数字:" + act.mainArg); }
                            }
                            else
                            {
                                timerAct.addIndex();
                                showStatus("不满足条件,直接下一步");
                            }
                        }
                    }
                }
            }
            weiboTimer.Interval = 50;
            weiboTimer.Enabled  = true;
        }