private Schedule CreateManualSchedule(Channel channel, int durationMinutes, out string notifyText)
 {
     using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent())
     {
         Schedule schedule = tvSchedulerAgent.CreateNewSchedule(ChannelType.Television, ScheduleType.Recording);
         DateTime startTime = DateTime.Now;
         TimeSpan duration = new TimeSpan(0, durationMinutes, 0);
         schedule.Rules.Add(ScheduleRuleType.Channels, channel.ChannelId);
         schedule.Rules.Add(ScheduleRuleType.ManualSchedule, startTime, new ScheduleTime(duration));
         schedule.Name = String.Format(CultureInfo.CurrentCulture, "{0} {1:g}-{2:t}", channel.DisplayName, startTime, startTime.Add(duration));
         notifyText = schedule.Name;
         return schedule;
     }
 }
Exemple #2
0
        private IMBotMessage DoRecordCommand(IMBotConversation conversation, IList<string> arguments)
        {
            if (arguments.Count == 0)
            {
                return new IMBotMessage("Program number missing.", IMBotMessage.ErrorColor);
            }

            using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent())
            {
                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 = tvSchedulerAgent.CreateNewSchedule(GetChannelType(conversation), ScheduleType.Recording);

                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);
                tvSchedulerAgent.SaveSchedule(schedule);

                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());
            }
        }
Exemple #3
0
        private IMBotMessage DoRecordCommand(IMBotConversation conversation, IList <string> arguments)
        {
            if (arguments.Count == 0)
            {
                return(new IMBotMessage("Program number missing.", IMBotMessage.ErrorColor));
            }

            using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent())
            {
                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 = tvSchedulerAgent.CreateNewSchedule(GetChannelType(conversation), ScheduleType.Recording);

                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);
                tvSchedulerAgent.SaveSchedule(schedule);

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