예제 #1
0
 private PluginService InternalGetRecorderTunerById(Guid recorderTunerId)
 {
     lock (_pluginServices)
     {
         if (!_pluginServices.ContainsKey(recorderTunerId))
         {
             try
             {
                 using (ControlServiceAgent tvControlAgent = new ControlServiceAgent())
                 {
                     _pluginServices.Clear();
                     PluginService[] pluginServices = tvControlAgent.GetAllPluginServices(false);
                     foreach (PluginService pluginService in pluginServices)
                     {
                         _pluginServices.Add(pluginService.PluginServiceId, pluginService);
                     }
                 }
             }
             catch { }
         }
         if (_pluginServices.ContainsKey(recorderTunerId))
         {
             return(_pluginServices[recorderTunerId]);
         }
         return(null);
     }
 }
예제 #2
0
 private PluginService InternalGetRecorderTunerById(Guid recorderTunerId)
 {
     lock (_pluginServices)
     {
         if (!_pluginServices.ContainsKey(recorderTunerId))
         {
             try
             {
                 using (ControlServiceAgent tvControlAgent = new ControlServiceAgent())
                 {
                     _pluginServices.Clear();
                     PluginService[] pluginServices = tvControlAgent.GetAllPluginServices(false);
                     foreach (PluginService pluginService in pluginServices)
                     {
                         _pluginServices.Add(pluginService.PluginServiceId, pluginService);
                     }
                 }
             }
             catch { }
         }
         if (_pluginServices.ContainsKey(recorderTunerId))
         {
             return _pluginServices[recorderTunerId];
         }
         return null;
     }
 }
예제 #3
0
 public void StartGrabbingTeletext()
 {
     if (_liveStream != null)
     {
         using (ControlServiceAgent tvControlAgent = new ControlServiceAgent())
         {
             tvControlAgent.StartGrabbingTeletext(_liveStream);
         }
     }
 }
예제 #4
0
 private void _refreshStatusBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
 {
     if (this.IsConnected)
     {
         using (ControlServiceAgent tvControlAgent = new ControlServiceAgent())
         {
             RefreshStatusResult result = new RefreshStatusResult();
             result.ActiveRecordings  = tvControlAgent.GetActiveRecordings();
             result.LiveStreams       = tvControlAgent.GetLiveStreams();
             result.UpcomingRecording = tvControlAgent.GetNextUpcomingRecording(false);
             e.Result = result;
         }
     }
 }
예제 #5
0
        public bool Scrobble(string filename)
        {
            StopScrobble();

            if (!g_Player.IsTVRecording)
            {
                return(false);
            }

            // get recording details from tv database
            ControlServiceAgent layer     = new ControlServiceAgent();
            Recording           recording = layer.GetRecordingByFileName(filename);

            if (recording == null || string.IsNullOrEmpty(recording.Title))
            {
                TraktLogger.Info("Unable to get recording details from argus database.");
                return(false);
            }

            // get year from title if available, some EPG entries contain this
            string title = null;
            string year  = null;

            BasicHandler.GetTitleAndYear(recording.Title, out title, out year);

            CurrentRecording = new VideoInfo
            {
                Type         = recording.EpisodeNumber != null || recording.SeriesNumber != null ? VideoType.Series : VideoType.Movie,
                Title        = title,
                Year         = year,
                SeasonIdx    = recording.SeriesNumber == null ? null : recording.SeriesNumber.ToString(),
                EpisodeIdx   = recording.EpisodeNumber == null ? null : recording.EpisodeNumber.ToString(),
                IsScrobbling = true
            };

            TraktLogger.Info("Current program details. Title='{0}', Year='{1}', Season='{2}', Episode='{3}', StartTime='{4}', Runtime='{5}'", CurrentRecording.Title, CurrentRecording.Year.ToLogString(), CurrentRecording.SeasonIdx.ToLogString(), CurrentRecording.EpisodeIdx.ToLogString(), CurrentRecording.StartTime == null ? "<empty>" : CurrentRecording.StartTime.ToString(), CurrentRecording.Runtime);

            if (CurrentRecording.Type == VideoType.Series)
            {
                TraktLogger.Info("Detected tv show playing in Argus TV Recordings. Title = '{0}'", CurrentRecording.ToString());
            }
            else
            {
                TraktLogger.Info("Detected movie playing in Argus TV Recordings. Title = '{0}'", CurrentRecording.ToString());
            }

            BasicHandler.StartScrobble(CurrentRecording);

            return(true);
        }
        public bool Scrobble(string filename)
        {
            StopScrobble();

            if (!g_Player.IsTVRecording) return false;

            // get recording details from tv database
            ControlServiceAgent layer = new ControlServiceAgent();
            Recording recording = layer.GetRecordingByFileName(filename);
            if (recording == null || string.IsNullOrEmpty(recording.Title))
            {
                TraktLogger.Info("Unable to get recording details from argus database.");
                return false;
            }

            // get year from title if available, some EPG entries contain this
            string title = null;
            string year = null;
            BasicHandler.GetTitleAndYear(recording.Title, out title, out year);

            CurrentRecording = new VideoInfo
            {
                Type = recording.EpisodeNumber != null || recording.SeriesNumber != null ? VideoType.Series : VideoType.Movie,
                Title = title,
                Year = year,
                SeasonIdx = recording.SeriesNumber == null ? null : recording.SeriesNumber.ToString(),
                EpisodeIdx = recording.EpisodeNumber == null ? null : recording.EpisodeNumber.ToString(),
                IsScrobbling = true
            };

            TraktLogger.Info("Current program details. Title='{0}', Year='{1}', Season='{2}', Episode='{3}', StartTime='{4}', Runtime='{5}'", CurrentRecording.Title, CurrentRecording.Year.ToLogString(), CurrentRecording.SeasonIdx.ToLogString(), CurrentRecording.EpisodeIdx.ToLogString(), CurrentRecording.StartTime == null ? "<empty>" : CurrentRecording.StartTime.ToString(), CurrentRecording.Runtime);

            if (CurrentRecording.Type == VideoType.Series)
            {
                TraktLogger.Info("Detected tv show playing in Argus TV Recordings. Title = '{0}'", CurrentRecording.ToString());
            }
            else
            {
                TraktLogger.Info("Detected movie playing in Argus TV Recordings. Title = '{0}'", CurrentRecording.ToString());
            }

            BasicHandler.StartScrobble(CurrentRecording);

            return true;
        }
예제 #7
0
 private void RefreshBotPersonalMessage()
 {
     if (_messenger.Owner != null)
     {
         string         message = "Idle";
         PresenceStatus status  = PresenceStatus.Online;
         using (ControlServiceAgent tvControlAgent = new ControlServiceAgent())
         {
             ActiveRecording[] activeRecordings = tvControlAgent.GetActiveRecordings();
             if (activeRecordings.Length > 0)
             {
                 message = "Recording";
                 status  = PresenceStatus.Busy;
             }
             else
             {
                 LiveStream[] liveStreams = tvControlAgent.GetLiveStreams();
                 if (liveStreams.Length > 0)
                 {
                     message = "Streaming";
                     status  = PresenceStatus.Away;
                 }
                 else
                 {
                     UpcomingRecording upcomingRecording = tvControlAgent.GetNextUpcomingRecording(false);
                     if (upcomingRecording != null)
                     {
                         message = "Waiting for next scheduled recording";
                     }
                 }
             }
         }
         if (_messenger.Owner.PersonalMessage == null ||
             _messenger.Owner.PersonalMessage.Message != message)
         {
             _messenger.Owner.PersonalMessage = new PersonalMessage(message);
         }
         if (_messenger.Owner.Status != status)
         {
             _messenger.Owner.Status = status;
         }
     }
 }
예제 #8
0
        private void _refreshProgramsBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            RefreshProgramsResult result = null;

            //DateTime startTime = DateTime.Now;

            if (this.IsConnected)
            {
                using (ControlServiceAgent tvControlAgent = new ControlServiceAgent())
                {
                    result = new RefreshProgramsResult();

                    result.AllUpcomingRecordings = tvControlAgent.GetAllUpcomingRecordings(UpcomingRecordingsFilter.Recordings, true);
                    result.ActiveRecordings      = tvControlAgent.GetActiveRecordings();
                    result.LiveStreams           = tvControlAgent.GetLiveStreams();
                    result.UpcomingRecordings    = new UpcomingOrActiveProgramsList(result.AllUpcomingRecordings);
                    result.UpcomingRecordings.RemoveActiveRecordings(result.ActiveRecordings);
                }
            }

            //Utility.EnsureMinimumTime(startTime, 250);

            e.Result = result;
        }
예제 #9
0
        public bool Scrobble(string filename)
        {
            StopScrobble();

            if (!g_Player.IsTVRecording)
            {
                return(false);
            }

            // get recording details from tv database
            ControlServiceAgent layer     = new ControlServiceAgent();
            Recording           recording = layer.GetRecordingByFileName(filename);

            if (recording == null || string.IsNullOrEmpty(recording.Title))
            {
                TraktLogger.Info("Unable to get recording details from argus database.");
                return(false);
            }

            // get year from title if available, some EPG entries contain this
            string title = null;
            string year  = null;

            GetTitleAndYear(recording, out title, out year);

            CurrentRecording = new VideoInfo
            {
                Type         = recording.EpisodeNumber != null || recording.SeriesNumber != null ? VideoType.Series : VideoType.Movie,
                Title        = title,
                Year         = year,
                SeasonIdx    = recording.SeriesNumber == null ? null : recording.SeriesNumber.ToString(),
                EpisodeIdx   = recording.EpisodeNumber == null ? null : recording.EpisodeNumber.ToString(),
                IsScrobbling = true
            };

            if (CurrentRecording.Type == VideoType.Series)
            {
                TraktLogger.Info("Detected tv-series '{0}' playing in Argus TV-Recordings", CurrentRecording.ToString());
            }
            else
            {
                TraktLogger.Info("Detected movie '{0}' playing in Argus TV-Recordings", CurrentRecording.ToString());
            }

            #region scrobble timer
            TraktTimer = new Timer(new TimerCallback((stateInfo) =>
            {
                Thread.CurrentThread.Name = "Scrobble";

                VideoInfo videoInfo = stateInfo as VideoInfo;

                // maybe the program does not exist on trakt
                // ignore in future if it failed previously
                if (videoInfo.IsScrobbling)
                {
                    if (videoInfo.Type == VideoType.Series)
                    {
                        videoInfo.IsScrobbling = BasicHandler.ScrobbleEpisode(videoInfo, TraktScrobbleStates.watching);
                    }
                    else
                    {
                        videoInfo.IsScrobbling = BasicHandler.ScrobbleMovie(videoInfo, TraktScrobbleStates.watching);
                    }

                    if (videoInfo.Equals(CurrentRecording))
                    {
                        CurrentRecording.IsScrobbling = videoInfo.IsScrobbling;
                    }
                }
            }), CurrentRecording, 3000, 900000);
            #endregion

            return(true);
        }
예제 #10
0
 private void _refreshStatusBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
 {
     if (this.IsConnected)
     {
         using (ControlServiceAgent tvControlAgent = new ControlServiceAgent())
         {
             RefreshStatusResult result = new RefreshStatusResult();
             result.ActiveRecordings = tvControlAgent.GetActiveRecordings();
             result.LiveStreams = tvControlAgent.GetLiveStreams();
             result.UpcomingRecording = tvControlAgent.GetNextUpcomingRecording(false);
             e.Result = result;
         }
     }
 }
예제 #11
0
        private void _refreshProgramsBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            RefreshProgramsResult result = null;
            //DateTime startTime = DateTime.Now;

            if (this.IsConnected)
            {
                using (ControlServiceAgent tvControlAgent = new ControlServiceAgent())
                {
                    result = new RefreshProgramsResult();

                    result.AllUpcomingRecordings = tvControlAgent.GetAllUpcomingRecordings(UpcomingRecordingsFilter.Recordings, true);
                    result.ActiveRecordings = tvControlAgent.GetActiveRecordings();
                    result.LiveStreams = tvControlAgent.GetLiveStreams();
                    result.UpcomingRecordings = new UpcomingOrActiveProgramsList(result.AllUpcomingRecordings);
                    result.UpcomingRecordings.RemoveActiveRecordings(result.ActiveRecordings);
                }
            }

            //Utility.EnsureMinimumTime(startTime, 250);

            e.Result = result;
        }
예제 #12
0
 public void StartGrabbingTeletext()
 {
     if (_liveStream != null)
     {
         using (ControlServiceAgent tvControlAgent = new ControlServiceAgent())
         {
             tvControlAgent.StartGrabbingTeletext(_liveStream);
         }
     }
 }
예제 #13
0
        private void OnActiveRecordings(List<Guid> ignoreActiveRecordings)
        {
            using (ControlServiceAgent tvControlAgent = new ControlServiceAgent())
            {
                List<ActiveRecording> activeRecordings = new List<ActiveRecording>(
                    tvControlAgent.GetActiveRecordings());

                if (activeRecordings != null && activeRecordings.Count > 0)
                {
                    GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_MENU);
                    if (dlg == null)
                    {
                        return;
                    }

                    dlg.Reset();
                    dlg.SetHeading(200052); // Active Recordings

                    List<ActiveRecording> listedRecordings = new List<ActiveRecording>();
                    foreach (ActiveRecording activeRecording in activeRecordings)
                    {
                        if (!ignoreActiveRecordings.Contains(activeRecording.RecordingId))
                        {
                            GUIListItem item = new GUIListItem();
                            string channelName = activeRecording.Program.Channel.DisplayName;
                            string programTitle = activeRecording.Program.Title;
                            string time = String.Format("{0}-{1}",
                                activeRecording.Program.StartTime.ToString("t", CultureInfo.CurrentCulture.DateTimeFormat),
                                activeRecording.Program.StopTime.ToString("t", CultureInfo.CurrentCulture.DateTimeFormat));

                            item.Label = channelName;
                            item.Label2 = programTitle + "  " + time;

                            string strLogo = string.Empty;
                            using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent())
                            {
                                strLogo = Utility.GetLogoImage(activeRecording.Program.Channel, tvSchedulerAgent);
                            }

                            if (string.IsNullOrEmpty(strLogo))
                            {
                                strLogo = "defaultVideoBig.png";
                            }

                            item.IconImage = strLogo;
                            item.IconImageBig = strLogo;
                            dlg.Add(item);
                            listedRecordings.Add(activeRecording);
                        }
                    }

                    dlg.SelectedLabel = listedRecordings.Count - 1;

                    dlg.DoModal(this.GetID);
                    if (dlg.SelectedLabel < 0 || listedRecordings.Count == 0 || (dlg.SelectedLabel - 1 > listedRecordings.Count))
                    {
                        return;
                    }

                    ActiveRecording selectedRecording = listedRecordings[dlg.SelectedLabel];
                    listedRecordings = null;

                    bool deleted = OnAbortActiveRecording(selectedRecording);
                    if (deleted && !ignoreActiveRecordings.Contains(selectedRecording.RecordingId))
                    {
                        ignoreActiveRecordings.Add(selectedRecording.RecordingId);
                    }

                    if (deleted)
                    {
                        OnActiveRecordings(ignoreActiveRecordings); //keep on showing the list until --> 1) user leaves menu, 2) no more active recordings
                    }
                }
                else if (ignoreActiveRecordings == null || ignoreActiveRecordings.Count == 0)
                {
                    GUIDialogOK pDlgOK = (GUIDialogOK)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_OK);
                    if (pDlgOK != null)
                    {
                        pDlgOK.SetHeading(200052); //my tv
                        pDlgOK.SetLine(1, GUILocalizeStrings.Get(200053)); // No Active recordings
                        pDlgOK.SetLine(2, "");
                        pDlgOK.DoModal(this.GetID);
                    }
                }
            }
        }
예제 #14
0
        private bool OnSelectItem(bool isItemSelected)
        {
            if (_currentProgram == null)
            {
                if (DateTime.Now < _viewingTime.AddMinutes(_timePerBlock * 4) && DateTime.Now > _viewingTime)
                {
                    DoViewThisChannel();
                }
                return true;
            }

            if (_currentProgram.StartTime <= DateTime.Now
                && _currentProgram.StopTime > DateTime.Now)
            {
                ActiveRecording activeRecording;
                if (PluginMain.IsActiveRecording(_currentChannel.ChannelId, _currentProgram, out activeRecording))
                {
                    Log.Info("TVGuide: clicked on a currently running recording");
                    GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_MENU);
                    if (dlg == null)
                    {
                        return true;
                    }

                    dlg.Reset();
                    dlg.SetHeading(_currentProgram.Title);
                    dlg.AddLocalizedString(979); //Play recording from beginning
                    dlg.AddLocalizedString(938); //View this channel
                    dlg.DoModal(GetID);

                    if (dlg.SelectedLabel == -1)
                        return true;

                    switch (dlg.SelectedId)
                    {
                        case 979: // Play recording from beginning
                            using (ControlServiceAgent tvControlAgent = new ControlServiceAgent())
                            {
                                Recording recording = tvControlAgent.GetRecordingById(activeRecording.RecordingId);
                                if (recording != null)
                                {
                                    RecordedBase.PlayFromPreRecPoint(recording);
                                }
                            }
                            break;

                        case 938: //View this channel
                            DoViewThisChannel();
                            break;
                    }
                }
                else
                {
                    DoViewThisChannel();
                }
            }
            else
            {
                ShowProgramInfo();
                return false;
            }
            return true;
        }
예제 #15
0
 private void LoadSchedules(bool refresh)
 {
     if (refresh)
     {
         using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent())
         using (ControlServiceAgent tvControlAgent = new ControlServiceAgent())
         {
             _controller.RefreshUpcomingPrograms(tvSchedulerAgent, tvControlAgent);
         }
     }
 }
        public bool Scrobble(string filename)
        {
            StopScrobble();

            if (!g_Player.IsTVRecording) return false;

            // get recording details from tv database
            ControlServiceAgent layer = new ControlServiceAgent();
            Recording recording = layer.GetRecordingByFileName(filename);
            if (recording == null || string.IsNullOrEmpty(recording.Title))
            {
                TraktLogger.Info("Unable to get recording details from argus database.");
                return false;
            }

            // get year from title if available, some EPG entries contain this
            string title = null;
            string year = null;
            GetTitleAndYear(recording, out title, out year);

            CurrentRecording = new VideoInfo
            {
                Type = recording.EpisodeNumber != null || recording.SeriesNumber != null ? VideoType.Series : VideoType.Movie,
                Title = title,
                Year = year,
                SeasonIdx = recording.SeriesNumber == null ? null : recording.SeriesNumber.ToString(),
                EpisodeIdx = recording.EpisodeNumber == null ? null : recording.EpisodeNumber.ToString(),
                IsScrobbling = true
            };

            if (CurrentRecording.Type == VideoType.Series)
                TraktLogger.Info("Detected tv-series '{0}' playing in Argus TV-Recordings", CurrentRecording.ToString());
            else
                TraktLogger.Info("Detected movie '{0}' playing in Argus TV-Recordings", CurrentRecording.ToString());

            #region scrobble timer
            TraktTimer = new Timer(new TimerCallback((stateInfo) =>
            {
                Thread.CurrentThread.Name = "Scrobble";

                VideoInfo videoInfo = stateInfo as VideoInfo;

                // maybe the program does not exist on trakt
                // ignore in future if it failed previously
                if (videoInfo.IsScrobbling)
                {
                    if (videoInfo.Type == VideoType.Series)
                    {
                        videoInfo.IsScrobbling = BasicHandler.ScrobbleEpisode(videoInfo, TraktScrobbleStates.watching);
                    }
                    else
                    {
                        videoInfo.IsScrobbling = BasicHandler.ScrobbleMovie(videoInfo, TraktScrobbleStates.watching);
                    }

                    if (videoInfo.Equals(CurrentRecording))
                        CurrentRecording.IsScrobbling = videoInfo.IsScrobbling;
                }

            }), CurrentRecording, 3000, 900000);
            #endregion

            return true;
        }
예제 #17
0
        internal static bool HasUpcomingRecording(Guid channelId, GuideProgram program, out UpcomingRecording upcomingRecording)
        {
            using (ControlServiceAgent tvControlAgent = new ControlServiceAgent())
            {
                upcomingRecording = null;
                Guid upcomingProgramId = program.GetUniqueUpcomingProgramId(channelId);

                UpcomingRecording[] upcomingRecordings = tvControlAgent.GetAllUpcomingRecordings(UpcomingRecordingsFilter.All, true);
                foreach (UpcomingRecording recording in upcomingRecordings)
                {
                    if (recording.Program.UpcomingProgramId == upcomingProgramId)
                    {
                        upcomingRecording = recording;
                        return true;
                    }
                }
                return false;
            }
        }
예제 #18
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.");
        }
예제 #19
0
        private IMBotMessage DoStatusCommand(IMBotConversation conversation, IList<string> arguments)
        {
            using (ControlServiceAgent tvControlAgent = new ControlServiceAgent())
            {
                bool fixedWidth = false;

                // Check if currently recording :
                ActiveRecording[] activeRecordings = tvControlAgent.GetActiveRecordings();
                LiveStream[] liveStreams = tvControlAgent.GetLiveStreams();
                UpcomingRecording upcomingRecording = tvControlAgent.GetNextUpcomingRecording(false);

                StringBuilder reply = new StringBuilder();

                if (activeRecordings.Length > 0)
                {
                    reply.Append("Currently recording:");
                    foreach (ActiveRecording activeRecording in activeRecordings)
                    {
                        PluginService pluginService = null;
                        if (activeRecording.CardChannelAllocation != null)
                        {
                            pluginService =
                                RecorderTunersCache.GetRecorderTunerById(activeRecording.CardChannelAllocation.RecorderTunerId);
                        }

                        reply.AppendLine();
                        Utility.AppendProgramDetails(reply, activeRecording.Program.Channel, activeRecording.Program);
                        reply.AppendFormat(" [{0}]", pluginService == null ? "-" : pluginService.Name);
                    }
                    fixedWidth = true;

                    if (liveStreams.Length > 0
                        || upcomingRecording != null)
                    {
                        reply.AppendLine();
                    }
                }
                if (liveStreams.Length > 0)
                {
                    reply.Append("Currently streaming:");
                    foreach (LiveStream liveStream in liveStreams)
                    {
                        reply.AppendLine();
                        reply.AppendFormat("[{0}]", liveStream.Channel.DisplayName);
                    }
                    fixedWidth = true;

                    if (upcomingRecording != null)
                    {
                        reply.AppendLine();
                    }
                }
                if (upcomingRecording != null)
                {
                    if (reply.Length == 0)
                    {
                        reply.AppendLine("Idle, next scheduled recording:");
                    }
                    else
                    {
                        reply.AppendLine("Next scheduled recording:");
                    }

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

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

                    fixedWidth = true;
                }
                if (reply.Length == 0)
                {
                    reply.Append("Idle");
                }
                reply.AppendLine().AppendLine();
                reply.Append("ARGUS TV Messenger " + Constants.ProductVersion + @", running on server \\").AppendLine(Dns.GetHostName());
                reply.Append("http://www.argus-tv.com");
                return new IMBotMessage(reply.ToString(), fixedWidth);
            }
        }
예제 #20
0
        private void ShowContextMenu()
        {
            GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_MENU);
            if (dlg != null)
            {
                dlg.Reset();
                dlg.SetHeading(GUILocalizeStrings.Get(924)); //Menu

                bool isRecording = false;
                bool isAlert = false;
                ActiveRecording activeRecording = null;

                if (_currentChannel != null)
                {
                    dlg.AddLocalizedString(938); // View this channel

                    if (_currentProgram != null)
                    {
                        dlg.AddLocalizedString(1020); // Information
                        string recordIconImage = GetChannelProgramIcon(_currentChannel, _currentProgram.GuideProgramId, out isRecording, out isAlert);
                    }
                }

                if (_currentProgram != null && _currentProgram.StartTime > DateTime.Now)
                {
                    if (isAlert)
                    {
                        dlg.AddLocalizedString(1212); // cancel reminder
                    }
                    else if (!isRecording)
                    {
                        dlg.AddLocalizedString(1040); // set reminder
                    }
                }

                if (_currentProgram != null && _currentChannel != null)
                {
                    if (PluginMain.IsActiveRecording(_currentChannel.ChannelId, _currentProgram, out activeRecording))
                    {
                        dlg.AddLocalizedString(1449); // Abort active recording
                    }
                    else if (isRecording)
                    {
                        dlg.AddLocalizedString(610); // don't record
                    }
                    else
                    {
                        dlg.AddLocalizedString(264); // Record
                    }
                }

                if (PluginMain.Navigator.GetGroups(_channelType).Count > 1)
                {
                    dlg.AddLocalizedString(971); // Group
                }

                dlg.AddLocalizedString(939); // Switch mode
                dlg.AddLocalizedString(368); // IMDB

                dlg.DoModal(GetID);
                if (dlg.SelectedLabel == -1)
                {
                    return;
                }
                switch (dlg.SelectedId)
                {
                    case 368: // IMDB
                        OnGetIMDBInfo();
                        break;

                    case 971: //group
                        OnSelectChannelGroup();
                        //dlg.Reset();
                        //dlg.SetHeading(GUILocalizeStrings.Get(971));//Group
                        //foreach (ChannelGroup group in TVHome.Navigator.Groups)
                        //{
                        //  dlg.Add(group.GroupName);
                        //}
                        //dlg.DoModal(GetID);
                        //if (dlg.SelectedLabel == -1) return;
                        //TVHome.Navigator.SetCurrentGroup(dlg.SelectedLabelText);

                        GetChannels(true);
                        Update(false);
                        SetFocus();
                        break;

                    case 938: // view channel
                        PluginMain.Navigator.ZapToChannel(_currentChannel, false);
                        break;

                    case 939: // switch mode
                        OnSwitchMode();
                        break;

                    case 1020: // information
                        ShowProgramInfo();
                        break;

                    case 610: // don't record
                    case 264: // record
                        OnRecordOrAlert(ScheduleType.Recording);
                        break;

                    case 1212: // don't notify
                    case 1040: // notify
                        OnRecordOrAlert(ScheduleType.Alert);
                        break;

                    case 1449:
                        //TODO: put this somewhere else
                        GUIDialogYesNo dlgYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);
                        if (dlgYesNo != null)
                        {
                            dlgYesNo.SetHeading(Utility.GetLocalizedText(TextId.StopRecording));
                            dlgYesNo.SetLine(1, _currentProgram.Title);
                            dlgYesNo.SetLine(2, string.Empty);
                            dlgYesNo.SetLine(3, string.Empty);
                            dlgYesNo.SetDefaultToYes(false);
                            dlgYesNo.DoModal(GetID);

                            if (dlgYesNo.IsConfirmed && activeRecording != null)
                            {
                                using (ControlServiceAgent tvControlAgent = new ControlServiceAgent())
                                {
                                    tvControlAgent.AbortActiveRecording(activeRecording);
                                }
                            }
                        }
                        break;
                }
            }
        }
예제 #21
0
        private bool OnAbortActiveRecording(ActiveRecording rec)
        {
            using (ControlServiceAgent tvControlAgent = new ControlServiceAgent())
            {
                if (rec == null) return false;
                bool aborted = false;
                GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
                if (dlg == null) return false;
                dlg.Reset();
                dlg.SetHeading(rec.Program.Title);
                dlg.AddLocalizedString(1449); //Stop recording
                dlg.AddLocalizedString(979);  //Play recorded from beginning
                dlg.AddLocalizedString(980);  //Play recorded from live point

                Recording recording = tvControlAgent.GetRecordingById(rec.RecordingId);
                if (recording != null && recording.LastWatchedPosition.HasValue)
                {
                    dlg.AddLocalizedString(900);//play from last point
                }

                dlg.DoModal(GetID);
                switch (dlg.SelectedId)
                {
                    case 979:
                        if (recording != null)
                        {
                            RecordedBase.PlayFromPreRecPoint(recording);
                        }
                        break;

                    case 980:
                        RecordedBase.PlayFromLivePoint(rec);
                        break;

                    case 900:
                        if (recording != null)
                        {
                            RecordedBase.PlayRecording(recording, recording.LastWatchedPosition.Value);
                        }
                        break;

                    case 1449: // Abort
                        GUIDialogYesNo dlgYesNo = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO);
                        if (dlgYesNo != null)
                        {
                            dlgYesNo.Reset();
                            dlgYesNo.SetHeading(Utility.GetLocalizedText(TextId.StopRecording));
                            dlgYesNo.SetLine(1, rec.Program.Channel.DisplayName);
                            dlgYesNo.SetLine(2, rec.Program.Title);
                            dlgYesNo.SetLine(3, string.Empty);
                            dlgYesNo.SetDefaultToYes(false);
                            dlgYesNo.DoModal(GetID);

                            if (dlgYesNo.IsConfirmed)
                            {
                                tvControlAgent.AbortActiveRecording(rec);
                                aborted = true;
                            }
                        }
                        break;
                }
                return aborted;
            }
        }
예제 #22
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."));
        }
예제 #23
0
 private void RefreshBotPersonalMessage()
 {
     if (_messenger.Owner != null)
     {
         string message = "Idle";
         PresenceStatus status = PresenceStatus.Online;
         using (ControlServiceAgent tvControlAgent = new ControlServiceAgent())
         {
             ActiveRecording[] activeRecordings = tvControlAgent.GetActiveRecordings();
             if (activeRecordings.Length > 0)
             {
                 message = "Recording";
                 status = PresenceStatus.Busy;
             }
             else
             {
                 LiveStream[] liveStreams = tvControlAgent.GetLiveStreams();
                 if (liveStreams.Length > 0)
                 {
                     message = "Streaming";
                     status = PresenceStatus.Away;
                 }
                 else
                 {
                     UpcomingRecording upcomingRecording = tvControlAgent.GetNextUpcomingRecording(false);
                     if (upcomingRecording != null)
                     {
                         message = "Waiting for next scheduled recording";
                     }
                 }
             }
         }
         if (_messenger.Owner.PersonalMessage == null
             || _messenger.Owner.PersonalMessage.Message != message)
         {
             _messenger.Owner.PersonalMessage = new PersonalMessage(message);
         }
         if (_messenger.Owner.Status != status)
         {
             _messenger.Owner.Status = status;
         }
     }
 }
예제 #24
0
        static int Main(string[] args)
        {
            try
            {
                if (args.Length > 0 && String.Equals(args[0], "Help", StringComparison.InvariantCultureIgnoreCase))
                {
                    ShowHelp();
                }
                else if (args.Length >= 2 && String.Equals(args[0], "MyVideo", StringComparison.InvariantCultureIgnoreCase))
                {
                    InitializeServiceChannelFactories();
                    Log(LogSeverity.Information, "Creating MP xml");
                    if (ServiceChannelFactories.IsInitialized)
                    {
                        using (ControlServiceAgent controlServiceAgent = new ControlServiceAgent())
                        {
                            string recordedFileName = args[1];

                            Recording recording = controlServiceAgent.GetRecordingByFileName(recordedFileName);
                            if (recording != null)
                            {
                                Tags tags = new Tags();
                                tags.SimpleTags.Add(new SimpleTag("TITLE", recording.Title));
                                tags.SimpleTags.Add(new SimpleTag("COMMENT", recording.Description));
                                tags.SimpleTags.Add(new SimpleTag("GENRE", recording.Category));
                                tags.SimpleTags.Add(new SimpleTag("CHANNEL_NAME", recording.ChannelDisplayName));

                                string     myVideoFileName = Path.ChangeExtension(recordedFileName, "xml");
                                FileStream outFile         = new FileStream(myVideoFileName, FileMode.Create, FileAccess.Write, FileShare.None);
                                try
                                {
                                    XmlSerializerNamespaces nspaces = new XmlSerializerNamespaces();
                                    nspaces.Add(String.Empty, String.Empty);

                                    XmlSerializer serializer = new XmlSerializer(typeof(Tags));
                                    serializer.Serialize(outFile, tags, nspaces);
                                }
                                catch (SerializationException ex)
                                {
                                    Debug.WriteLine("Failed to serialize. Reason: " + ex.Message, "Error");
                                }
                                catch (Exception ex)
                                {
                                    Debug.WriteLine(ex.Message);
                                }
                                finally
                                {
                                    outFile.Close();
                                }
                            }
                            else
                            {
                                Log(LogSeverity.Error, string.Format("Failed to find recording \"{0}\"", recordedFileName));
                            }
                        }
                    }
                }
                else if (args.Length == 2 && String.Equals(args[0], "Log", StringComparison.InvariantCultureIgnoreCase))
                {
                    Log(LogSeverity.Information, args[1]);
                }
                else if (args.Length >= 3 && String.Equals(args[0], "Delete", StringComparison.InvariantCultureIgnoreCase))
                {
                    InitializeServiceChannelFactories();
                    Log(LogSeverity.Information, string.Format("Deleting {0} from ARGUS TV {1} the actual recording", args[1], (args[2] == "1" ? "and" : "but not")));
                    if (ServiceChannelFactories.IsInitialized)
                    {
                        using (ControlServiceAgent controlServiceAgent = new ControlServiceAgent())
                        {
                            string  recordedFileName = args[1];
                            Boolean keepGile         = (args[2] == "1" ? true : false);
                            controlServiceAgent.DeleteRecording(recordedFileName, keepGile);
                        }
                    }
                }
                else if (args.Length == 4 && String.Equals(args[0], "description", StringComparison.InvariantCultureIgnoreCase))
                {
                    InitializeServiceChannelFactories();
                    string recordedFileName = args[1];
                    string outputFileName   = Path.ChangeExtension(args[1], args[2]);
                    string fileString       = args[3].ToLower();
                    Log(LogSeverity.Information, string.Format("Creating description file for {0} called {1}", args[1], outputFileName));
                    if (ServiceChannelFactories.IsInitialized)
                    {
                        using (ControlServiceAgent controlServiceAgent = new ControlServiceAgent())
                        {
                            Recording tvRecording = controlServiceAgent.GetRecordingByFileName(recordedFileName);
                            fileString = fileString.Replace("{description}", tvRecording.Description);
                            fileString = fileString.Replace("{starttime}", tvRecording.StartTime.ToString());
                            fileString = fileString.Replace("{stoptime}", tvRecording.StopTime.ToString());
                            fileString = fileString.Replace("{title}", tvRecording.Title.ToString());
                            fileString = fileString.Replace("{episodenumber}", tvRecording.EpisodeNumber.ToString());
                            fileString = fileString.Replace("{seriesnumber}", tvRecording.SeriesNumber.ToString());
                            using (StreamWriter descriptionfile = new StreamWriter(outputFileName, false, Encoding.UTF8))
                            {
                                descriptionfile.WriteLine(fileString);
                            }
                        }
                    }
                }
                else if (args.Length >= 3 && String.Equals(args[0], "Rename", StringComparison.InvariantCultureIgnoreCase))
                {
                    InitializeServiceChannelFactories();
                    Log(LogSeverity.Information, string.Format("Renaming {0} to {1}", args[1], args[2]));
                    if (ServiceChannelFactories.IsInitialized)
                    {
                        using (ControlServiceAgent controlServiceAgent = new ControlServiceAgent())
                        {
                            string    recordedFileName = args[1];
                            string    newFileName      = args[2];
                            Recording recording;

                            using (ControlServiceAgent controlAgent = new ControlServiceAgent())
                            {
                                recording = controlAgent.GetRecordingByFileName(newFileName);
                            }

                            if (recording == null)
                            {
                                string lUncPath;
                                if (newFileName.StartsWith("\\"))
                                {
                                    lUncPath = newFileName;
                                }
                                else
                                {
                                    try
                                    {
                                        lUncPath = GetUncPath(newFileName);
                                    }
                                    catch (IOException)
                                    {
                                        Console.Error.WriteLine("Could not get a UNC path for recording");
                                        Log(LogSeverity.Warning, string.Format("Could not convert {0} to an unc path", newFileName));
                                        LogArgs(LogSeverity.Information, args);
                                        return(-2);
                                    }
                                }
                                controlServiceAgent.ChangeRecordingFile(recordedFileName, lUncPath, null, null);
                            }
                            else
                            {
                                Console.Error.WriteLine("Could not move recording as another one with same name allready exsist");
                                Log(LogSeverity.Warning, string.Format("Could not rename as a recording with the name {0} allready exist in database", newFileName));
                                LogArgs(LogSeverity.Information, args);
                                return(-2);
                            }
                        }
                    }
                }
                else if (args.Length >= 2 && String.Equals(args[0], "IsPartial", StringComparison.InvariantCultureIgnoreCase))
                {
                    InitializeServiceChannelFactories();
                    if (ServiceChannelFactories.IsInitialized)
                    {
                        using (ControlServiceAgent controlServiceAgent = new ControlServiceAgent())
                        {
                            string    recordedFileName = args[1];
                            Recording recording;

                            using (ControlServiceAgent controlAgent = new ControlServiceAgent())
                            {
                                recording = controlAgent.GetRecordingByFileName(recordedFileName);
                            }

                            if (recording != null)
                            {
                                return(recording.IsPartialRecording ? -1 : 0);
                            }
                            else
                            {
                                Console.Error.WriteLine("Could not check recording as it could not be found in the database");
                                Log(LogSeverity.Warning, string.Format("{0} not found in the ARGUS TV database", args[1]));
                                LogArgs(LogSeverity.Information, args);
                                return(-2);
                            }
                        }
                    }
                    else
                    {
                        return(-2);
                    }
                }
                else if (args.Length >= 2 && String.Equals(args[0], "Exist", StringComparison.InvariantCultureIgnoreCase))
                {
                    InitializeServiceChannelFactories();
                    if (ServiceChannelFactories.IsInitialized)
                    {
                        using (ControlServiceAgent controlServiceAgent = new ControlServiceAgent())
                        {
                            string    recordedFileName = args[1];
                            Recording recording;

                            using (ControlServiceAgent controlAgent = new ControlServiceAgent())
                            {
                                recording = controlAgent.GetRecordingByFileName(recordedFileName);
                            }

                            if (recording != null)
                            {
                                return(0);
                            }
                            else
                            {
                                return(-1);
                            }
                        }
                    }
                    else
                    {
                        return(-2);
                    }
                }
                else if (args.Length >= 1 && String.Equals(args[0], "Wake", StringComparison.InvariantCultureIgnoreCase))
                {
                }
                else
                {
                    Log(LogSeverity.Warning, "Batch processor did not get valid command(s)");
                    LogArgs(LogSeverity.Information, args);
                }
            }
            catch
            {
                return(-2);
            }
            if (ServiceChannelFactories.IsInitialized)
            {
                return(0);
            }
            else
            {
                return(-3);
            }
        }
예제 #25
0
        static int Main(string[] args)
        {
            try
            {
                if (args.Length > 0 && String.Equals(args[0], "Help", StringComparison.InvariantCultureIgnoreCase))
                {
                    ShowHelp();
                }
                else if (args.Length >= 2 && String.Equals(args[0], "MyVideo", StringComparison.InvariantCultureIgnoreCase))
                {
                    InitializeServiceChannelFactories();
                    Log(LogSeverity.Information, "Creating MP xml");
                    if (ServiceChannelFactories.IsInitialized)
                    {
                        using (ControlServiceAgent controlServiceAgent = new ControlServiceAgent())
                        {
                            string recordedFileName = args[1];

                            Recording recording = controlServiceAgent.GetRecordingByFileName(recordedFileName);
                            if (recording != null)
                            {
                                Tags tags = new Tags();
                                tags.SimpleTags.Add(new SimpleTag("TITLE", recording.Title));
                                tags.SimpleTags.Add(new SimpleTag("COMMENT", recording.Description));
                                tags.SimpleTags.Add(new SimpleTag("GENRE", recording.Category));
                                tags.SimpleTags.Add(new SimpleTag("CHANNEL_NAME", recording.ChannelDisplayName));

                                string myVideoFileName = Path.ChangeExtension(recordedFileName, "xml");
                                FileStream outFile = new FileStream(myVideoFileName, FileMode.Create, FileAccess.Write, FileShare.None);
                                try
                                {
                                    XmlSerializerNamespaces nspaces = new XmlSerializerNamespaces();
                                    nspaces.Add(String.Empty, String.Empty);

                                    XmlSerializer serializer = new XmlSerializer(typeof(Tags));
                                    serializer.Serialize(outFile, tags, nspaces);
                                }
                                catch (SerializationException ex)
                                {
                                    Debug.WriteLine("Failed to serialize. Reason: " + ex.Message, "Error");
                                }
                                catch (Exception ex)
                                {
                                    Debug.WriteLine(ex.Message);
                                }
                                finally
                                {
                                    outFile.Close();
                                }
                            }
                            else
                            {
                                Log(LogSeverity.Error, string.Format("Failed to find recording \"{0}\"", recordedFileName));
                            }
                        }
                    }
                }
                else if (args.Length == 2 && String.Equals(args[0], "Log", StringComparison.InvariantCultureIgnoreCase))
                {
                    Log(LogSeverity.Information, args[1]);
                }
                else if (args.Length >= 3 && String.Equals(args[0], "Delete", StringComparison.InvariantCultureIgnoreCase))
                {
                    InitializeServiceChannelFactories();
                    Log(LogSeverity.Information, string.Format("Deleting {0} from ARGUS TV {1} the actual recording", args[1], (args[2] == "1" ? "and" : "but not")));
                    if (ServiceChannelFactories.IsInitialized)
                    {
                        using (ControlServiceAgent controlServiceAgent = new ControlServiceAgent())
                        {
                            string recordedFileName = args[1];
                            Boolean keepGile = (args[2] == "1" ? true : false);
                            controlServiceAgent.DeleteRecording(recordedFileName, keepGile);

                        }
                    }
                }
                else if (args.Length == 4 && String.Equals(args[0], "description", StringComparison.InvariantCultureIgnoreCase))
                {
                    InitializeServiceChannelFactories();
                    string recordedFileName = args[1];
                    string outputFileName = Path.ChangeExtension(args[1], args[2]);
                    string fileString = args[3].ToLower();
                    Log(LogSeverity.Information, string.Format("Creating description file for {0} called {1}", args[1], outputFileName));
                    if (ServiceChannelFactories.IsInitialized)
                    {
                        using (ControlServiceAgent controlServiceAgent = new ControlServiceAgent())
                        {
                            Recording tvRecording = controlServiceAgent.GetRecordingByFileName(recordedFileName);
                            fileString = fileString.Replace("{description}", tvRecording.Description);
                            fileString = fileString.Replace("{starttime}", tvRecording.StartTime.ToString());
                            fileString = fileString.Replace("{stoptime}", tvRecording.StopTime.ToString());
                            fileString = fileString.Replace("{title}", tvRecording.Title.ToString());
                            fileString = fileString.Replace("{episodenumber}", tvRecording.EpisodeNumber.ToString());
                            fileString = fileString.Replace("{seriesnumber}", tvRecording.SeriesNumber.ToString());
                            using (StreamWriter descriptionfile = new StreamWriter(outputFileName, false, Encoding.UTF8))
                            {
                                descriptionfile.WriteLine(fileString);
                            }
                        }
                    }
                }
                else if (args.Length >= 3 && String.Equals(args[0], "Rename", StringComparison.InvariantCultureIgnoreCase))
                {
                    InitializeServiceChannelFactories();
                    Log(LogSeverity.Information, string.Format("Renaming {0} to {1}", args[1], args[2]));
                    if (ServiceChannelFactories.IsInitialized)
                    {
                        using (ControlServiceAgent controlServiceAgent = new ControlServiceAgent())
                        {
                            string recordedFileName = args[1];
                            string newFileName = args[2];
                            Recording recording;

                            using (ControlServiceAgent controlAgent = new ControlServiceAgent())
                            {
                                recording = controlAgent.GetRecordingByFileName(newFileName);
                            }

                            if (recording == null)
                            {
                                string lUncPath;
                                if (newFileName.StartsWith("\\"))
                                    lUncPath = newFileName;
                                else
                                {
                                    try
                                    {
                                        lUncPath = GetUncPath(newFileName);
                                    }
                                    catch (IOException)
                                    {
                                        Console.Error.WriteLine("Could not get a UNC path for recording");
                                        Log(LogSeverity.Warning, string.Format("Could not convert {0} to an unc path", newFileName));
                                        LogArgs(LogSeverity.Information, args);
                                        return -2;
                                    }
                                }
                                controlServiceAgent.ChangeRecordingFile(recordedFileName, lUncPath, null, null);
                            }
                            else
                            {
                                Console.Error.WriteLine("Could not move recording as another one with same name allready exsist");
                                Log(LogSeverity.Warning, string.Format("Could not rename as a recording with the name {0} allready exist in database", newFileName));
                                LogArgs(LogSeverity.Information, args);
                                return -2;
                            }
                        }
                    }
                }
                else if (args.Length >= 2 && String.Equals(args[0], "IsPartial", StringComparison.InvariantCultureIgnoreCase))
                {
                    InitializeServiceChannelFactories();
                    if (ServiceChannelFactories.IsInitialized)
                    {
                        using (ControlServiceAgent controlServiceAgent = new ControlServiceAgent())
                        {
                            string recordedFileName = args[1];
                            Recording recording;

                            using (ControlServiceAgent controlAgent = new ControlServiceAgent())
                            {
                                recording = controlAgent.GetRecordingByFileName(recordedFileName);
                            }

                            if (recording != null)
                                return (recording.IsPartialRecording ? -1 : 0);
                            else
                            {
                                Console.Error.WriteLine("Could not check recording as it could not be found in the database");
                                Log(LogSeverity.Warning, string.Format("{0} not found in the ARGUS TV database", args[1]));
                                LogArgs(LogSeverity.Information, args);
                                return -2;
                            }
                        }
                    }
                    else
                    {
                        return -2;
                    }
                }
                else if (args.Length >= 2 && String.Equals(args[0], "Exist", StringComparison.InvariantCultureIgnoreCase))
                {
                    InitializeServiceChannelFactories();
                    if (ServiceChannelFactories.IsInitialized)
                    {
                        using (ControlServiceAgent controlServiceAgent = new ControlServiceAgent())
                        {
                            string recordedFileName = args[1];
                            Recording recording;

                            using (ControlServiceAgent controlAgent = new ControlServiceAgent())
                            {
                                recording = controlAgent.GetRecordingByFileName(recordedFileName);
                            }

                            if (recording != null)
                                return 0;
                            else
                                return -1;
                        }
                    }
                    else
                    {
                        return -2;
                    }
                }
                else if (args.Length >= 1 && String.Equals(args[0], "Wake", StringComparison.InvariantCultureIgnoreCase))
                {

                }
                else
                {
                    Log(LogSeverity.Warning, "Batch processor did not get valid command(s)");
                    LogArgs(LogSeverity.Information, args);
                }
            }
            catch
            {
                return -2;
            }
            if (ServiceChannelFactories.IsInitialized)
                return 0;
            else
                return -3;
        }
예제 #26
0
        private IMBotMessage DoStatusCommand(IMBotConversation conversation, IList <string> arguments)
        {
            using (ControlServiceAgent tvControlAgent = new ControlServiceAgent())
            {
                bool fixedWidth = false;

                // Check if currently recording :
                ActiveRecording[] activeRecordings  = tvControlAgent.GetActiveRecordings();
                LiveStream[]      liveStreams       = tvControlAgent.GetLiveStreams();
                UpcomingRecording upcomingRecording = tvControlAgent.GetNextUpcomingRecording(false);

                StringBuilder reply = new StringBuilder();

                if (activeRecordings.Length > 0)
                {
                    reply.Append("Currently recording:");
                    foreach (ActiveRecording activeRecording in activeRecordings)
                    {
                        PluginService pluginService = null;
                        if (activeRecording.CardChannelAllocation != null)
                        {
                            pluginService =
                                RecorderTunersCache.GetRecorderTunerById(activeRecording.CardChannelAllocation.RecorderTunerId);
                        }

                        reply.AppendLine();
                        Utility.AppendProgramDetails(reply, activeRecording.Program.Channel, activeRecording.Program);
                        reply.AppendFormat(" [{0}]", pluginService == null ? "-" : pluginService.Name);
                    }
                    fixedWidth = true;

                    if (liveStreams.Length > 0 ||
                        upcomingRecording != null)
                    {
                        reply.AppendLine();
                    }
                }
                if (liveStreams.Length > 0)
                {
                    reply.Append("Currently streaming:");
                    foreach (LiveStream liveStream in liveStreams)
                    {
                        reply.AppendLine();
                        reply.AppendFormat("[{0}]", liveStream.Channel.DisplayName);
                    }
                    fixedWidth = true;

                    if (upcomingRecording != null)
                    {
                        reply.AppendLine();
                    }
                }
                if (upcomingRecording != null)
                {
                    if (reply.Length == 0)
                    {
                        reply.AppendLine("Idle, next scheduled recording:");
                    }
                    else
                    {
                        reply.AppendLine("Next scheduled recording:");
                    }

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

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

                    fixedWidth = true;
                }
                if (reply.Length == 0)
                {
                    reply.Append("Idle");
                }
                reply.AppendLine().AppendLine();
                reply.Append("ARGUS TV Messenger " + Constants.ProductVersion + @", running on server \\").AppendLine(Dns.GetHostName());
                reply.Append("http://www.argus-tv.com");
                return(new IMBotMessage(reply.ToString(), fixedWidth));
            }
        }