示例#1
0
        /// <summary>
        /// 获取定时播的插入位置。
        /// </summary>
        /// <param name="startTime"></param>
        /// <returns></returns>
        private int FindTimingInsertIndex(DateTime startTime)
        {
            // 获取定时播或定时插播的插入位置。
            // 第一个开始时间大于等于startTime的索引(-1表示列表为空或开始时间全部小于startTime)
            int index = _playlist.FindFirstIndex((i) => !i.IsSkipped() && i.ScheduleInfo.StartTime >= startTime);

            // index==-1是在尾部插入(包含_playlist为空的情况)。
            index = index < 0 ? _playlist.Count : index;
            return(index);
        }
        internal static void EnsureNoTimingConflict(this IPlaylist playlist, DateTime startTime, TimeSpan duration)
        {
            var stopTime = startTime.Add(duration);

            var index = playlist.FindFirstIndex((i) =>
                                                (i.ScheduleInfo.ScheduleMode == ScheduleMode.Timing || i.ScheduleInfo.ScheduleMode == ScheduleMode.TimingBreak) &&
                                                !i.IsSkipped() &&
                                                (i.ScheduleInfo.StopTime > startTime && i.ScheduleInfo.StartTime < stopTime)); //!(i.ScheduleInfo.StopTime<=startTime || i.ScheduleInfo.StartTime>=stopTime)

            if (index >= 0)
            {
                var item = playlist[index];
                throw new InvalidOperationException(string.Format("与{0}'{1}'之间有时间冲突。",
                                                                  item.ScheduleInfo.ScheduleMode == ScheduleMode.Timing ? "定时播" : "定时插播", item.Title));
            }
        }
 public static int FindFirstIndex(this IPlaylist playlist, Func <IPlaylistItem, bool> predicate)
 {
     return(playlist.FindFirstIndex(0, predicate));
 }