Example #1
0
        public virtual List <StatutoryHoliday> StatutoryHolidays(int?year = null, params int[] month)
        {
            var statutory_holidays = new List <StatutoryHoliday>();

            #region 请求范围,默认请求当前年份所有月的假日信息

            var months = new List <string>();

            if (year.HasValue && month.Length > 0)
            {
                months = month.Where(w => w > 0 && w < 13)
                         .Select(q => String.Concat(year.Value, q.ToString().PadLeft(2, '0')))
                         .ToList();
            }
            else
            {
                for (int i = 1; i <= 12; i++)
                {
                    months.Add(String.Concat(DateTime.Now.Year, i.ToString().PadLeft(2, '0')));
                }
            }

            #endregion

            #region 请求三方假日安排接口并解析数据

            var srcResponse = Network.Request.Get(String.Concat("http://www.easybots.cn", $"/api/holiday.php?ak=k438.4928942901b4d60a898b165e17565976@{AppConfig.DOMAIN_SUFFIX}&m=", String.Join(",", months)));

            //按月份划分数据
            var regex_holidays = new Regex("(\"\\d{6}\":\\{(\"\\d{2}\":\"[0|1|2]\"[,|\\}])+)");
            //匹配月份数值
            var regex_holiday_month = new Regex("\\d{6}");
            //匹配月份值中的日期信息
            var regex_holiday_month_day = new Regex("(\"\\d{2}\":\"[0|1|2]\")");

            //按月划分的假日安排
            var holidayCollection = regex_holidays.Matches(srcResponse);
            foreach (var holiday in holidayCollection)
            {
                var holidayMonth  = regex_holiday_month.Match(holiday.ToString());
                var dayCollection = regex_holiday_month_day.Matches(holiday.ToString());

                var statutory_holiday = new StatutoryHoliday()
                {
                    Month = holidayMonth.Value
                };

                foreach (var day in dayCollection)
                {
                    var _day = day.ToString().Replace("\"", "").Split(':');
                    statutory_holiday.Days.Add(_day[0], int.Parse(_day[1]));
                }
                statutory_holidays.Add(statutory_holiday);
            }

            #endregion

            return(statutory_holidays);
        }
Example #2
0
        public virtual List <StatutoryHoliday> StatutoryHolidays2(int?year = null, params int[] month)
        {
            var statutory_holidays = new List <StatutoryHoliday>();

            #region 请求范围,默认请求当前年份所有月的假日信息

            var months = new List <string>();

            if (year.HasValue && month.Length > 0)
            {
                months = month.Where(w => w > 0 && w < 13)
                         .Select(q => String.Concat(year.Value, q.ToString().PadLeft(2, '0')))
                         .ToList();
            }
            else
            {
                for (int i = 1; i <= 12; i++)
                {
                    months.Add(String.Concat(DateTime.Now.Year, i.ToString().PadLeft(2, '0')));
                }
            }

            #endregion

            #region 请求三方假日安排接口并解析数据

            var srcResponse = Network.Request.Get(String.Concat("http://tool.bitefu.net", "/jiari/?type=list&apikey=123456&d=", String.Join(",", months)));

            //按月份划分数据
            var regex_holidays = new Regex("(\"\\d{6}\":\\{(\"\\d{4}\":\"[0|1|2]\"[,|\\}])+)");
            //匹配月份数值
            var regex_holiday_month = new Regex("\\d{6}");
            //匹配月份值中的日期信息
            var regex_holiday_month_day = new Regex("(\"\\d{4}\":\"[0|1|2]\")");

            //按月划分的假日安排
            var holidayCollection = regex_holidays.Matches(srcResponse);
            foreach (var holiday in holidayCollection)
            {
                var holidayMonth  = regex_holiday_month.Match(holiday.ToString());
                var dayCollection = regex_holiday_month_day.Matches(holiday.ToString());

                var statutory_holiday = new StatutoryHoliday()
                {
                    Month = holidayMonth.Value
                };

                foreach (var day in dayCollection)
                {
                    var _day = day.ToString().Replace("\"", "").Split(':');
                    statutory_holiday.Days.Add(_day[0].Substring(2), int.Parse(_day[1]));
                }
                statutory_holidays.Add(statutory_holiday);
            }

            #endregion

            return(statutory_holidays);
        }