Ejemplo n.º 1
0
        private IMBotMessage DoSearchResults(IMBotConversation conversation, int resultNumber)
        {
            if (!conversation.Session.ContainsKey(SessionKey.FoundTitles))
            {
                return(new IMBotMessage("No search results found, use search command.", IMBotMessage.ErrorColor));
            }

            string[] titles = (string[])conversation.Session[SessionKey.FoundTitles];

            if (resultNumber < 1 ||
                resultNumber > titles.Length)
            {
                return(new IMBotMessage("Bad search result number.", IMBotMessage.ErrorColor));
            }

            using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent())
            {
                Dictionary <Guid, UpcomingGuideProgram> upcomingRecordingsById = BuildUpcomingDictionary(
                    tvSchedulerAgent.GetUpcomingGuidePrograms(ScheduleType.Recording, true));
                Dictionary <Guid, UpcomingGuideProgram> upcomingAlertsById = BuildUpcomingDictionary(
                    tvSchedulerAgent.GetUpcomingGuidePrograms(ScheduleType.Alert, false));
                Dictionary <Guid, UpcomingGuideProgram> upcomingSuggestionsById = BuildUpcomingDictionary(
                    tvSchedulerAgent.GetUpcomingGuidePrograms(ScheduleType.Suggestion, false));

                ChannelProgram[] programs = tvSchedulerAgent.SearchGuideByTitle(GetChannelType(conversation), titles[resultNumber - 1], false);

                StringBuilder replyText = new StringBuilder();
                int           index     = 0;
                foreach (ChannelProgram program in programs)
                {
                    if (replyText.Length > 0)
                    {
                        replyText.AppendLine();
                    }
                    replyText.AppendFormat("{0,3}» ", ++index);
                    string appendText = AppendProgramIndicatorsPrefix(replyText, program.GetUniqueUpcomingProgramId(),
                                                                      upcomingRecordingsById, upcomingAlertsById, upcomingSuggestionsById);
                    Utility.AppendProgramDetails(replyText, program.Channel, program);
                    replyText.Append(appendText);
                }

                conversation.Session[SessionKey.Programs] = new Session.Programs(programs);

                return(new IMBotMessage(replyText.ToString(), true)
                {
                    Footer = "Use 'record', 'cancel', 'uncancel' or 'delete schedule' with <number>."
                });
            }
        }
Ejemplo n.º 2
0
        private IMBotMessage DoSearchResults(IMBotConversation conversation, int resultNumber)
        {
            if (!conversation.Session.ContainsKey(SessionKey.FoundTitles))
            {
                return new IMBotMessage("No search results found, use search command.", IMBotMessage.ErrorColor);
            }

            string[] titles = (string[])conversation.Session[SessionKey.FoundTitles];

            if (resultNumber < 1
                || resultNumber > titles.Length)
            {
                return new IMBotMessage("Bad search result number.", IMBotMessage.ErrorColor);
            }

            using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent())
            {
                Dictionary<Guid, UpcomingGuideProgram> upcomingRecordingsById = BuildUpcomingDictionary(
                    tvSchedulerAgent.GetUpcomingGuidePrograms(ScheduleType.Recording, true));
                Dictionary<Guid, UpcomingGuideProgram> upcomingAlertsById = BuildUpcomingDictionary(
                    tvSchedulerAgent.GetUpcomingGuidePrograms(ScheduleType.Alert, false));
                Dictionary<Guid, UpcomingGuideProgram> upcomingSuggestionsById = BuildUpcomingDictionary(
                    tvSchedulerAgent.GetUpcomingGuidePrograms(ScheduleType.Suggestion, false));

                ChannelProgram[] programs = tvSchedulerAgent.SearchGuideByTitle(GetChannelType(conversation), titles[resultNumber - 1], false);

                StringBuilder replyText = new StringBuilder();
                int index = 0;
                foreach (ChannelProgram program in programs)
                {
                    if (replyText.Length > 0)
                    {
                        replyText.AppendLine();
                    }
                    replyText.AppendFormat("{0,3}» ", ++index);
                    string appendText = AppendProgramIndicatorsPrefix(replyText, program.GetUniqueUpcomingProgramId(),
                        upcomingRecordingsById, upcomingAlertsById, upcomingSuggestionsById);
                    Utility.AppendProgramDetails(replyText, program.Channel, program);
                    replyText.Append(appendText);
                }

                conversation.Session[SessionKey.Programs] = new Session.Programs(programs);

                return new IMBotMessage(replyText.ToString(), true)
                {
                    Footer = "Use 'record', 'cancel', 'uncancel' or 'delete schedule' with <number>."
                };
            }
        }