コード例 #1
0
        public IList <LotteryData> RequestNewDatas()
        {
            if (_iscrawlingData)
            {
                return(null);
            }
            _iscrawlingData = true;

            try
            {
                LogDbHelper.LogDebug("正在从" + _dataSite.Name + "爬取数据", GetType().FullName + "=>RequestNewDatas", OperationType.Job);
                var dataList = CrawNewDatas();
                if (dataList.Count <= 0)
                {
                    LogDbHelper.LogDebug("从" + _dataSite.Name + "爬取数据失败,没有获取到最新的数据", GetType().FullName + "=>RequestNewDatas", OperationType.Job);
                }
                else
                {
                    LogDbHelper.LogDebug("从" + _dataSite.Name + "爬取数据成功,共爬取到" + dataList.Count + "条数据", GetType().FullName + "=>RequestNewDatas", OperationType.Job);
                }

                return(dataList);
            }
            catch (Exception e)
            {
                LogDbHelper.LogError("从" + _dataSite.Name + "爬取数据失败,原因" + e.Message, GetType().FullName + "=>RequestNewDatas", OperationType.Job);
                return(null);
            }
            finally
            {
                _iscrawlingData = false;
            }
        }
コード例 #2
0
 internal void PutThisRegionData(KeyValuePair <int, PeriodNumberInfo> keyValuePair)
 {
     if (keyValuePair.Value.ThreeRegionShape == _regionShape)
     {
         if (!_keyNumbers.ContainsKey(keyValuePair.Key))
         {
             _keyNumbers.Add(keyValuePair);
         }
         else
         {
             LogDbHelper.LogDebug("已经存在了当前期" + keyValuePair.Key + "的数据分析", GetType() + "PutThisRegionData");
         }
     }
     ;
 }
コード例 #3
0
        private void RequestData(DataSite dataSite)
        {
            var dataUpdateItem = ObtainDataUpdateItemByReflect(dataSite);

            if (dataUpdateItem == null)
            {
                throw new LSException("获取彩票开始数据数据爬取器失败.=>" + dataSite.Name + dataSite.Id);
            }

            var newDataList = dataUpdateItem.RequestNewDatas();

            lock (_lockObject)
            {
                if (newDataList != null && newDataList.Count > 0)
                {
                    //必须排序
                    newDataList = newDataList.OrderBy(p => p.Period).ToList();
                    foreach (var newData in newDataList)
                    {
                        if (!_lotteryDataAppService.ExsitData(_lotteryDataJob.LotteryType.ToString(), newData.Period))
                        {
                            var lastLotteryData = _lotteryDataAppService.Insert(newData);
                            _lastPeriod = lastLotteryData.Period;
                            string key = AppUtils.GetLotteryRedisKey(lastLotteryData.LotteryType, LsConstant.LastLotteryDataCacheKey);
                            CacheHelper.SetCache(key, lastLotteryData);
                            // todo:更新彩票分析数据
                            var lotteryEngine =
                                LotteryEngine.GetLotteryEngine(
                                    Utils.StringConvertEnum <LotteryType>(lastLotteryData.LotteryType));
                            lotteryEngine.CalculateNextLotteryData();
                        }
                    }
                    LogDbHelper.LogDebug(string.Format("更新彩票{0}开奖数据数据成功,共{1}条数据", _lotteryDataJob.LotteryType, newDataList.Count),
                                         GetType().FullName + "=>RequestData", OperationType.Job);
                    _lotteryDataJob.NextLotteryTime = _lotteryUpdateConfig.NextLotteryTime;
                }
            }
        }