Exemple #1
0
        private static IMBotMessage FindUpcomingRecording(IMBotConversation conversation, IList <string> arguments, out UpcomingProgram upcomingRecording)
        {
            upcomingRecording = null;

            IProgramSummary program           = null;
            Channel         channel           = null;
            Guid?           upcomingProgramId = null;

            int programNumber;

            if (!int.TryParse(arguments[0], out programNumber))
            {
                return(new IMBotMessage("Bad program number.", IMBotMessage.ErrorColor));
            }

            Session.Programs sessionPrograms = null;
            if (conversation.Session.ContainsKey(SessionKey.Programs))
            {
                sessionPrograms = conversation.Session[SessionKey.Programs] as Session.Programs;
            }
            if (sessionPrograms != null)
            {
                program = sessionPrograms.GetProgramAt(programNumber, out channel, out upcomingProgramId);
                if (program == null)
                {
                    return(new IMBotMessage("Bad program number.", IMBotMessage.ErrorColor));
                }
            }
            else
            {
                return(new IMBotMessage("No programs.", IMBotMessage.ErrorColor));
            }

            var upcomingPrograms = Proxies.SchedulerService.GetAllUpcomingPrograms(ScheduleType.Recording, true).Result;

            foreach (UpcomingProgram upcomingProgram in upcomingPrograms)
            {
                bool idMatches = upcomingProgramId.HasValue &&
                                 upcomingProgram.UpcomingProgramId == upcomingProgramId.Value;
                if ((idMatches || upcomingProgram.Title == program.Title) &&
                    upcomingProgram.Channel.ChannelId == channel.ChannelId &&
                    upcomingProgram.StartTime == program.StartTime)
                {
                    upcomingRecording = upcomingProgram;
                    return(null);
                }
            }

            return(new IMBotMessage("Program not found in upcoming recordings.", IMBotMessage.ErrorColor));
        }
Exemple #2
0
        private IMBotMessage DoRecordCommand(IMBotConversation conversation, IList <string> arguments)
        {
            if (arguments.Count == 0)
            {
                return(new IMBotMessage("Program number missing.", IMBotMessage.ErrorColor));
            }

            RepeatingType repeatingType = RepeatingType.None;

            if (arguments.Count > 1)
            {
                switch (arguments[1].ToLowerInvariant())
                {
                case "once":
                case "o": repeatingType = RepeatingType.Once; break;

                case "daily":
                case "d": repeatingType = RepeatingType.Daily; break;

                case "weekly":
                case "w": repeatingType = RepeatingType.Weekly; break;

                case "workingdays":
                case "wd": repeatingType = RepeatingType.WorkingDays; break;

                case "weekends":
                case "we": repeatingType = RepeatingType.Weekends; break;

                case "anytime":
                case "a": repeatingType = RepeatingType.AnyTime; break;
                }
            }

            int programNumber;

            if (repeatingType == RepeatingType.None ||
                !int.TryParse(arguments[0], out programNumber))
            {
                return(new IMBotMessage("Please specify program number and once, daily, weekly, workingdays, weekends or anytime.", IMBotMessage.ErrorColor));
            }

            Session.Programs sessionPrograms = null;
            if (conversation.Session.ContainsKey(SessionKey.Programs))
            {
                sessionPrograms = conversation.Session[SessionKey.Programs] as Session.Programs;
            }

            IProgramSummary program = null;
            Channel         channel = null;

            if (sessionPrograms != null)
            {
                program = sessionPrograms.GetProgramAt(programNumber, out channel);
                if (program == null)
                {
                    return(new IMBotMessage("Bad program number.", IMBotMessage.ErrorColor));
                }
            }
            else
            {
                return(new IMBotMessage("No programs.", IMBotMessage.ErrorColor));
            }

            Schedule schedule = Proxies.SchedulerService.CreateNewSchedule(GetChannelType(conversation), ScheduleType.Recording).Result;

            bool   newEpisodesOnly = arguments.Count > 2 && arguments[2].Equals("new", StringComparison.CurrentCultureIgnoreCase);
            string repeatingText   = String.Empty;

            if (repeatingType == RepeatingType.Once)
            {
                schedule.Name = GuideProgram.CreateProgramTitle(program.Title, program.SubTitle, program.EpisodeNumberDisplay);
                schedule.Rules.Add(ScheduleRuleType.OnDate, program.StartTime.Date);
                schedule.Rules.Add(ScheduleRuleType.AroundTime, new ScheduleTime(program.StartTime.TimeOfDay));
                if (!String.IsNullOrEmpty(program.SubTitle))
                {
                    schedule.Rules.Add(ScheduleRuleType.SubTitleEquals, program.SubTitle);
                }
                else if (!String.IsNullOrEmpty(program.EpisodeNumberDisplay))
                {
                    schedule.Rules.Add(ScheduleRuleType.EpisodeNumberEquals, program.EpisodeNumberDisplay);
                }
                newEpisodesOnly = false;
            }
            else if (repeatingType == RepeatingType.AnyTime)
            {
                schedule.Name = program.Title + " (Any Time)";
                repeatingText = " any time";
            }
            else if (repeatingType == RepeatingType.Weekly)
            {
                schedule.Name = program.Title + " (Weekly)";
                schedule.Rules.Add(ScheduleRuleType.DaysOfWeek, GetDaysOfWeek(program.StartTime));
                schedule.Rules.Add(ScheduleRuleType.AroundTime, new ScheduleTime(program.StartTime.TimeOfDay));
                repeatingText = " weekly";
            }
            else if (repeatingType == RepeatingType.WorkingDays)
            {
                schedule.Name = program.Title + " (Mon-Fri)";
                schedule.Rules.Add(ScheduleRuleType.DaysOfWeek, ScheduleDaysOfWeek.WorkingDays);
                schedule.Rules.Add(ScheduleRuleType.AroundTime, new ScheduleTime(program.StartTime.TimeOfDay));
                repeatingText = " Mon-Fri";
            }
            else if (repeatingType == RepeatingType.Weekends)
            {
                schedule.Name = program.Title + " (Sat-Sun)";
                schedule.Rules.Add(ScheduleRuleType.DaysOfWeek, ScheduleDaysOfWeek.Weekends);
                schedule.Rules.Add(ScheduleRuleType.AroundTime, new ScheduleTime(program.StartTime.TimeOfDay));
                repeatingText = " Sat-Sun";
            }
            else if (repeatingType == RepeatingType.Weekly)
            {
                schedule.Name = program.Title + " (Weekly)";
                schedule.Rules.Add(ScheduleRuleType.DaysOfWeek, GetDaysOfWeek(program.StartTime));
                schedule.Rules.Add(ScheduleRuleType.AroundTime, new ScheduleTime(program.StartTime.TimeOfDay));
                repeatingText = " weekly";
            }
            else
            {
                schedule.Name = program.Title + " (Daily)";
                schedule.Rules.Add(ScheduleRuleType.AroundTime, new ScheduleTime(program.StartTime.TimeOfDay));
                repeatingText = " daily";
            }
            if (newEpisodesOnly)
            {
                schedule.Rules.Add(ScheduleRuleType.NewEpisodesOnly, true);
            }
            schedule.Rules.Add(ScheduleRuleType.Channels, channel.ChannelId);
            schedule.Rules.Add(ScheduleRuleType.TitleEquals, program.Title);
            Proxies.SchedulerService.SaveSchedule(schedule).Wait();

            StringBuilder replyText = new StringBuilder();

            replyText.Append("Created schedule to record ");
            Utility.AppendProgramDetails(replyText, channel, program);
            replyText.Append(repeatingText);
            if (newEpisodesOnly)
            {
                replyText.Append(" (record episodes once)");
            }
            replyText.Append(".");

            return(new IMBotMessage(replyText.ToString()));
        }