//public static void Start() //{ // ThreadStart start = new ThreadStart(GetLetteryInfo); // Thread th = new Thread(start); // th.IsBackground = true; // th.Start(); //} public static void GetLetteryInfo() { try { string path = System.AppDomain.CurrentDomain.BaseDirectory; string fullPath = path + "LotteryWebsite.xml"; XDocument doc = XDocument.Load(fullPath); var website = doc.Descendants("webSite").Select(p => new { lotteryType = p.Element("lotteryType").Value, url = p.Element("url").Value }).ToList(); BetLotteryProcess betprocess = new BetLotteryProcess(); ResultProcess resProcess = new ResultProcess(); foreach (var item in website) { string html = HttpGet(item.url, Encoding.UTF8); LotteryResultService lrService = new LotteryResultService(); Dictionary <string, JObject> dicreds = DeserializeStringToDictionary <string, JObject>(html); foreach (var dictionary in dicreds) { LotteryResult existLotteryResult = lrService.LoadEntities(s => s.LotteryType == item.lotteryType && s.Expect == dictionary.Key).FirstOrDefault(); if (existLotteryResult != null) { continue; } JObject lottery = dictionary.Value; LotteryResult lotteryResult = new LotteryResult(); lotteryResult.LotteryType = item.lotteryType; lotteryResult.Expect = dictionary.Key; lotteryResult.Opencode = lottery["number"].ToString(); //开奖日期不能用接口反回的时间,不准确 //if (lotteryResult.LotteryType.Equals("六合彩")) lotteryResult.Opentime = GetRealOpenTime(lotteryResult.LotteryType, DateTime.Parse(lottery["dateline"].ToString())); lotteryResult.Opentime = lotteryResult.Opentime.Value.AddSeconds(0 - lotteryResult.Opentime.Value.Second); //else //{ // LotteryResult beforeResult = lrService.LoadEntities(s => s.LotteryType == item.lotteryType).OrderByDescending(s => s.Expect).FirstOrDefault(); // if (beforeResult == null) // lotteryResult.Opentime = GetRealOpenTime(lotteryResult.LotteryType, DateTime.Parse(lottery["dateline"].ToString())); // else // lotteryResult.Opentime = beforeResult.NextOpenTime; //} if (lotteryResult.LotteryType.Equals("六合彩")) { GetHttpInfoForlhc.GetlhcInfo(lotteryResult); } else { lotteryResult.NextExpect = resProcess.GetNextExpect(item.lotteryType, lotteryResult.Expect); lotteryResult.NextOpenTime = resProcess.GetNextOpenTime(item.lotteryType, lotteryResult.Opentime.Value); } lrService.AddEntity(lotteryResult); betprocess.ProcessBet(lotteryResult); } } } catch (Exception ex) { throw; } }
public JsonResult GetLotteryRecordForNewList() { List <LotteryResult> retList = new List <LotteryResult>(); string[] lotteryTypearray = new string[] { "广东快乐十分", "广东11选5", "重庆时时彩", "六合彩", "百家乐三公" }; //取每种彩票最新一期的开奖数据 for (int i = 0; i < lotteryTypearray.Length; i++) { string itemType = lotteryTypearray[i]; LotteryResult item = new LotteryResultService().LoadEntities(s => s.LotteryType.Equals(itemType)).OrderByDescending(s => s.Expect).FirstOrDefault(); if (item != null) { retList.Add(item); } } return(Json(retList.OrderByDescending(s => s.Opentime), JsonRequestBehavior.AllowGet)); }