Esempio n. 1
0
        private static IMBotMessage FindUpcomingRecording(SchedulerServiceAgent tvSchedulerAgent, 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));
            }

            UpcomingProgram[] upcomingPrograms = tvSchedulerAgent.GetAllUpcomingPrograms(ScheduleType.Recording, true);
            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));
        }
Esempio n. 2
0
        private void HandleAlerts()
        {
            UpcomingProgram[] upcomingAlerts;
            AddressList       alertContactFilter;

            lock (_alertsLock)
            {
                if (_upcomingAlerts == null)
                {
                    using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent())
                    {
                        _upcomingAlerts = tvSchedulerAgent.GetAllUpcomingPrograms(ScheduleType.Alert, false);
                    }
                }
                EnsureAlertContactFilter();
                upcomingAlerts     = _upcomingAlerts;
                alertContactFilter = _alertContactFilter;
            }

            bool sentAlert = false;

            foreach (UpcomingProgram upcomingAlert in upcomingAlerts)
            {
                if (upcomingAlert.StopTime > DateTime.Now &&
                    upcomingAlert.StartTime.AddMinutes(-_alertMinutes) <= DateTime.Now)
                {
                    if (!IsRecentlyAlerted(upcomingAlert))
                    {
                        if (sentAlert)
                        {
                            // We just sent out an alert, seems this is needed to give the system
                            // some extra time :-(
                            Thread.Sleep(100);
                        }
                        if (BroadcastAlert(alertContactFilter, upcomingAlert))
                        {
                            _recentlyAlerted.Add(upcomingAlert);
                            sentAlert = true;
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        private void ProcessAlerts(DateTime preNotifySecs)
        {
            using (SchedulerServiceAgent tvschedulerAgent = new SchedulerServiceAgent())
            {
                List <UpcomingProgram> upcomingPrograms = new List <UpcomingProgram>(
                    tvschedulerAgent.GetAllUpcomingPrograms(ScheduleType.Alert, false));
                if (upcomingPrograms.Count > 0)
                {
                    DateTime _now = DateTime.Now;
                    foreach (UpcomingProgram program in upcomingPrograms)
                    {
                        if (preNotifySecs > program.StartTime && _now < program.StopTime &&
                            !AlreadyNotifiedAlerts.Contains(program.ScheduleId))
                        {
                            NotifyProgram(program);
                            AlreadyNotifiedAlerts.Add(program.ScheduleId);
                            Log.Debug("NotifyManager: AlreadyNotifiedAlerts.Add {0}", program.Title);
                        }
                        else if (_now >= program.StopTime &&
                                 AlreadyNotifiedConflict.Contains(program.ScheduleId))
                        {
                            Log.Debug("NotifyManager: AlreadyNotifiedAlerts.Remove");
                            AlreadyNotifiedAlerts.Remove(program.ScheduleId);
                        }

                        if (program.StartTime < _nextCheckTimeAlerts && program.StartTime > _now)
                        {
                            _nextCheckTimeAlerts = program.StartTime;
                        }

                        if (program.StopTime < _nextCheckTimeAlerts && program.StopTime > _now)
                        {
                            _nextCheckTimeAlerts = program.StopTime;
                        }
                    }
                }
            }
        }
        private void ProcessAlerts(DateTime preNotifySecs)
        {
            using (SchedulerServiceAgent tvschedulerAgent = new SchedulerServiceAgent())
            {
                List<UpcomingProgram> upcomingPrograms = new List<UpcomingProgram>(
                    tvschedulerAgent.GetAllUpcomingPrograms(ScheduleType.Alert, false));
                if (upcomingPrograms.Count > 0)
                {
                    DateTime _now = DateTime.Now;
                    foreach (UpcomingProgram program in upcomingPrograms)
                    {
                        if (preNotifySecs > program.StartTime && _now < program.StopTime
                            && !AlreadyNotifiedAlerts.Contains(program.ScheduleId))
                        {
                            NotifyProgram(program);
                            AlreadyNotifiedAlerts.Add(program.ScheduleId);
                            Log.Debug("NotifyManager: AlreadyNotifiedAlerts.Add {0}", program.Title);
                        }
                        else if (_now >= program.StopTime
                            && AlreadyNotifiedConflict.Contains(program.ScheduleId))
                        {
                            Log.Debug("NotifyManager: AlreadyNotifiedAlerts.Remove");
                            AlreadyNotifiedAlerts.Remove(program.ScheduleId);
                        }

                        if (program.StartTime < _nextCheckTimeAlerts && program.StartTime > _now)
                        {
                            _nextCheckTimeAlerts = program.StartTime;
                        }

                        if (program.StopTime < _nextCheckTimeAlerts && program.StopTime > _now)
                        {
                            _nextCheckTimeAlerts = program.StopTime;
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        private IMBotMessage DoShowUpcomingCommand(IMBotConversation conversation, ScheduleType type)
        {
            if (type == ScheduleType.Recording)
            {
                using (ControlServiceAgent tvControlAgent = new ControlServiceAgent())
                {
                    UpcomingRecording[] upcomingRecordings = tvControlAgent.GetAllUpcomingRecordings(UpcomingRecordingsFilter.Recordings, false);

                    StringBuilder replyText = new StringBuilder();

                    if (upcomingRecordings.Length > 0)
                    {
                        int index = 0;
                        foreach (UpcomingRecording upcomingRecording in upcomingRecordings)
                        {
                            if (replyText.Length > 0)
                            {
                                replyText.AppendLine();
                            }

                            PluginService pluginService = null;
                            if (upcomingRecording.CardChannelAllocation != null)
                            {
                                pluginService =
                                    RecorderTunersCache.GetRecorderTunerById(upcomingRecording.CardChannelAllocation.RecorderTunerId);
                            }

                            replyText.AppendFormat("{0,3}» ", ++index);
                            Utility.AppendProgramDetails(replyText, upcomingRecording.Program.Channel, upcomingRecording.Program);
                            replyText.AppendFormat(" [{0}]", pluginService == null ? "-" : pluginService.Name);
                        }

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

                        return new IMBotMessage(replyText.ToString(), true)
                        {
                            Footer = "Use 'cancel', 'uncancel' or 'delete schedule' with <number>."
                        };
                    }
                }
            }
            else
            {
                using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent())
                {
                    UpcomingProgram[] upcomingPrograms = tvSchedulerAgent.GetAllUpcomingPrograms(type, false);

                    StringBuilder replyText = new StringBuilder();

                    if (upcomingPrograms.Length > 0)
                    {
                        int index = 0;
                        foreach (UpcomingProgram upcomingProgram in upcomingPrograms)
                        {
                            if (replyText.Length > 0)
                            {
                                replyText.AppendLine();
                            }
                            replyText.AppendFormat("{0,3}» ", ++index);
                            Utility.AppendProgramDetails(replyText, upcomingProgram.Channel, upcomingProgram);
                        }

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

                        return new IMBotMessage(replyText.ToString(), true)
                        {
                            Footer = "Use 'record', 'cancel', 'uncancel' or 'delete schedule' with <number>."
                        };
                    }
                }
            }
            return new IMBotMessage("There are no upcoming " + type.ToString().ToLowerInvariant() + "s.");
        }
Esempio n. 6
0
        private static IMBotMessage FindUpcomingRecording(SchedulerServiceAgent tvSchedulerAgent, 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);
            }

            UpcomingProgram[] upcomingPrograms = tvSchedulerAgent.GetAllUpcomingPrograms(ScheduleType.Recording, true);
            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);
        }
Esempio n. 7
0
        private void HandleAlerts()
        {
            UpcomingProgram[] upcomingAlerts;
            AddressList alertContactFilter;
            lock (_alertsLock)
            {
                if (_upcomingAlerts == null)
                {
                    using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent())
                    {
                        _upcomingAlerts = tvSchedulerAgent.GetAllUpcomingPrograms(ScheduleType.Alert, false);
                    }
                }
                EnsureAlertContactFilter();
                upcomingAlerts = _upcomingAlerts;
                alertContactFilter = _alertContactFilter;
            }

            bool sentAlert = false;
            foreach (UpcomingProgram upcomingAlert in upcomingAlerts)
            {
                if (upcomingAlert.StopTime > DateTime.Now
                    && upcomingAlert.StartTime.AddMinutes(-_alertMinutes) <= DateTime.Now)
                {
                    if (!IsRecentlyAlerted(upcomingAlert))
                    {
                        if (sentAlert)
                        {
                            // We just sent out an alert, seems this is needed to give the system
                            // some extra time :-(
                            Thread.Sleep(100);
                        }
                        if (BroadcastAlert(alertContactFilter, upcomingAlert))
                        {
                            _recentlyAlerted.Add(upcomingAlert);
                            sentAlert = true;
                        }
                    }
                }
            }
        }
        internal static bool HasUpcomingProgram(Guid channelId, GuideProgram program, out UpcomingProgram upcomingProgram, ScheduleType scheduleType)
        {
            using (SchedulerServiceAgent SchedulerAgent = new SchedulerServiceAgent())
            {
                upcomingProgram = null;
                Guid upcomingProgramId = program.GetUniqueUpcomingProgramId(channelId);

                List<UpcomingProgram> upcomingPrograms = new List<UpcomingProgram>(
                    SchedulerAgent.GetAllUpcomingPrograms(scheduleType, true));
                foreach (UpcomingProgram upcoming in upcomingPrograms)
                {
                    if (upcoming.UpcomingProgramId == upcomingProgramId)
                    {
                        upcomingProgram = upcoming;
                        return true;
                    }
                }
                return false;
            }
        }
Esempio n. 9
0
        private IMBotMessage DoShowUpcomingCommand(IMBotConversation conversation, ScheduleType type)
        {
            if (type == ScheduleType.Recording)
            {
                using (ControlServiceAgent tvControlAgent = new ControlServiceAgent())
                {
                    UpcomingRecording[] upcomingRecordings = tvControlAgent.GetAllUpcomingRecordings(UpcomingRecordingsFilter.Recordings, false);

                    StringBuilder replyText = new StringBuilder();

                    if (upcomingRecordings.Length > 0)
                    {
                        int index = 0;
                        foreach (UpcomingRecording upcomingRecording in upcomingRecordings)
                        {
                            if (replyText.Length > 0)
                            {
                                replyText.AppendLine();
                            }

                            PluginService pluginService = null;
                            if (upcomingRecording.CardChannelAllocation != null)
                            {
                                pluginService =
                                    RecorderTunersCache.GetRecorderTunerById(upcomingRecording.CardChannelAllocation.RecorderTunerId);
                            }

                            replyText.AppendFormat("{0,3}» ", ++index);
                            Utility.AppendProgramDetails(replyText, upcomingRecording.Program.Channel, upcomingRecording.Program);
                            replyText.AppendFormat(" [{0}]", pluginService == null ? "-" : pluginService.Name);
                        }

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

                        return(new IMBotMessage(replyText.ToString(), true)
                        {
                            Footer = "Use 'cancel', 'uncancel' or 'delete schedule' with <number>."
                        });
                    }
                }
            }
            else
            {
                using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent())
                {
                    UpcomingProgram[] upcomingPrograms = tvSchedulerAgent.GetAllUpcomingPrograms(type, false);

                    StringBuilder replyText = new StringBuilder();

                    if (upcomingPrograms.Length > 0)
                    {
                        int index = 0;
                        foreach (UpcomingProgram upcomingProgram in upcomingPrograms)
                        {
                            if (replyText.Length > 0)
                            {
                                replyText.AppendLine();
                            }
                            replyText.AppendFormat("{0,3}» ", ++index);
                            Utility.AppendProgramDetails(replyText, upcomingProgram.Channel, upcomingProgram);
                        }

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

                        return(new IMBotMessage(replyText.ToString(), true)
                        {
                            Footer = "Use 'record', 'cancel', 'uncancel' or 'delete schedule' with <number>."
                        });
                    }
                }
            }
            return(new IMBotMessage("There are no upcoming " + type.ToString().ToLowerInvariant() + "s."));
        }