public static bool InitialiseServerSettings(ServerSettings serverSettings, out string errorMessage) { errorMessage = string.Empty; bool succeeded = true; string _settingSection = PluginMain._settingSection; try { ServiceChannelFactories.Initialize(serverSettings, true); using (Settings xmlwriter = new MPSettings()) { xmlwriter.SetValue(_settingSection, TvHome.SettingName.MacAddresses, serverSettings.WakeOnLan.MacAddresses); xmlwriter.SetValue(_settingSection, TvHome.SettingName.IPAddress, serverSettings.WakeOnLan.IPAddress); xmlwriter.SetValueAsBool(_settingSection, TvHome.SettingName.IsSingleSeat, IsThisASingleSeatSetup(serverSettings.ServerName)); } } catch (ArgusTVNotFoundException ex) { errorMessage = ex.Message; succeeded = false; } catch (Exception ex) { errorMessage = ex.Message; succeeded = false; } return(succeeded); }
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 static void InitializeServiceChannelFactories() { ServerSettings serverSettings = new ServerSettings(); serverSettings.ServerName = Properties.Settings.Default.ArgusTVServerName; serverSettings.Port = Properties.Settings.Default.ArgusTVPort; ServiceChannelFactories.Initialize(serverSettings, false); }
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); }
private static void InitializeArgusTVServiceChannelFactories(out string errorMessage) { try { errorMessage = null; ServerSettings serverSettings = new ServerSettings(); serverSettings.ServerName = Properties.Settings.Default.ArgusTVServerName; serverSettings.Transport = ServiceTransport.NetTcp; serverSettings.Port = Properties.Settings.Default.ArgusTVPort; ServiceChannelFactories.Initialize(serverSettings, true); } catch (Exception ex) { errorMessage = ex.Message; } }
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); } }
internal bool InitializeArgusTVConnection(IWin32Window settingsPanel) { try { ServiceChannelFactories.Initialize(_serverSettings, true); } catch (Exception ex) { if (settingsPanel != null) { MessageBox.Show(settingsPanel, ex.Message, null, MessageBoxButtons.OK, MessageBoxIcon.Error); } else { Log.Error("ArgusTV.Recorder.MediaPortalTvServer: InitializeArgusTVConnection(): {0}", ex.Message); } return(false); } return(true); }
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); } } }
private bool TestConnection() { try { Cursor.Current = Cursors.WaitCursor; _serverSettings.ServerName = _serverTextBox.Text.Trim(); _serverSettings.Transport = ServiceTransport.NetTcp; _serverSettings.Port = (int)_portNumericUpDown.Value; _serverSettings.WakeOnLan.Enabled = _useWolCheckBox.Checked; _serverSettings.WakeOnLan.TimeoutSeconds = (int)_wolSecondsNumericUpDown.Value; ServiceChannelFactories.Initialize(_serverSettings, true); _isSingleSeat = Utility.IsThisASingleSeatSetup(_serverSettings.ServerName); return(true); } catch (Exception ex) { MessageBox.Show(this, ex.Message, Utility.GetLocalizedText(TextId.Error), MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { Cursor.Current = Cursors.Default; } return(false); }