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