コード例 #1
0
ファイル: DapperHelper.cs プロジェクト: wqh3944/Grap
 public static int setTaskState(LotteryTask t)
 {
     using (IDbConnection connection = new MySqlConnection(constr))
     {
         return(connection.Execute("update task set state=@state where TaskID=@TaskID", t));
     }
 }
コード例 #2
0
ファイル: MyJob.cs プロジェクト: wqh3944/Grap
        public Task Execute(IJobExecutionContext context)
        {
            return(Task.Run(() =>
            {
                JobDataMap data = context.JobDetail.JobDataMap;
                DateTime starttime = data.GetDateTimeValue("StartTime");
                DateTime endtime = data.GetDateTimeValue("EndTime");
                if (endtime < starttime)
                {
                    endtime = endtime.AddDays(1);
                }

                if (DateTime.Now <= endtime && DateTime.Now >= starttime)
                {
                    int lid = data.GetIntValue("LotteryID");
                    Console.WriteLine(DateTime.Now + ",LotteryID:" + lid);
                    Lottery l = DapperHelper.getLotteryByID(lid);
                    if (l != null)
                    {
                        LotteryTask t = new LotteryTask();
                        t.lotteryID = lid;
                        t.website = l.website;
                        t.lotteryType = l.lotteryType;
                        t.lotteryName = l.lotteryName;
                        t.state = 0;
                        t.createTime = DateTime.Now;
                        DapperHelper.setTask(t);
                    }
                }
            }));
        }
コード例 #3
0
        public bool ConsumeTask(LotteryTask t)
        {
            task = t;
            Browser.InitBrowser();

            Console.Write("开始采集:" + task.website);
            //彩种种类
            string subPage = GetLotteryType(task.website);
            //开奖结果
            LotteryResult lr = GetResult(subPage);

            Console.Write("采集结果:" + lr.ToString());

            bool cmp = true;
            //对比结果
            List <LotteryResult> lrs = DapperHelper.getResultByNo(lr.No.Substring(lr.No.Length - 6, 6), lr.lotteryType);

            for (int i = 0; i < lrs.Count; i++)
            {
                if (lrs[i].Number != lr.Number || lrs[i].guanYaHe != lr.guanYaHe)
                {
                    cmp = false;
                }
            }

            lr.isRight = cmp;

            DapperHelper.setLotteryResult(lr);

            return(cmp);
        }
コード例 #4
0
 public static int setTask(LotteryTask task)
 {
     using (IDbConnection connection = new MySqlConnection(constr))
     {
         string sql    = @" INSERT INTO task(lotteryID,website,lotteryType,lotteryName,state,createTime)
      VALUES(@lotteryID,@website,@lotteryType,@lotteryName,@state,@createTime); ";
         int    result = connection.Execute(sql, task); //直接传送list对象
         return(result);
     }
 }
コード例 #5
0
ファイル: Program.cs プロジェクト: wqh3944/Grap
        static void Main(string[] args)
        {
            LotteryTask t = DapperHelper.getOneTask();

            if (t != null)
            {
                Console.WriteLine(string.Format("获取到采集任务:采集网站:{0} 彩票名称:{1}", t.website, t.lotteryType));
                t.state = 1;
                DapperHelper.setTaskState(t);


                Picker taskConsumer = new Picker();
                bool   cmp          = taskConsumer.ConsumeTask(t);

                Console.WriteLine("任务结束,采集结果:" + cmp);

                t.state = 2;
                DapperHelper.setTaskState(t);
                Browser.cd.Quit();
            }
        }