Exemplo n.º 1
0
        public void GetLotteryResult(string type, string lotteryCode)
        {
            //api 请求url
            string url = ConfigHelper.BuilderApiUrl(type);

            LogManager.Info(string.Format("开始抓取开奖数据: type={0},lotteryCode={1}", type, lotteryCode));
            //获取开奖结果,如未获取到数据,则轮询指定次数
            int whileCount = 0;

            while (whileCount < ConfigHelper.GetApiLotteryRound)
            {
                var    result = mHttpHelper.DoGet(url);
                string log    = string.Format("expect={0} ,opencode={1} opentime={2} type={3}", result.FirstOrDefault().expect, result.FirstOrDefault().opencode, result.FirstOrDefault().opentime, type);
                LogManager.Info(log);
                if (UpdateLotteryIssueResult(lotteryCode, type, result))
                {
                    break;    //验证,处理成功,跳出循环
                }
                whileCount++; //继续循环拉取数据
                System.Threading.Thread.Sleep(ConfigHelper.GetApiLotterySleep);
            }
        }
        public void Execute(IJobExecutionContext context)
        {
            var groupName = context.Trigger.Key.Name;
            int type      = groupName == "openresult_task" ? 0 : 1;//0为普通 1 为一分彩盒2两分

            LogManager.Info("开始执行开奖任务!" + groupName);
            try
            {
                var result = mLotteryIssuesData.GetNowOpenIssue(type);//获取当前50分钟内存在未开奖数据的集合,进行开奖结果抓取
                foreach (var item in result)
                {
                    //api 请求url
                    string url         = ConfigHelper.BuilderApiUrl(item);
                    var    openResults = mHttpHelper.DoGet(url);//获取开奖对象集合
                    if (null != openResults)
                    {
                        PoolParam param = new PoolParam()
                        {
                            lotteryid     = item,
                            LotteryIssues = openResults
                        };
                        ThreadPool.QueueUserWorkItem(UpdateLotteryIssueResult, param);
                    }
                }

                #region old
                //Dictionary<int, List<LotteryIssue>> asyDictionary = new Dictionary<int, List<LotteryIssue>>();
                //foreach (var item in result)
                //{
                //    List<LotteryIssue> issues = null;
                //    if (!asyDictionary.ContainsKey(item.LotteryId.Value))
                //    {
                //        issues = new List<LotteryIssue>();
                //        asyDictionary.Add(item.LotteryId.Value, issues);
                //    }
                //    else
                //    {
                //        issues = asyDictionary[item.LotteryId.Value];
                //    }
                //    string key = item.LotteryId + "," + item.IssueCode;
                //    if (CalculationQueue.CreateInstance().IsCompledTask(key))
                //    {
                //        issues.Add(item);
                //        LogManager.Error("添加队列key:" + key + " issue:" + item.IssueCode);
                //    }
                //    else
                //    {
                //        LogManager.Error("队列中已经存在key:" + key + " issue:" + item.IssueCode);
                //    }
                //}

                ////获取开奖
                //foreach (var key in asyDictionary.Keys)
                //{
                //    var issue = asyDictionary[key];
                //    string issueCode = "";
                //    issue.ForEach(x => issueCode += x.IssueCode + ",");
                //    LogManager.Info(string.Format("开始执行获取开奖数据逻辑 key={0} issue={1}", key, issueCode));
                //    ThreadPool.QueueUserWorkItem(new WaitCallback(GetLotteryResult), new PoolParam()
                //    {
                //        lottertId = key,
                //        LotteryIssues = issue
                //    });
                //}
                #endregion
            }
            catch (Exception ex)
            {
                LogManager.Error("执行开奖任务异常", ex);
            }
        }