示例#1
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);
                }
            }
        }
示例#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));
                    }
                }
        }