예제 #1
0
        private static bool CanBroadcast(BroadcastInfoItem broadcastInfoItem, BroadcastTimeItem lastBroadcastTimeItem, int weekDayID, int hour, int minute)
        {
            bool result;

            if (null == broadcastInfoItem.Times)
            {
                result = false;
            }
            else
            {
                if (!string.IsNullOrEmpty(broadcastInfoItem.WeekDays))
                {
                    if (-1 == broadcastInfoItem.WeekDays.IndexOf(weekDayID.ToString()))
                    {
                        return(false);
                    }
                }
                if (broadcastInfoItem.KaiFuStartDay > 0)
                {
                    DateTime jugeDateTime = Global.GetKaiFuTime();
                    if (2 == broadcastInfoItem.TimeType)
                    {
                        jugeDateTime = Global.GetHefuStartDay();
                    }
                    else if (3 == broadcastInfoItem.TimeType)
                    {
                        jugeDateTime = Global.GetJieriStartDay();
                    }
                    DateTime todayTime = TimeUtil.NowDateTime();
                    int      currday   = Global.GetOffsetDay(todayTime);
                    int      jugeday   = Global.GetOffsetDay(jugeDateTime);
                    if (currday - jugeday < broadcastInfoItem.KaiFuStartDay)
                    {
                        return(false);
                    }
                    if (broadcastInfoItem.KaiFuShowType > 0)
                    {
                        if (currday - jugeday >= broadcastInfoItem.KaiFuStartDay + broadcastInfoItem.KaiFuShowType)
                        {
                            return(false);
                        }
                    }
                }
                int lastTime = lastBroadcastTimeItem.Hour * 60 + lastBroadcastTimeItem.Minute;
                int nowTime  = hour * 60 + minute;
                for (int i = 0; i < broadcastInfoItem.Times.Length; i++)
                {
                    int itemTime = broadcastInfoItem.Times[i].Hour * 60 + broadcastInfoItem.Times[i].Minute;
                    if (itemTime > lastTime)
                    {
                        if (nowTime >= itemTime)
                        {
                            return(true);
                        }
                    }
                }
                result = false;
            }
            return(result);
        }
예제 #2
0
 private static BroadcastTimeItem[] ParseBroadcastTimeItems(string times)
 {
     BroadcastTimeItem[] result;
     if (string.IsNullOrEmpty(times))
     {
         result = null;
     }
     else
     {
         string[] fields = times.Split(new char[]
         {
             '|'
         });
         if (fields.Length <= 0)
         {
             result = null;
         }
         else
         {
             BroadcastTimeItem[] broadcastTimeItemArray = new BroadcastTimeItem[fields.Length];
             for (int i = 0; i < fields.Length; i++)
             {
                 string str = fields[i].Trim();
                 if (string.IsNullOrEmpty(str))
                 {
                     return(null);
                 }
                 string[] fields2 = str.Split(new char[]
                 {
                     ':'
                 });
                 if (fields2 == null || fields2.Length != 2)
                 {
                     return(null);
                 }
                 broadcastTimeItemArray[i] = new BroadcastTimeItem
                 {
                     Hour   = Global.SafeConvertToInt32(fields2[0]),
                     Minute = Global.SafeConvertToInt32(fields2[1])
                 };
             }
             result = broadcastTimeItemArray;
         }
     }
     return(result);
 }
예제 #3
0
        /// <summary>
        /// 解析时间段
        /// </summary>
        /// <param name="times"></param>
        /// <returns></returns>
        private static BroadcastTimeItem[] ParseBroadcastTimeItems(string times)
        {
            if (string.IsNullOrEmpty(times))
            {
                return(null);
            }

            string[] fields = times.Split('|');
            if (fields.Length <= 0)
            {
                return(null);
            }

            BroadcastTimeItem[] broadcastTimeItemArray = new BroadcastTimeItem[fields.Length];
            for (int i = 0; i < fields.Length; i++)
            {
                string str = fields[i].Trim();
                if (string.IsNullOrEmpty(str))
                {
                    return(null);
                }

                string[] fields2 = str.Split(':');
                if (null == fields2 || fields2.Length != 2)
                {
                    return(null);
                }

                broadcastTimeItemArray[i] = new BroadcastTimeItem()
                {
                    Hour   = Global.SafeConvertToInt32(fields2[0]),
                    Minute = Global.SafeConvertToInt32(fields2[1]),
                };
            }

            return(broadcastTimeItemArray);
        }
예제 #4
0
        /// <summary>
        /// 是否能否播放
        /// </summary>
        /// <param name="broadcastInfoItem"></param>
        /// <returns></returns>
        private static bool CanBroadcast(BroadcastInfoItem broadcastInfoItem, BroadcastTimeItem lastBroadcastTimeItem, int weekDayID, int hour, int minute)
        {
            if (null == broadcastInfoItem.Times)
            {
                return(false);
            }

            //如果要限制周日期
            if (!string.IsNullOrEmpty(broadcastInfoItem.WeekDays))
            {
                if (-1 == broadcastInfoItem.WeekDays.IndexOf(weekDayID.ToString()))
                {
                    return(false);
                }
            }

            if (broadcastInfoItem.KaiFuStartDay > 0) //根据开服后几天来播报
            {
                DateTime jugeDateTime = Global.GetKaiFuTime();
                if (2 == broadcastInfoItem.TimeType) //合服
                {
                    jugeDateTime = Global.GetHefuStartDay();
                }
                else if (3 == broadcastInfoItem.TimeType) //节日
                {
                    jugeDateTime = Global.GetJieriStartDay();
                }

                DateTime todayTime = DateTime.Now;

                if ((int)todayTime.DayOfYear - (int)jugeDateTime.DayOfYear >= broadcastInfoItem.KaiFuStartDay)
                {
                    if (broadcastInfoItem.KaiFuShowType > 0)
                    {
                        if (todayTime.DayOfYear - jugeDateTime.DayOfYear < (broadcastInfoItem.KaiFuStartDay + broadcastInfoItem.KaiFuShowType))
                        {
                            ///可以播报
                        }
                        else
                        {
                            return(false); //不播报
                        }
                    }
                }
                else
                {
                    return(false); //不播报
                }
            }

            int lastTime = lastBroadcastTimeItem.Hour * 60 + lastBroadcastTimeItem.Minute;
            int nowTime  = hour * 60 + minute;

            for (int i = 0; i < broadcastInfoItem.Times.Length; i++)
            {
                int itemTime = broadcastInfoItem.Times[i].Hour * 60 + broadcastInfoItem.Times[i].Minute;
                if (itemTime <= lastTime) //已经广播过了
                {
                    continue;
                }

                if (nowTime >= itemTime)
                {
                    return(true);
                }
            }

            return(false);
        }