Beispiel #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>."
                });
            }
        }
Beispiel #2
0
        private IMBotMessage DoShowGuideCommand(IMBotConversation conversation, IList<string> arguments)
        {
            if (arguments.Count == 0)
            {
                return new IMBotMessage("Channel name or number missing.", IMBotMessage.ErrorColor);
            }

            using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent())
            using (GuideServiceAgent tvGuideAgent = new GuideServiceAgent())
            {
                Channel selectedChannel = null;
                ChannelType channelType = GetChannelType(conversation);

                int lcn;
                if (int.TryParse(arguments[0], out lcn))
                {
                    selectedChannel = tvSchedulerAgent.GetChannelByLogicalChannelNumber(channelType, lcn);
                    if (selectedChannel == null)
                    {
                        return new IMBotMessage("Unknown channel number.", IMBotMessage.ErrorColor);
                    }
                }
                else
                {
                    selectedChannel = tvSchedulerAgent.GetChannelByDisplayName(channelType, arguments[0]);
                    if (selectedChannel == null)
                    {
                        return new IMBotMessage("Unknown channel name.", IMBotMessage.ErrorColor);
                    }
                }

                if (selectedChannel.GuideChannelId.HasValue)
                {
                    DateTime lowerTime = DateTime.Today;
                    if (arguments.Count > 1)
                    {
                        int dayNumber;
                        if (!int.TryParse(arguments[1], out dayNumber))
                        {
                            return new IMBotMessage("Bad day number, use 0 for today, 1 for tomorrow, etc...", IMBotMessage.ErrorColor);
                        }
                        lowerTime = lowerTime.AddDays(dayNumber);
                    }

                    DateTime upperTime = lowerTime.AddDays(1);
                    if (lowerTime.Date == DateTime.Today)
                    {
                        lowerTime = DateTime.Now;
                    }

                    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));

                    GuideProgramSummary[] programs = tvGuideAgent.GetChannelProgramsBetween(selectedChannel.GuideChannelId.Value, lowerTime, upperTime);
                    if (programs.Length == 0)
                    {
                        return new IMBotMessage(String.Format(CultureInfo.CurrentCulture, "No guide data for {0} on {1}.", selectedChannel.DisplayName, lowerTime.ToLongDateString()),
                            IMBotMessage.ErrorColor);
                    }
                    else
                    {
                        StringBuilder replyText = new StringBuilder();
                        replyText.AppendFormat("{0} on {1}:", lowerTime.ToLongDateString(), selectedChannel.DisplayName);
                        int index = 0;
                        foreach (GuideProgramSummary program in programs)
                        {
                            replyText.AppendLine();
                            replyText.AppendFormat("{0,3}» ", ++index);
                            string appendText = AppendProgramIndicatorsPrefix(replyText,
                                program.GetUniqueUpcomingProgramId(selectedChannel.ChannelId),
                                upcomingRecordingsById, upcomingAlertsById, upcomingSuggestionsById);
                            Utility.AppendProgramDetails(replyText, program);
                            replyText.Append(appendText);
                        }

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

                        return new IMBotMessage(replyText.ToString(), true)
                        {
                            Footer = "Use 'record', 'cancel', 'uncancel' or 'delete schedule' with <number>."
                        };
                    }
                }
                else
                {
                    return new IMBotMessage("Channel has no guide data.", IMBotMessage.ErrorColor);
                }
            }
        }
Beispiel #3
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>."
                };
            }
        }
Beispiel #4
0
        private IMBotMessage DoShowGuideCommand(IMBotConversation conversation, IList <string> arguments)
        {
            if (arguments.Count == 0)
            {
                return(new IMBotMessage("Channel name or number missing.", IMBotMessage.ErrorColor));
            }

            using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent())
                using (GuideServiceAgent tvGuideAgent = new GuideServiceAgent())
                {
                    Channel     selectedChannel = null;
                    ChannelType channelType     = GetChannelType(conversation);

                    int lcn;
                    if (int.TryParse(arguments[0], out lcn))
                    {
                        selectedChannel = tvSchedulerAgent.GetChannelByLogicalChannelNumber(channelType, lcn);
                        if (selectedChannel == null)
                        {
                            return(new IMBotMessage("Unknown channel number.", IMBotMessage.ErrorColor));
                        }
                    }
                    else
                    {
                        selectedChannel = tvSchedulerAgent.GetChannelByDisplayName(channelType, arguments[0]);
                        if (selectedChannel == null)
                        {
                            return(new IMBotMessage("Unknown channel name.", IMBotMessage.ErrorColor));
                        }
                    }

                    if (selectedChannel.GuideChannelId.HasValue)
                    {
                        DateTime lowerTime = DateTime.Today;
                        if (arguments.Count > 1)
                        {
                            int dayNumber;
                            if (!int.TryParse(arguments[1], out dayNumber))
                            {
                                return(new IMBotMessage("Bad day number, use 0 for today, 1 for tomorrow, etc...", IMBotMessage.ErrorColor));
                            }
                            lowerTime = lowerTime.AddDays(dayNumber);
                        }

                        DateTime upperTime = lowerTime.AddDays(1);
                        if (lowerTime.Date == DateTime.Today)
                        {
                            lowerTime = DateTime.Now;
                        }

                        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));

                        GuideProgramSummary[] programs = tvGuideAgent.GetChannelProgramsBetween(selectedChannel.GuideChannelId.Value, lowerTime, upperTime);
                        if (programs.Length == 0)
                        {
                            return(new IMBotMessage(String.Format(CultureInfo.CurrentCulture, "No guide data for {0} on {1}.", selectedChannel.DisplayName, lowerTime.ToLongDateString()),
                                                    IMBotMessage.ErrorColor));
                        }
                        else
                        {
                            StringBuilder replyText = new StringBuilder();
                            replyText.AppendFormat("{0} on {1}:", lowerTime.ToLongDateString(), selectedChannel.DisplayName);
                            int index = 0;
                            foreach (GuideProgramSummary program in programs)
                            {
                                replyText.AppendLine();
                                replyText.AppendFormat("{0,3}» ", ++index);
                                string appendText = AppendProgramIndicatorsPrefix(replyText,
                                                                                  program.GetUniqueUpcomingProgramId(selectedChannel.ChannelId),
                                                                                  upcomingRecordingsById, upcomingAlertsById, upcomingSuggestionsById);
                                Utility.AppendProgramDetails(replyText, program);
                                replyText.Append(appendText);
                            }

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

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