private bool SetAndConnectHttps(bool test) { try { Cursor.Current = Cursors.WaitCursor; ServerSettings serverSettings = new ServerSettings(); serverSettings.ServerName = _serverHttpsTextBox.Text.Trim(); if (!String.IsNullOrEmpty(serverSettings.ServerName)) { serverSettings.Port = (int)_portHttpsNumericUpDown.Value; serverSettings.UserName = _userNameTextBox.Text; serverSettings.Password = _passwordTextBox.Text; serverSettings.Transport = ServiceTransport.BinaryHttps; ServiceChannelFactories.Initialize(serverSettings, true); Config.Current.HttpsServerName = serverSettings.ServerName; Config.Current.HttpsPort = serverSettings.Port; Config.Current.UserName = serverSettings.UserName; Config.Current.Password = serverSettings.Password; Config.Current.MacAddresses = serverSettings.WakeOnLan.MacAddresses; Config.Current.IpAddress = serverSettings.WakeOnLan.IPAddress; } else { Config.Current.HttpsServerName = String.Empty; Config.Current.HttpsPort = ServerSettings.DefaultHttpsPort; Config.Current.UserName = String.Empty; Config.Current.Password = String.Empty; } return true; } catch (ArgusTVNotFoundException ex) { if (MessageBox.Show(this, ex.Message, null, test ? MessageBoxButtons.OK : MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK) { return !test; } } catch (Exception ex) { MessageBox.Show(this, "Failed to connect over HTTPS." + Environment.NewLine + Environment.NewLine + ex.Message, null, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } finally { Cursor.Current = Cursors.Default; } return false; }
protected internal ServerBase(EventHandler<DiagnosticsEventArgs> diagnosticsEventHandler, ServerSettings settings) : base(diagnosticsEventHandler, settings?.Name) { // Check settings if (settings == null) { TraceEvent(EventLevel.Critical, @"Settings are invalid."); throw new ArgumentException(@"Settings are invalid.", nameof(settings)); } // Initialize active tasks activeTasks = new LinkedList<KeyValuePair<Task<Boolean>, IServerRequestHandler>>(); // Initialize performance counters var counters = new Dictionary<String, PerformanceCounter>(); foreach (var counterConfiguration in settings.PerformanceCounters) { // Create instance of the counter var counter = new PerformanceCounter(counterConfiguration.Value.Category, counterConfiguration.Value.Name, false); // Add to the dictionary counters.Add(counterConfiguration.Key, counter); } PerformanceCounters = new ReadOnlyDictionary<String, PerformanceCounter>(counters); // Initialize performance counter activeTasksCounter = PerformanceCounters[@"ActiveTasks"]; // Initialize performance counter badRequestsPerSecondCounter = PerformanceCounters[@"BadRequestsPerSecond"]; // Initialize performance counter requestsPerSecondCounter = PerformanceCounters[@"RequestsPerSecond"]; // Initialize performance counter requestProcessingAverageBaseCounter = PerformanceCounters[@"RequestProcessingAverageBase"]; // Initialize performance counter requestProcessingAverageTimeCounter = PerformanceCounters[@"RequestProcessingAverageTime"]; }
protected internal ServerBase(EventHandler <DiagnosticsEventArgs> diagnosticsEventHandler, ServerSettings settings) : base(diagnosticsEventHandler, settings?.Name) { // Check settings if (settings == null) { TraceEvent(EventLevel.Critical, @"Settings are invalid."); throw new ArgumentException(@"Settings are invalid.", nameof(settings)); } // Initialize active tasks activeTasks = new LinkedList <KeyValuePair <Task <Boolean>, IServerRequestHandler> >(); // Initialize performance counters var counters = new Dictionary <String, PerformanceCounter>(); foreach (var counterConfiguration in settings.PerformanceCounters) { // Create instance of the counter var counter = new PerformanceCounter(counterConfiguration.Value.Category, counterConfiguration.Value.Name, false); // Add to the dictionary counters.Add(counterConfiguration.Key, counter); } PerformanceCounters = new ReadOnlyDictionary <String, PerformanceCounter>(counters); // Initialize performance counter activeTasksCounter = PerformanceCounters[@"ActiveTasks"]; // Initialize performance counter badRequestsPerSecondCounter = PerformanceCounters[@"BadRequestsPerSecond"]; // Initialize performance counter requestsPerSecondCounter = PerformanceCounters[@"RequestsPerSecond"]; // Initialize performance counter requestProcessingAverageBaseCounter = PerformanceCounters[@"RequestProcessingAverageBase"]; // Initialize performance counter requestProcessingAverageTimeCounter = PerformanceCounters[@"RequestProcessingAverageTime"]; }
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 SendWakeOnLan(object state) { SendWakeOnLanArgs args = state as SendWakeOnLanArgs; if (args != null && !String.IsNullOrEmpty(args.TcpServerName)) { ServerSettings serverSettings = new ServerSettings(); serverSettings.ServerName = args.TcpServerName; serverSettings.Port = args.TcpPort; serverSettings.Transport = ServiceTransport.NetTcp; serverSettings.WakeOnLan.IPAddress = args.IpAddress; serverSettings.WakeOnLan.MacAddresses = args.MacAddresses; serverSettings.WakeOnLan.Enabled = true; ServiceChannelFactories.Initialize(serverSettings, false); } }
private void ConnectOverHttps() { if (!String.IsNullOrEmpty(Config.Current.HttpsServerName)) { ServerSettings serverSettings = new ServerSettings(); serverSettings.ServerName = Config.Current.HttpsServerName; serverSettings.Port = Config.Current.HttpsPort; serverSettings.UserName = Config.Current.UserName; serverSettings.Password = Config.Current.Password; serverSettings.Transport = ServiceTransport.BinaryHttps; if (ServiceChannelFactories.Initialize(serverSettings, false)) { lock (_connectionLock) { _serviceTransport = serverSettings.Transport; _isConnected = true; _nextTcpConnectionAttemptTime = DateTime.Now.AddMinutes(_retryTcpConnectionMinutes); } } } }
private void InitializeServiceChannelFactories(string _forTheRecordServerName, int _forTheRecordPort) { int RetryDelay = 30000; //ms bool success = ServiceChannelFactories.IsInitialized; bool success_on_first_attempt = true; ServerSettings serverSettings = new ServerSettings(); serverSettings.ServerName = _forTheRecordServerName; serverSettings.Port = _forTheRecordPort; while (!success) { try { ServiceChannelFactories.Initialize(serverSettings, true); //string FTR_version = ForTheRecord.Entities.Constants.ProductVersion; if (success_on_first_attempt) { //Ftr2LoService._log.do_log(_modulename, (int)FTR2LO_log.LogLevel.INFO, "ServiceChannelFactories successfully initialized. For the Record Version: " + FTR_version); } else { //Ftr2LoService._log.do_log(_modulename, (int)FTR2LO_log.LogLevel.INFO, "ServiceChannelFactories are now initialized. For the Record Version: " + FTR_version); } success = true; } catch (ForTheRecordException) { success_on_first_attempt = false; //Ftr2LoService._log.do_log(_modulename, (int)FTR2LO_log.LogLevel.ERROR, ftrex.Message); //Ftr2LoService._log.do_log(_modulename, (int)FTR2LO_log.LogLevel.ERROR, "Retrying in " + (RetryDelay / 1000).ToString() + " seconds...."); System.Threading.Thread.Sleep(RetryDelay); } } }
private void EnsureArgusTVConnection() { if (!ServiceChannelFactories.IsInitialized) { ServerSettings serverSettings = new ServerSettings(); serverSettings.ServerName = Properties.Settings.Default.ArgusTVServerName; serverSettings.Transport = ServiceTransport.NetTcp; serverSettings.Port = Properties.Settings.Default.ArgusTVTcpPort; try { ServiceChannelFactories.Initialize(serverSettings, true); UpdateAlertMinutesSetting(); } catch (ArgusTVNotFoundException ex) { Logger.Error(ex.ToString()); } catch (Exception ex) { Logger.Error("Failed to connect to ARGUS TV: " + ex.Message); } } }
public TestServer(EventHandler <DiagnosticsEventArgs> diagnosticsEventHandler, ServerSettings settings) : base(diagnosticsEventHandler, settings) { Assert.AreEqual(EntityState.Creating, State); State = EntityState.Inactive; }