using Interface; using Services; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Models.Entity.LotteryNumDB; using Cache.Entity; using Models; using Common; using Business.KJH; namespace Cache { public static class Ctrl { private static LotteryNumInterface services; private static Dictionary MlotteryData; private static Object ZXView; private static int UpTK = 300; private static DateTime lotteryLastUpTime; private static DateTime ZXviewUpTime; static Ctrl() { services = new LotteryService(); MlotteryData = new Dictionary(); lotteryLastUpTime = DateTime.Now; ZXviewUpTime = new DateTime(); ZXView = new object(); // GetList(); } private static void Test() { } private static void lotteryDoUpdate() { if (MlotteryData.Count==0) { GetList(); } if ((DateTime.Now- lotteryLastUpTime).TotalSeconds> UpTK) { GetList(); lotteryLastUpTime = DateTime.Now; } } public static bool ZXViewNeedUpdate() { if (ZXView==null) { return false; } if ((DateTime.Now - ZXviewUpTime).TotalSeconds > UpTK) { // ZXView = data; // ZXviewUpTime = DateTime.Now; return false; } return true; } public static object GetZXView() { return ZXView; } public static void SETZXView(object data) { ZXView = data; ZXviewUpTime = DateTime.Now; } private static void GetList() { var list = KJBLL.GetLotteryList(); for (int i = 0; i < list.Count; i++) { var lottery = Enum.Parse(typeof(SCCLottery), list[i].LotteryType); if (ZSlotterType.TypeOfNameDict.Keys.Contains(list[i].LotteryType)) { list[i].HasLotteryZS = true; } list[i].LotteryText = EnumHelper.GetLotteryText((SCCLottery)lottery); MlotteryData[list[i].LotteryType] = list[i]; } //var gpcresult = new { c11x5 = new { Name = "11选5", Data = c11x5 }, k3 = new { Name = "快3", Data = k3 }, klsf = new { Name = "快乐十分", Data = klsf }, kl12 = new { Name = "快乐12", Data = kl12 }, qt = new { Name = "其他彩种", Data = qt } }; // var res = new { QGC = qgc, DFC = dfc, GPC = gpcresult }; } /// /// 返回单个 /// /// /// public static LotteryData GetLottery(string typename) { try { if (!MlotteryData.Keys.Contains(typename)) { lotteryDoUpdate(); return MlotteryData[typename]; } else { return MlotteryData[typename]; } } catch (Exception ee) { return null; ; } } /// /// 返回所有缓存对象 /// /// public static List GetLottery() { try { if (MlotteryData.Keys.Count == 0) { lotteryDoUpdate(); } return MlotteryData.Values.ToList(); } catch (Exception ee) { return null; } } } }