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); }
/// <summary> /// 解析Xml项 /// </summary> /// <param name="systemXmlItem"></param> private static void ParseXmlItem(SystemXmlItem systemXmlItem, List <BroadcastInfoItem> broadcastInfoItemList) { int id = systemXmlItem.GetIntValue("ID"); int infoClass = systemXmlItem.GetIntValue("InfoClass"); int hintErrID = systemXmlItem.GetIntValue("HintErrID"); int timeType = systemXmlItem.GetIntValue("TimeType"); int kaiFuStartDay = systemXmlItem.GetIntValue("StartDay"); int kaiFuShowType = systemXmlItem.GetIntValue("ShowType"); string weekDays = systemXmlItem.GetStringValue("WeekDays"); string times = systemXmlItem.GetStringValue("Times"); string text = systemXmlItem.GetStringValue("Text"); string onlineNotice = systemXmlItem.GetStringValue("OnlineNotice"); int minZhuanSheng = systemXmlItem.GetIntValue("MinZhuanSheng"); int minLevel = systemXmlItem.GetIntValue("MinLevel"); if (string.IsNullOrEmpty(times)) { LogManager.WriteLog(LogTypes.Error, string.Format("解析广播配置表中的时间项失败, ID={0}", id)); return; } BroadcastTimeItem[] broadcastTimeItemArray = ParseBroadcastTimeItems(times); if (null == broadcastTimeItemArray) { LogManager.WriteLog(LogTypes.Error, string.Format("解析广播配置表中的时间项为数组时失败, ID={0}", id)); return; } if (string.IsNullOrEmpty(text)) { LogManager.WriteLog(LogTypes.Error, string.Format("解析广播配置表中的时间项失败, ID={0}", id)); return; } DateTimeRange[] onlineNoticeTimeRanges = Global.ParseDateTimeRangeStr(onlineNotice); BroadcastInfoItem broadcastInfoItem = new BroadcastInfoItem() { ID = id, InfoClass = infoClass, HintErrID = hintErrID, TimeType = timeType, KaiFuStartDay = kaiFuStartDay, KaiFuShowType = kaiFuShowType, WeekDays = weekDays, Times = broadcastTimeItemArray, OnlineNoticeTimeRanges = onlineNoticeTimeRanges, Text = text.Replace(":", ""), //防止出现半角的冒号 MinZhuanSheng = minZhuanSheng, MinLevel = minLevel, }; broadcastInfoItemList.Add(broadcastInfoItem); }
/// <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); }