Example #1
0
        private void _connectionBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            bool retryTcpConnection =
                (this.ServiceTransport == ServiceTransport.BinaryHttps &&
                 !String.IsNullOrEmpty(Config.Current.TcpServerName) &&
                 DateTime.Now > _nextTcpConnectionAttemptTime);

            if (!this.IsConnected ||
                retryTcpConnection)
            {
                e.Result = false;

                try
                {
                    if (!String.IsNullOrEmpty(Config.Current.TcpServerName))
                    {
                        ServerSettings serverSettings = new ServerSettings();
                        serverSettings.ServerName = Config.Current.TcpServerName;
                        serverSettings.Port       = Config.Current.TcpPort;
                        serverSettings.Transport  = ServiceTransport.NetTcp;

                        ServiceChannelFactories.Initialize(serverSettings, true);

                        using (CoreServiceAgent coreAgent = new CoreServiceAgent())
                        {
                            coreAgent.EnsureEventListener(EventGroup.RecordingEvents, _eventsServiceBaseUrl, Constants.EventListenerApiVersion);
                        }
                        lock (_connectionLock)
                        {
                            _serviceTransport = serverSettings.Transport;
                            _isConnected      = true;
                        }
                        _nextTcpConnectionAttemptTime = DateTime.MaxValue;
                        e.Result = true;
                    }
                    else
                    {
                        ConnectOverHttps();
                        e.Result = true;
                    }
                }
                catch
                {
                    try
                    {
                        ConnectOverHttps();
                        e.Result = true;
                    }
                    catch
                    {
                        this.IsConnected = false;
                    }
                }
            }
            else
            {
                e.Result = this.IsConnected;
            }
        }
Example #2
0
 private static void DoKeepAlive()
 {
     try
     {
         // Inform the local system we need it.
         SetThreadExecutionState(EXECUTION_STATE.ES_SYSTEM_REQUIRED);
         // Tell the server we need it.
         using (CoreServiceAgent coreAgent = new CoreServiceAgent())
         {
             coreAgent.KeepServerAlive();
         }
     }
     catch { }
 }
Example #3
0
        public static void KeepImportServiceAlive()
        {
            try
            {
                Debug.WriteLine(String.Format("{0:HH:mm:ss} - KeepImportServiceAlive called", DateTime.Now));

                // Inform the local system we need it.
                SetThreadExecutionState(EXECUTION_STATE.ES_SYSTEM_REQUIRED);

                // Tell the server we still need it.
                using (CoreServiceAgent coreServiceAgent = new CoreServiceAgent())
                {
                    coreServiceAgent.KeepServerAlive();
                }
            }
            catch { }
        }
Example #4
0
 private void _exitToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (this.IsConnected &&
         this.ServiceTransport == ServiceTransport.NetTcp)
     {
         try
         {
             using (CoreServiceAgent coreAgent = new CoreServiceAgent())
             {
                 coreAgent.RemoveEventListener(_eventsServiceBaseUrl);
             }
         }
         catch
         {
         }
     }
     Application.Exit();
 }
Example #5
0
        private void EnsureEventsListenerService()
        {
            if (_eventsServiceHost == null)
            {
                try
                {
                    string eventsServiceBaseUrl = String.Format(CultureInfo.InvariantCulture, "net.tcp://localhost:{0}/ArgusTV.Messenger/", Properties.Settings.Default.EventsTcpPort);

                    EventsListenerService.OnUpcomingAlertsChanged     += new EventHandler(EventsListenerService_OnUpcomingAlertsChanged);
                    EventsListenerService.OnRecordingStarted          += new EventsListenerService.RecordingEventDelegate(EventsListenerService_OnRecordingStarted);
                    EventsListenerService.OnRecordingEnded            += new EventsListenerService.RecordingEventDelegate(EventsListenerService_OnRecordingEnded);
                    EventsListenerService.OnConfigurationChanged      += new EventsListenerService.ConfigurationChangedDelegate(EventsListenerService_OnConfigurationChanged);
                    EventsListenerService.OnLiveStreamStarted         += new EventsListenerService.StreamingEventDelegate(EventsListenerService_OnLiveStreamChanged);
                    EventsListenerService.OnLiveStreamTuned           += new EventsListenerService.StreamingEventDelegate(EventsListenerService_OnLiveStreamChanged);
                    EventsListenerService.OnLiveStreamEnded           += new EventsListenerService.StreamingEventDelegate(EventsListenerService_OnLiveStreamChanged);
                    EventsListenerService.OnUpcomingRecordingsChanged += new EventHandler(EventsListenerService_OnUpcomingRecordingsChanged);

                    _eventsServiceHost = EventsListenerService.CreateServiceHost(eventsServiceBaseUrl);
                    _eventsServiceHost.Open();

                    using (CoreServiceAgent systemAgent = new CoreServiceAgent())
                    {
                        systemAgent.EnsureEventListener(
                            EventGroup.RecordingEvents | EventGroup.ScheduleEvents | EventGroup.SystemEvents,
                            eventsServiceBaseUrl, Constants.EventListenerApiVersion);
                    }
                }
                catch
                {
                    if (_eventsServiceHost != null &&
                        _eventsServiceHost.State == CommunicationState.Opened)
                    {
                        _eventsServiceHost.Close();
                    }
                    _eventsServiceHost = null;
                }
            }
        }
        private void ImportEpgPrograms(EpgChannel epgChannel)
        {
            if (!this.IsArgusTVConnectionInitialized)
            {
                InitializeArgusTVConnection(null);
            }
            if (this.IsArgusTVConnectionInitialized)
            {
                TvDatabase.TvBusinessLayer layer = new TvDatabase.TvBusinessLayer();
                bool epgSyncOn = Convert.ToBoolean(layer.GetSetting(SettingName.EpgSyncOn, false.ToString()).Value);
                if (epgSyncOn)
                {
                    DVBBaseChannel dvbChannel = epgChannel.Channel as DVBBaseChannel;
                    if (dvbChannel != null)
                    {
                        TvDatabase.Channel mpChannel = layer.GetChannelByTuningDetail(dvbChannel.NetworkId, dvbChannel.TransportId, dvbChannel.ServiceId);
                        if (mpChannel != null)
                        {
                            Log.Debug("ArgusTV.Recorder.MediaPortalTvServer: ImportEpgPrograms(): received {0} programs on {1}", epgChannel.Programs.Count, mpChannel.DisplayName);

                            using (CoreServiceAgent coreAgent = new CoreServiceAgent())
                            using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent())
                            using (GuideServiceAgent tvGuideAgent = new GuideServiceAgent())
                            {
                                bool epgSyncAutoCreateChannels = Convert.ToBoolean(layer.GetSetting(SettingName.EpgSyncAutoCreateChannels, false.ToString()).Value);
                                bool epgSyncAutoCreateChannelsWithGroup = Convert.ToBoolean(layer.GetSetting(SettingName.EpgSyncAutoCreateChannelsWithGroup, false.ToString()).Value);
                                string epgLanguages = layer.GetSetting("epgLanguages").Value;

                                Channel channel = EnsureChannelForDvbEpg(tvSchedulerAgent, mpChannel, epgSyncAutoCreateChannels, epgSyncAutoCreateChannelsWithGroup);
                                if (channel != null)
                                {
                                    EnsureGuideChannelForDvbEpg(tvSchedulerAgent, tvGuideAgent, channel, mpChannel);

                                    List<GuideProgram> guidePrograms = new List<GuideProgram>();

                                    foreach (EpgProgram epgProgram in epgChannel.Programs)
                                    {
                                        string title;
                                        string description;
                                        string genre;
                                        int starRating;
                                        string classification;
                                        int parentalRating;
                                        GetProgramInfoForLanguage(epgProgram.Text, epgLanguages, out title, out description, out genre,
                                            out starRating, out classification, out parentalRating);

                                        if (!String.IsNullOrEmpty(title))
                                        {
                                            GuideProgram guideProgram = new GuideProgram();
                                            guideProgram.GuideChannelId = channel.GuideChannelId.Value;
                                            guideProgram.StartTime = epgProgram.StartTime;
                                            guideProgram.StopTime = epgProgram.EndTime;
                                            guideProgram.StartTimeUtc = epgProgram.StartTime.ToUniversalTime();
                                            guideProgram.StopTime = epgProgram.EndTime;
                                            guideProgram.StopTimeUtc = epgProgram.EndTime.ToUniversalTime();
                                            guideProgram.Title = title;
                                            guideProgram.Description = description;
                                            guideProgram.Category = genre;
                                            guideProgram.Rating = classification;
                                            guideProgram.StarRating = starRating / 7.0;
                                            guidePrograms.Add(guideProgram);
                                        }
                                    }

                                    _dvbEpgThread.ImportProgramsAsync(guidePrograms);
                                }
                                else
                                {
                                    Log.Info("ArgusTV.Recorder.MediaPortalTvServer: ImportEpgPrograms() failed to ensure channel.");
                                }
                            }
                        }
                        else
                        {
                            Log.Info("ArgusTV.Recorder.MediaPortalTvServer: ImportEpgPrograms() failed to find MP channel.");
                        }
                    }
                }
            }
        }
Example #7
0
        public static void KeepImportServiceAlive()
        {
            try
            {
                Debug.WriteLine(String.Format("{0:HH:mm:ss} - KeepImportServiceAlive called", DateTime.Now));

                // Inform the local system we need it.
                SetThreadExecutionState(EXECUTION_STATE.ES_SYSTEM_REQUIRED);

                // Tell the server we still need it.
                using (CoreServiceAgent coreServiceAgent = new CoreServiceAgent())
                {
                    coreServiceAgent.KeepServerAlive();
                }
            }
            catch { }
        }
        public void StartListener()
        {
            if (PluginMain.IsConnected())
            {
                int _port = GetFreeTcpPort(49800);
                if (_port == -1)
                {
                    Log.Error("EventListener: No free port found!");
                    return;
                }

                _serviceUrl = "net.tcp://" + Dns.GetHostName() + ":" + _port + "/MpClient/";
                StopListener();

                Log.Debug("EventListener: start()");
                _serviceHost = CreateServiceHost(_serviceUrl);
                _serviceHost.Open();

                _started = true;
                try
                {
                    using (CoreServiceAgent agent = new CoreServiceAgent())
                    {
                        agent.EnsureEventListener(EventGroup.RecordingEvents | EventGroup.ScheduleEvents, _serviceUrl, Constants.EventListenerApiVersion);
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("EventListener: StartListener() error = {0}", ex.Message);
                    _started = false;
                }
            }
        }
        public void StopListener()
        {
            if (PluginMain.IsConnected())
            {
                Log.Debug("EventListener: stop()");
                try
                {
                    using (CoreServiceAgent agent = new CoreServiceAgent())
                    {
                        agent.RemoveEventListener(_serviceUrl);
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("EventListener: StopListener() error = {0}", ex.Message);
                }

                if (_serviceHost != null)
                {
                    _serviceHost.Close();
                }
                _started = false;
            }
        }
 private static void DoKeepAlive()
 {
     try
     {
         // Inform the local system we need it.
         SetThreadExecutionState(EXECUTION_STATE.ES_SYSTEM_REQUIRED);
         // Tell the server we need it.
         using (CoreServiceAgent coreAgent = new CoreServiceAgent())
         {
             coreAgent.KeepServerAlive();
         }
     }
     catch { }
 }
        private void ImportEpgPrograms(EpgChannel epgChannel)
        {
            if (!this.IsArgusTVConnectionInitialized)
            {
                InitializeArgusTVConnection(null);
            }
            if (this.IsArgusTVConnectionInitialized)
            {
                TvDatabase.TvBusinessLayer layer = new TvDatabase.TvBusinessLayer();
                bool epgSyncOn = Convert.ToBoolean(layer.GetSetting(SettingName.EpgSyncOn, false.ToString()).Value);
                if (epgSyncOn)
                {
                    DVBBaseChannel dvbChannel = epgChannel.Channel as DVBBaseChannel;
                    if (dvbChannel != null)
                    {
                        TvDatabase.Channel mpChannel = layer.GetChannelByTuningDetail(dvbChannel.NetworkId, dvbChannel.TransportId, dvbChannel.ServiceId);
                        if (mpChannel != null)
                        {
                            Log.Debug("ArgusTV.Recorder.MediaPortalTvServer: ImportEpgPrograms(): received {0} programs on {1}", epgChannel.Programs.Count, mpChannel.DisplayName);

                            using (CoreServiceAgent coreAgent = new CoreServiceAgent())
                                using (SchedulerServiceAgent tvSchedulerAgent = new SchedulerServiceAgent())
                                    using (GuideServiceAgent tvGuideAgent = new GuideServiceAgent())
                                    {
                                        bool   epgSyncAutoCreateChannels          = Convert.ToBoolean(layer.GetSetting(SettingName.EpgSyncAutoCreateChannels, false.ToString()).Value);
                                        bool   epgSyncAutoCreateChannelsWithGroup = Convert.ToBoolean(layer.GetSetting(SettingName.EpgSyncAutoCreateChannelsWithGroup, false.ToString()).Value);
                                        string epgLanguages = layer.GetSetting("epgLanguages").Value;

                                        Channel channel = EnsureChannelForDvbEpg(tvSchedulerAgent, mpChannel, epgSyncAutoCreateChannels, epgSyncAutoCreateChannelsWithGroup);
                                        if (channel != null)
                                        {
                                            EnsureGuideChannelForDvbEpg(tvSchedulerAgent, tvGuideAgent, channel, mpChannel);

                                            List <GuideProgram> guidePrograms = new List <GuideProgram>();

                                            foreach (EpgProgram epgProgram in epgChannel.Programs)
                                            {
                                                string title;
                                                string description;
                                                string genre;
                                                int    starRating;
                                                string classification;
                                                int    parentalRating;
                                                GetProgramInfoForLanguage(epgProgram.Text, epgLanguages, out title, out description, out genre,
                                                                          out starRating, out classification, out parentalRating);

                                                if (!String.IsNullOrEmpty(title))
                                                {
                                                    GuideProgram guideProgram = new GuideProgram();
                                                    guideProgram.GuideChannelId = channel.GuideChannelId.Value;
                                                    guideProgram.StartTime      = epgProgram.StartTime;
                                                    guideProgram.StopTime       = epgProgram.EndTime;
                                                    guideProgram.StartTimeUtc   = epgProgram.StartTime.ToUniversalTime();
                                                    guideProgram.StopTime       = epgProgram.EndTime;
                                                    guideProgram.StopTimeUtc    = epgProgram.EndTime.ToUniversalTime();
                                                    guideProgram.Title          = title;
                                                    guideProgram.Description    = description;
                                                    guideProgram.Category       = genre;
                                                    guideProgram.Rating         = classification;
                                                    guideProgram.StarRating     = starRating / 7.0;
                                                    guidePrograms.Add(guideProgram);
                                                }
                                            }

                                            _dvbEpgThread.ImportProgramsAsync(guidePrograms);
                                        }
                                        else
                                        {
                                            Log.Info("ArgusTV.Recorder.MediaPortalTvServer: ImportEpgPrograms() failed to ensure channel.");
                                        }
                                    }
                        }
                        else
                        {
                            Log.Info("ArgusTV.Recorder.MediaPortalTvServer: ImportEpgPrograms() failed to find MP channel.");
                        }
                    }
                }
            }
        }
Example #12
0
 private void _exitToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (this.IsConnected
         && this.ServiceTransport == ServiceTransport.NetTcp)
     {
         try
         {
             using (CoreServiceAgent coreAgent = new CoreServiceAgent())
             {
                 coreAgent.RemoveEventListener(_eventsServiceBaseUrl);
             }
         }
         catch
         {
         }
     }
     Application.Exit();
 }
Example #13
0
        private void _connectionBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            bool retryTcpConnection =
                (this.ServiceTransport == ServiceTransport.BinaryHttps
                && !String.IsNullOrEmpty(Config.Current.TcpServerName)
                && DateTime.Now > _nextTcpConnectionAttemptTime);
            if (!this.IsConnected
                || retryTcpConnection)
            {
                e.Result = false;

                try
                {
                    if (!String.IsNullOrEmpty(Config.Current.TcpServerName))
                    {
                        ServerSettings serverSettings = new ServerSettings();
                        serverSettings.ServerName = Config.Current.TcpServerName;
                        serverSettings.Port = Config.Current.TcpPort;
                        serverSettings.Transport = ServiceTransport.NetTcp;

                        ServiceChannelFactories.Initialize(serverSettings, true);

                        using (CoreServiceAgent coreAgent = new CoreServiceAgent())
                        {
                            coreAgent.EnsureEventListener(EventGroup.RecordingEvents, _eventsServiceBaseUrl, Constants.EventListenerApiVersion);
                        }
                        lock (_connectionLock)
                        {
                            _serviceTransport = serverSettings.Transport;
                            _isConnected = true;
                        }
                        _nextTcpConnectionAttemptTime = DateTime.MaxValue;
                        e.Result = true;
                    }
                    else
                    {
                        ConnectOverHttps();
                        e.Result = true;
                    }
                }
                catch
                {
                    try
                    {
                        ConnectOverHttps();
                        e.Result = true;
                    }
                    catch
                    {
                        this.IsConnected = false;
                    }
                }
            }
            else
            {
                e.Result = this.IsConnected;
            }
        }
Example #14
0
        private void EnsureEventsListenerService()
        {
            if (_eventsServiceHost == null)
            {
                try
                {
                    string eventsServiceBaseUrl = String.Format(CultureInfo.InvariantCulture, "net.tcp://localhost:{0}/ArgusTV.Messenger/", Properties.Settings.Default.EventsTcpPort);

                    EventsListenerService.OnUpcomingAlertsChanged += new EventHandler(EventsListenerService_OnUpcomingAlertsChanged);
                    EventsListenerService.OnRecordingStarted += new EventsListenerService.RecordingEventDelegate(EventsListenerService_OnRecordingStarted);
                    EventsListenerService.OnRecordingEnded += new EventsListenerService.RecordingEventDelegate(EventsListenerService_OnRecordingEnded);
                    EventsListenerService.OnConfigurationChanged += new EventsListenerService.ConfigurationChangedDelegate(EventsListenerService_OnConfigurationChanged);
                    EventsListenerService.OnLiveStreamStarted += new EventsListenerService.StreamingEventDelegate(EventsListenerService_OnLiveStreamChanged);
                    EventsListenerService.OnLiveStreamTuned += new EventsListenerService.StreamingEventDelegate(EventsListenerService_OnLiveStreamChanged);
                    EventsListenerService.OnLiveStreamEnded += new EventsListenerService.StreamingEventDelegate(EventsListenerService_OnLiveStreamChanged);
                    EventsListenerService.OnUpcomingRecordingsChanged += new EventHandler(EventsListenerService_OnUpcomingRecordingsChanged);

                    _eventsServiceHost = EventsListenerService.CreateServiceHost(eventsServiceBaseUrl);
                    _eventsServiceHost.Open();

                    using (CoreServiceAgent systemAgent = new CoreServiceAgent())
                    {
                        systemAgent.EnsureEventListener(
                            EventGroup.RecordingEvents | EventGroup.ScheduleEvents | EventGroup.SystemEvents,
                            eventsServiceBaseUrl, Constants.EventListenerApiVersion);
                    }
                }
                catch
                {
                    if (_eventsServiceHost != null
                        && _eventsServiceHost.State == CommunicationState.Opened)
                    {
                        _eventsServiceHost.Close();
                    }
                    _eventsServiceHost = null;
                }
            }
        }