static void Main() { try { bool firstInstance; using (Mutex singleInstanceMutex = new Mutex(true, _singleInstanceGuid, out firstInstance)) { if (firstInstance) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); int port = GetFreeTcpPort(Properties.Settings.Default.EventsNetTcpPort); string eventsServiceBaseUrl = String.Format(CultureInfo.InvariantCulture, "net.tcp://{0}:{1}/ArgusTV.UI.Notifier/", Dns.GetHostName(), port); // // Create the form *before* opening the host for the WCF thread synchronization context! // StatusForm form = new StatusForm(); form.EventsServiceBaseUrl = eventsServiceBaseUrl; ServiceHost recordingEventsHost = EventsListenerService.CreateServiceHost(eventsServiceBaseUrl); EventsListenerService.StatusForm = form; recordingEventsHost.Open(); try { Application.Run(form); } finally { recordingEventsHost.Close(); } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "ArgusTV.UI.Notifier", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
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; } } }