TvDatabase.TvBusinessLayer.SearchMinimalPrograms C# (CSharp) Method

SearchMinimalPrograms() public method

public SearchMinimalPrograms ( System.DateTime startTime, System.DateTime endTime, string programName, TvDatabase.Channel channel ) : IList
startTime System.DateTime
endTime System.DateTime
programName string
channel TvDatabase.Channel
return IList
    public IList<Program> SearchMinimalPrograms(DateTime startTime, DateTime endTime, string programName,
                                                Channel channel)
    {
      return channel != null
               ? GetProgramsByTitle(channel, startTime, endTime, programName)
               : GetProgramsByTitle(startTime, endTime, programName);
    }

Usage Example

    private void PopulateListviewWithUpcomingEpisodes(Program lastSelectedProgram)
    {
      int itemToSelect = -1;
      lstUpcomingEpsiodes.Clear();
      TvBusinessLayer layer = new TvBusinessLayer();
      DateTime dtDay = DateTime.Now;

      // build a list of all upcoming instances of program from EPG data based on program name alone
      List<Program> episodes = (List<Program>)layer.SearchMinimalPrograms(dtDay, dtDay.AddDays(28), initialProgram.Title, null);

      // now if schedule is time based then build a second list for that schedule based on start time (see below)
      IList<Program> actualUpcomingEps = new List<Program>();      
      if (currentSchedule != null)
      {
        int scheduletype = currentSchedule.ScheduleType;        

        switch (scheduletype)
        {
          case (int)ScheduleRecordingType.Weekly:
            actualUpcomingEps = Program.RetrieveWeekly(initialProgram.StartTime, initialProgram.EndTime, initialProgram.IdChannel);
            break;

          case (int)ScheduleRecordingType.Weekends:
            actualUpcomingEps = Program.RetrieveWeekends(initialProgram.StartTime, initialProgram.EndTime, initialProgram.IdChannel);
            break;

          case (int)ScheduleRecordingType.WorkingDays:
            actualUpcomingEps = Program.RetrieveWorkingDays(initialProgram.StartTime, initialProgram.EndTime, initialProgram.IdChannel);
            break;

          case (int)ScheduleRecordingType.Daily:
          actualUpcomingEps = Program.RetrieveDaily(initialProgram.StartTime, initialProgram.EndTime, initialProgram.IdChannel);
          break;
        }
       
        // now if we have a time based schedule then loop through that and if entry does not exist
        // in the original list then add it
        // an entry will exist in the second list but not first if the program name is different
        // in reality this will probably be a series that has finished
        // eg. we have set a schedule for channel X for Monday 21:00 to 22:00 which happens to be when 
        // program A is on.   The series for program A finishes and now between 21:00 and 22:00 on 
        // channel X is program B.   A time based schedule does not take the program name into account
        // therefore program B will get recorded.
        if (actualUpcomingEps.Count > 0)
        {
          for (int i = actualUpcomingEps.Count - 1; i >= 0; i--)
          {
            Program ep = actualUpcomingEps[i];

            if (!episodes.Contains(ep))
            {
              episodes.Add(ep);
            }
          }
          episodes.Sort((x, y) => (x.StartTime.CompareTo(y.StartTime))); //resort list locally on starttime
        }

      }
      bool updateCurrentProgram = true;
      anyUpcomingEpisodesRecording = false;
      int activeRecordings = 0;
      for (int i = 0; i < episodes.Count; i++)
      {        
        Program episode = episodes[i];
        GUIListItem item = new GUIListItem();
        item.Label = TVUtil.GetDisplayTitle(episode);
        item.OnItemSelected += item_OnItemSelected;
        string logo = Utils.GetCoverArt(Thumbs.TVChannel, episode.ReferencedChannel().DisplayName);
        if (string.IsNullOrEmpty(logo))                      
        {
          item.Label = String.Format("{0} {1}", episode.ReferencedChannel().DisplayName, TVUtil.GetDisplayTitle(episode));
          logo = "defaultVideoBig.png";
        }

        bool isActualUpcomingEps = actualUpcomingEps.Contains(episode) ;
        bool isRecPrg = isActualUpcomingEps;
        Schedule recordingSchedule = currentSchedule;

        // appears a little odd but seems to work
        // if episode is not in second (time based) list then override isRecPrg by actually
        // checking if episode is due to be recorded (if it is in second (time based) list then
        // it is going to be recorded
        if (!isActualUpcomingEps)
        {
            isRecPrg = (episode.IsRecording || episode.IsRecordingOncePending || episode.IsRecordingSeriesPending || 
                        episode.IsPartialRecordingSeriesPending) && IsRecordingProgram(episode, out recordingSchedule, true);
        }
        if (isRecPrg)
        {          
          if (!recordingSchedule.IsSerieIsCanceled(recordingSchedule.GetSchedStartTimeForProg(episode), episode.IdChannel))
          {
            bool hasConflict = recordingSchedule.ReferringConflicts().Count > 0;
            bool isPartialRecording = false;
            bool isSeries = (recordingSchedule.ScheduleType != (int)ScheduleRecordingType.Once);

            //check for partial recordings.
            if (isActualUpcomingEps && currentSchedule != null)
            {
              isPartialRecording = Schedule.IsPartialRecording(currentSchedule, episode);
            }
            if (isPartialRecording)
            {
              item.PinImage = hasConflict ? 
                (isSeries? Thumbs.TvConflictPartialRecordingSeriesIcon : Thumbs.TvConflictPartialRecordingIcon) : 
                (isSeries? Thumbs.TvPartialRecordingSeriesIcon : Thumbs.TvPartialRecordingIcon);
            }
            else
            {
              item.PinImage = hasConflict ? 
                (isSeries? Thumbs.TvConflictRecordingSeriesIcon : Thumbs.TvConflictRecordingIcon) : 
                (isSeries? Thumbs.TvRecordingSeriesIcon : Thumbs.TvRecordingIcon);
            }

            if (updateCurrentProgram)
            {
              //currentProgram = episode;
            }
            activeRecordings++;
            anyUpcomingEpisodesRecording = true;
            updateCurrentProgram = false;
          }          
          item.TVTag = recordingSchedule;
        }
        else
        {
          if (episode.Notify)
          {
            item.PinImage = Thumbs.TvNotifyIcon;
          }
        }

        item.MusicTag = episode;
        item.ThumbnailImage = item.IconImageBig = item.IconImage = logo;

        item.Label2 = String.Format("{0} {1} - {2}",
                                    Utils.GetShortDayString(episode.StartTime),
                                    episode.StartTime.ToString("t", CultureInfo.CurrentCulture.DateTimeFormat),
                                    episode.EndTime.ToString("t", CultureInfo.CurrentCulture.DateTimeFormat));

        if (lastSelectedProgram != null)
        {
          if (lastSelectedProgram.IdChannel == episode.IdChannel &&
              lastSelectedProgram.StartTime == episode.StartTime &&
              lastSelectedProgram.EndTime == episode.EndTime && lastSelectedProgram.Title == episode.Title)
          {
            itemToSelect = lstUpcomingEpsiodes.Count;
          }
        }
        lstUpcomingEpsiodes.Add(item);
      }


      if (!anyUpcomingEpisodesRecording)
      {
        currentProgram = initialProgram;
      }

      if (itemToSelect != -1)
      {
        lstUpcomingEpsiodes.SelectedListItemIndex = itemToSelect;
      }

      lblUpcomingEpsiodes.Label = GUILocalizeStrings.Get(1203, new object[] { activeRecordings });

      //set object count label
      GUIPropertyManager.SetProperty("#itemcount", Utils.GetObjectCountLabel(lstUpcomingEpsiodes.ListItems.Count));
    }
All Usage Examples Of TvDatabase.TvBusinessLayer::SearchMinimalPrograms
TvBusinessLayer