123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- using System;
- using System.Collections.Generic;
- using System.Xml;
- using CB.Common;
- using CB.Entity;
- using CB.Entity.Frequency;
- using CB.Interface.Infrastructure.Frequency;
- using CB.LotteryCatchData.Entity;
- using CB.LotteryCatchData.Interface;
- namespace CB.LotteryCatchData.Opencai
- {
- /// <summary>
- /// 湖南幸运赛车数据抓取实现
- /// </summary>
- public class KL8_BeiJing : CatchRepository, ICatchDataProvider
- {
- public override LotteryParamKeys GetLotteryParamKeys(string fileName)
- {
- return GetLotteryParamKeysDefault(fileName);
- }
- public override LotteryOpenCode GetLatestOpenCode()
- {
- return CB.Data.Frequency.KL8BeiJingService.GetLatestOpenCodeForCatch();
- }
- public override IList<LotteryOpenCode> CatchData(LotteryConfigInfo config, LotteryParamKeys keys)
- {
- if (!this.IsCatchData(config, keys))
- return null;
- XmlDocument doc = new XmlDocument();
- try
- {
- doc.Load(config.DataUrl);
- var nodeList = doc.SelectNodes("xml/row");
- if (null == nodeList || 0 >= nodeList.Count)
- return null;
- IList<LotteryOpenCode> list = new List<LotteryOpenCode>();
- LotteryOpenCode entity = null;
- string qi = "";
- string[] data;
- foreach (XmlNode node in nodeList)
- {
- qi = node.Attributes["expect"].Value.Trim();
- if (0 <= keys.LocalTerm.CompareTo(qi))
- continue;
- data = node.Attributes["opencode"].Value.Trim().Split(new char[] { ',', '+' });
- entity = new LotteryOpenCode()
- {
- Term = long.Parse(qi)
- };
- entity.OpenCode = new List<int>();
- entity.OpenCode.Add(TypeConverter.StrToInt(data[0]));
- entity.OpenCode.Add(TypeConverter.StrToInt(data[1]));
- entity.OpenCode.Add(TypeConverter.StrToInt(data[2]));
- entity.OpenCode.Add(TypeConverter.StrToInt(data[3]));
- entity.OpenCode.Add(TypeConverter.StrToInt(data[4]));
- entity.OpenCode.Add(TypeConverter.StrToInt(data[5]));
- entity.OpenCode.Add(TypeConverter.StrToInt(data[6]));
- entity.OpenCode.Add(TypeConverter.StrToInt(data[7]));
- entity.OpenCode.Add(TypeConverter.StrToInt(data[8]));
- entity.OpenCode.Add(TypeConverter.StrToInt(data[9]));
- entity.OpenCode.Add(TypeConverter.StrToInt(data[10]));
- entity.OpenCode.Add(TypeConverter.StrToInt(data[11]));
- entity.OpenCode.Add(TypeConverter.StrToInt(data[12]));
- entity.OpenCode.Add(TypeConverter.StrToInt(data[13]));
- entity.OpenCode.Add(TypeConverter.StrToInt(data[14]));
- entity.OpenCode.Add(TypeConverter.StrToInt(data[15]));
- entity.OpenCode.Add(TypeConverter.StrToInt(data[16]));
- entity.OpenCode.Add(TypeConverter.StrToInt(data[17]));
- entity.OpenCode.Add(TypeConverter.StrToInt(data[18]));
- entity.OpenCode.Add(TypeConverter.StrToInt(data[19]));
- entity.OpenCode.Add(TypeConverter.StrToInt(data[20]));
- entity.Addtime = DateTime.Now;
- entity.OpenTime = GetRealOpenTime(config.StartTime, config.OpenPeriod, qi, TypeConverter.StrToDateTime(node.Attributes["opentime"].Value.Trim(), entity.Addtime), 8, 2);
- list.Add(entity);
- }
- return list;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- public override int SaveData(IList<LotteryOpenCode> list, ref LotteryParamKeys keys)
- {
- if (null == list || 0 >= list.Count)
- return -1;
- int n = 0;
- long term = Convert.ToInt64(keys.LocalTerm);
- DateTime t = keys.LastOpenTime;
- KL8Info_BeiJing entity = null;
- foreach (var item in list)
- {
- entity = new KL8Info_BeiJing()
- {
- Term = item.Term,
- OpenCode1 = item.OpenCode[0],
- OpenCode2 = item.OpenCode[1],
- OpenCode3 = item.OpenCode[2],
- OpenCode4 = item.OpenCode[3],
- OpenCode5 = item.OpenCode[4],
- OpenCode6 = item.OpenCode[5],
- OpenCode7 = item.OpenCode[6],
- OpenCode8 = item.OpenCode[7],
- OpenCode9 = item.OpenCode[8],
- OpenCode10 = item.OpenCode[9],
- OpenCode11 = item.OpenCode[10],
- OpenCode12 = item.OpenCode[11],
- OpenCode13 = item.OpenCode[12],
- OpenCode14 = item.OpenCode[13],
- OpenCode15 = item.OpenCode[14],
- OpenCode16 = item.OpenCode[15],
- OpenCode17 = item.OpenCode[16],
- OpenCode18 = item.OpenCode[17],
- OpenCode19 = item.OpenCode[18],
- OpenCode20 = item.OpenCode[19],
- OpenCode21 = item.OpenCode[20],
- OpenTime = item.OpenTime,
- Addtime = item.Addtime
- };
- if (CB.Data.Frequency.KL8BeiJingService.Save(entity))
- {
- n++;
- if (term < item.Term)
- term = item.Term;
- if (t < item.OpenTime)
- t = item.OpenTime;
- }
- }
- if (0 < n)
- {
- keys.IsCatch = 1;
- keys.LocalTerm = term.ToString();
- keys.LastOpenTime = t;
- }
- return n;
- }
- protected override DateTime GetRealOpenTime(TimeSpan startTime, int openPeriod, string localTerm, DateTime openTime, int startIndex, int length)
- {
- return openTime;
- }
- }
- }
|