Esempio n. 1
0
        public static DateTime GenerateGXKL10FYesterdayOpenTime(SCCConfig config, string QiHao)
        {
            var openDay   = SCCSysDateTime.AddDays(-1);
            var StartTime = new DateTime(openDay.Year, openDay.Month, openDay.Day, config.StartHour, config.StartMinute, 0);

            return(StartTime.AddMinutes((Convert.ToInt32(QiHao.Substring(7)) - 1) * config.Interval));
        }
Esempio n. 2
0
        /// <summary>
        /// 组装主站爬取地址
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        private List <string> GetMainUrl(SCCConfig config)
        {
            List <string> urlList = new List <string>();
            string        url     = config.MainUrl;
            int           pages   = config.MainUrlPages > 0 ? config.MainUrlPages : 1;

            for (int i = 1; i <= pages; i++)
            {
                string res;
                if (i == 1)
                {
                    res = "http://www.zhcw.com/xinwen/caizhongxinwenqlc/";
                }
                else
                {
                    res = string.Format(url, i);
                }

                if (!urlList.Contains(res))
                {
                    urlList.Add(res);
                }
            }
            return(urlList);
        }
Esempio n. 3
0
        /// <summary>
        /// 组装二级页面三要素
        /// </summary>
        /// <returns></returns>
        private SystemThreeElementsViewEntity AppendSecondElements(string type)
        {
            SystemThreeElementsViewEntity res = Cache.Factory.CacheFactory.Cache().GetCache <SystemThreeElementsViewEntity>(CacheKeyEnum.SystemThreeElements.ToString() + "__" + type + "__");

            if (res == null)
            {
                res = new SystemThreeElementsViewEntity();

                string keywordTemplate = ConfigHelper.GetValue("SystemElementsKeywords");
                string descTemplate    = ConfigHelper.GetValue("SystemElementsDescription");

                //获取当前彩种配置信息
                SCCConfig config = LotteryConfig.FirstOrDefault(s => s.EnumCode.Equals(type));
                if (config != null)
                {
                    res.Keywords    = keywordTemplate.Replace("$Name$", config.LotteryName);
                    res.Description = descTemplate.Replace("$Name$", config.LotteryName);
                }
                else
                {
                    bool isSucc = Enum.TryParse <SCCLottery>(type, true, out SCCLottery lottery);
                    //SCCLottery type = (SCCLottery)Enum.Parse(typeof(SCCLottery), arg.EnumCode, true);
                    if (isSucc)
                    {
                        res.Keywords    = keywordTemplate.Replace("$Name$", lottery.GetEnumDescription());
                        res.Description = descTemplate.Replace("$Name$", lottery.GetEnumDescription());
                    }
                }
                Cache.Factory.CacheFactory.Cache().WriteCache(res, CacheKeyEnum.SystemThreeElements.ToString() + "__" + type + "__", DateTimeHelper.Now.AddDays(30));
            }
            return(res);
        }
Esempio n. 4
0
        public ActionResult GetTodaysLottery()
        {
            Dictionary <string, SCCConfig> dict = GetTodayLotteryDict();
            List <TodaysLotteryViewEntity> obj  = new List <TodaysLotteryViewEntity>();

            foreach (KeyValuePair <string, SCCConfig> pair in dict)
            {
                SCCConfig  config = pair.Value;
                SCCLottery type   = (SCCLottery)Enum.Parse(typeof(SCCLottery), config.EnumCode, true);
                //当前彩种今天真实开始开奖时间
                DateTime todayRealStartOpentime = (DateTimeHelper.Now.ToString("yyyy-MM-dd") + " " + config.StartHour + ":" + config.StartMinute).TryToDateTime();
                //如果当前时间大于当前彩种今天真实开始开奖时间,则忽略
                if (DateTimeHelper.Now < todayRealStartOpentime)
                {
                    string lastTerm = qgfc3Dbll.GetNewTermByTableName(type.GetSCCLotteryTableName());
                    obj.Add(new TodaysLotteryViewEntity
                    {
                        LotteryName = config.LotteryName,
                        Term        = lastTerm,
                        OpenTime    = todayRealStartOpentime,
                        MainUrl     = config.MainUrl,
                        EnumCode    = config.EnumCode
                    });
                }
            }
            obj = obj.OrderBy(o => o.OpenTime).ToList();
            return(Success("操作成功", obj.ToJson()));
        }
Esempio n. 5
0
        /// <summary>
        /// 检查今天该地方彩是否应该开奖
        /// 是则进行爬取工作
        /// </summary>
        /// <param name="config">配置信息</param>
        /// <returns></returns>
        public static bool CheckTodayIsOpenDay(SCCConfig config)
        {
            var week = SCCSysDateTime.DayOfWeek.ToString("d");

            if (config.KJTime.Contains(week))
            {
                return(true);
            }
            return(false);
        }
Esempio n. 6
0
        /// <summary>
        /// 核实该地方彩程序运行时间是否应该获取到数据
        /// 开奖第二天检查时应该抓取到开奖数据才正确
        /// </summary>
        /// <param name="config">配置信息</param>
        /// <returns></returns>
        public static bool CheckDTIsNeedGetData(SCCConfig config)
        {
            var week = SCCSysDateTime.AddDays(-1).DayOfWeek.ToString("d");

            if (config.KJTime.Contains(week))//第二天只检查1次//&& SCCSysDateTime.Hour < 1
            {
                return(true);
            }
            return(false);
        }
Esempio n. 7
0
        /// <summary>
        /// 组装主站爬取地址
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        private List <string> GetMainUrl(SCCConfig config)
        {
            List <string> urlList = new List <string>();
            string        url     = config.MainUrl;
            int           pages   = config.MainUrlPages > 0 ? config.MainUrlPages : 1;

            for (int i = 1; i <= pages; i++)
            {
                string res = string.Format(url, i);
                if (!urlList.Contains(res))
                {
                    urlList.Add(res);
                }
            }
            return(urlList);
        }
Esempio n. 8
0
        /// <summary>
        /// 从作业数据地图中获取配置信息
        /// </summary>
        /// <param name="datamap">作业数据地图</param>
        /// <returns></returns>
        public static SCCConfig GetConfigFromDataMap(JobDataMap datamap)
        {
            SCCConfig config     = new SCCConfig();
            var       properties = typeof(SCCConfig).GetProperties();

            foreach (PropertyInfo info in properties)
            {
                if (info.PropertyType == typeof(string))
                {
                    info.SetValue(config, datamap.GetString(info.Name), null);
                }
                else if (info.PropertyType == typeof(Int32))
                {
                    info.SetValue(config, datamap.GetInt(info.Name), null);
                }
            }
            return(config);
        }
Esempio n. 9
0
        /// <summary>
        /// 批量发送邮件
        /// </summary>
        private void SendEmail()
        {
            if (dictionary.Count > 0)
            {
                //当前时间
                DateTime now = DateTimeHelper.Now;

                Task task = Task.Factory.StartNew(() =>
                {
                    StringBuilder builder = new StringBuilder();
                    foreach (KeyValuePair <string, SCCConfig> pair in dictionary)
                    {
                        if (!sendEmailSuccList.Contains(pair.Key))
                        {
                            SCCConfig config = pair.Value;
                            //当前彩种今天真实开始开奖时间
                            string todayRealStartOpentime = now.ToString("yyyy-MM-dd") + " " + config.StartHour.RepairZero() + ":" + config.StartMinute.RepairZero();

                            builder.Append(config.LotteryName + ",开奖时间:" + todayRealStartOpentime + ";<br />");//<a href='" + config.MainUrl + "  target='_blank''>[参考网址]</a>

                            //添加到已经开奖集合,下一次就需要发送邮件了
                            sendEmailSuccList.Add(pair.Key);

                            Trace.WriteLine(config.LotteryName + "  添加成功!");
                        }
                    }
                    if (!string.IsNullOrEmpty(builder.ToString()))
                    {
                        string body = "管理员请注意,以下彩种将在30分钟后开奖:<br /><br />" + StringHelper.DelLastChar(builder.ToString(), ";") + "。";
                        //发送邮件
                        string address = ConfigHelper.GetValue("ErrorReportTo");
                        string subject = "开奖提醒";

                        MailHelper.SendByThread(address, subject, body);
                    }
                });
                task.Wait();
            }
        }
Esempio n. 10
0
        /// <summary>
        /// 生成地方彩昨天的开奖时间
        /// </summary>
        /// <param name="config">配置信息</param>
        /// <returns></returns>
        public static DateTime GenerateDTOpenTime(SCCConfig config)
        {
            var openday = SCCSysDateTime.AddDays(-1);

            return(new DateTime(openday.Year, openday.Month, openday.Day, config.StartHour, config.StartMinute, 0));
        }
Esempio n. 11
0
 public static string GetJobLogError(SCCConfig config, string QiHao)
 {
     return(string.Format("【{0}】抓取{1}期开奖数据失败", config.Area + config.LotteryName, QiHao));
 }
Esempio n. 12
0
 public static string GetJobBackLogInfo(SCCConfig config, string QiHao)
 {
     return(string.Format("【{0}】通过备用地址抓取{1}期开奖数据成功", config.Area + config.LotteryName, QiHao));
 }
Esempio n. 13
0
        /// <summary>
        /// 获取今日对应期号的开奖时间
        /// 期号需形如YYMMDDQQ或YYMMDDQQQ
        /// </summary>
        /// <param name="config">配置项</param>
        /// <param name="QiHao">开奖期号</param>
        /// <returns></returns>
        public static DateTime GenerateTodayOpenTime(SCCConfig config, string QiHao)
        {
            var StartTime = new DateTime(SCCSysDateTime.Year, SCCSysDateTime.Month, SCCSysDateTime.Day, config.StartHour, config.StartMinute, 0);

            return(StartTime.AddMinutes((Convert.ToInt32(QiHao.Substring(6)) - 1) * config.Interval));
        }