/// <summary> /// Initialize the ArgusTV ServiceChannelFactories /// </summary> private void InitializeServiceChannelFactories() { _logger.Info("[ArgusTV] Start InitializeServiceChannelFactories"); var config = Plugin.Instance.Configuration; var serverIp = config.ServerIp; var serverPort = config.ServerPort; try { var serverSettings = new ServerSettings { ServerName = serverIp, Port = serverPort }; UtilsHelper.DebugInformation(_logger,string.Format("[ArgusTV] ServerSettings: {0}", _jsonSerializer.SerializeToString(serverSettings))); Proxies.Initialize(serverSettings); _logger.Info(string.Format("[ArgusTV] Successful initialized on server {0} with port {1}", serverIp, serverPort)); } catch (Exception ex) { _logger.ErrorException("[ArgusTV] It's not possible to initialize a connection to the ArgusTV Server on server {0} with port {1}", ex, serverIp, serverPort); } }
public static void EnsureServerAwake(ServerSettings serverSettings) { // Check if wake-on-lan is turned on and if the server does *not* respond to a ping. // In that case we will try to wake it up. if (serverSettings.WakeOnLan.Enabled && !String.IsNullOrEmpty(serverSettings.WakeOnLan.MacAddresses) && !String.IsNullOrEmpty(serverSettings.WakeOnLan.IPAddress) && !Ping(serverSettings.WakeOnLan.IPAddress)) { string[] macAddresses = serverSettings.WakeOnLan.MacAddresses.Split(';'); if (WakeUp(macAddresses, serverSettings.WakeOnLan.IPAddress, serverSettings.WakeOnLan.TimeoutSeconds)) { // Wait one additional second after a successful ping. System.Threading.Thread.Sleep(1000); } } }
public void SetupFTRConnection(Object state, ElapsedEventArgs eventArgs) { try { if (Proxies.IsInitialized) { if (Proxies.CoreService.Ping(Constants.RestApiVersion).Result > 0) { log.Debug("Ping"); } return; } log.Debug("Trying to connect to Argus TV"); ArgusTV.ServiceProxy.ServerSettings serverSettings = GetServerSettings(); if (Proxies.Initialize(serverSettings)) { Proxies.LogService.LogMessage(MODULE, LogSeverity.Information, "GuideEnricher successfully connected"); log.Info("Successfully connected to Argus TV"); } else { log.Fatal("Unable to connect to Argus TV, check your settings. Will try again later"); } } catch (ArgusTV.ServiceProxy.ArgusTVNotFoundException notFoundException) { log.Error(notFoundException.Message); } catch (EndpointNotFoundException) { log.Error("Connection to Argus TV lost, make sure the Argus TV service is running"); } catch (ArgusTVException ftrException) { log.Fatal(ftrException.Message); } finally { ftrConnectionTimer.Interval = TimeSpan.FromMinutes(1).TotalMilliseconds; ftrConnectionTimer.Start(); } }
public static ArgusTV.ServiceProxy.ServerSettings GetServerSettings() { var serverSettings = new ArgusTV.ServiceProxy.ServerSettings(); serverSettings.ServerName = config.GetProperty("ftrUrlHost"); serverSettings.Transport = ArgusTV.ServiceProxy.ServiceTransport.Http; serverSettings.Port = Convert.ToInt32(config.GetProperty("ftrUrlPort")); var password = config.GetProperty("ftrUrlPassword"); var userName = config.GetProperty("ftrUserName"); if (!string.IsNullOrEmpty(userName)) { serverSettings.UserName = userName; } if (!string.IsNullOrEmpty(password)) { serverSettings.Password = password; } return(serverSettings); }
public static bool InitialiseServerSettings(ServerSettings serverSettings, out string errorMessage) { errorMessage = string.Empty; bool succeeded = true; string _settingSection = PluginMain._settingSection; try { Proxies.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; }
ServerSettings GetServerSettings() { var serverSettings = new ServerSettings(); serverSettings.ServerName = _configuration.GetProperty("ftrUrlHost"); serverSettings.Port = Convert.ToInt32(_configuration.GetProperty("ftrUrlPort")); var password = _configuration.GetProperty("ftrUrlPassword"); var userName = _configuration.GetProperty("ftrUserName"); if (!string.IsNullOrEmpty(userName)) { serverSettings.UserName = userName; } if (!string.IsNullOrEmpty(password)) { serverSettings.Password = password; } return serverSettings; }
private async Task <bool> InternalInitialize(ServerSettings serverSettings, bool throwError, IServiceProxyLogger logger, SourceLevels logLevel = SourceLevels.Error) #endif { #if DOTNET4 lock (Instance._syncLock) #else using (await _asyncLock.LockAsync().ConfigureAwait(false)) #endif { ServerSettings previousServerSettings = _serverSettings; bool previousIsInitialized = _isInitialized; IServiceProxyLogger previousLogger = _logger; try { _isInitialized = false; _serverSettings = serverSettings; _logger = logger ?? new DefaultLogger(); WakeOnLan.EnsureServerAwake(serverSettings); DateTime firstTryTime = DateTime.Now; for (; ;) { try { #if DOTNET4 PingAndCheckServer(serverSettings).Wait(); #else await PingAndCheckServer(serverSettings).ConfigureAwait(false); #endif break; } catch { TimeSpan span = DateTime.Now - firstTryTime; if (!serverSettings.WakeOnLan.Enabled || span.TotalSeconds >= serverSettings.WakeOnLan.TimeoutSeconds) { throw; } System.Threading.Thread.Sleep(1000); } } } catch { _serverSettings = previousServerSettings; _logger = previousLogger; _isInitialized = previousIsInitialized; if (!throwError) { return(false); } throw; } ResetProxies(); _isInitialized = true; return(true); } }
/// <summary> /// Initialize the proxies for the given server settings. /// </summary> /// <param name="serverSettings">Where to locate the ARGUS TV Scheduler service.</param> /// <param name="throwError">If set to true an exception may be thrown, if false any errors will be swallowed.</param> /// <param name="logger">An optional logger that should be thread-safe and that will be used to log any errors that occur in the proxy.</param> /// <param name="logLevel">The optional logging level, currently ignored and always set to the default of Error.</param> /// <returns>If throwError was false, a boolean indicating success or failure.</returns> public static async Task <bool> InitializeAsync(ServerSettings serverSettings, bool throwError = true, IServiceProxyLogger logger = null, SourceLevels logLevel = SourceLevels.Error) { return(await Proxies.Instance.InternalInitialize(serverSettings, throwError, logger, logLevel).ConfigureAwait(false)); }
/// <summary> /// Initialize the proxies for the given server settings. /// </summary> /// <param name="serverSettings">Where to locate the ARGUS TV Scheduler service.</param> /// <param name="throwError">If set to true an exception may be thrown, if false any errors will be swallowed.</param> /// <param name="logger">An optional logger that should be thread-safe and that will be used to log any errors that occur in the proxy.</param> /// <param name="logLevel">The optional logging level, currently ignored and always set to the default of Error.</param> /// <returns>If throwError was false, a boolean indicating success or failure.</returns> public static bool Initialize(ServerSettings serverSettings, bool throwError = true, IServiceProxyLogger logger = null, SourceLevels logLevel = SourceLevels.Error) { #if DOTNET4 return Proxies.Instance.InternalInitialize(serverSettings, throwError, logger, logLevel); #else return Proxies.Instance.InternalInitialize(serverSettings, throwError, logger, logLevel).Result; #endif }
/// <summary> /// Clone the server settings. /// </summary> /// <returns>A new server settings instance.</returns> public object Clone() { ServerSettings serverSettings = new ServerSettings(); serverSettings.Transport = this.Transport; serverSettings.ServerName = this.ServerName; serverSettings.Port = this.Port; serverSettings.UserName = this.UserName; serverSettings.Password = this.Password; serverSettings.WakeOnLan.Enabled = this.WakeOnLan.Enabled; serverSettings.WakeOnLan.IPAddress = this.WakeOnLan.IPAddress; serverSettings.WakeOnLan.MacAddresses = this.WakeOnLan.MacAddresses; serverSettings.WakeOnLan.TimeoutSeconds = this.WakeOnLan.TimeoutSeconds; return serverSettings; }
private static void InitializeServiceChannelFactories() { ServerSettings serverSettings = new ServerSettings(); serverSettings.ServerName = Properties.Settings.Default.ArgusTVServerName; serverSettings.Port = Properties.Settings.Default.ArgusTVPort; Proxies.Initialize(serverSettings, false); }
private bool SetAndConnect(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.Transport = ServiceTransport.Https; serverSettings.UserName = _userNameTextBox.Text; serverSettings.Password = _passwordTextBox.Text; #if DEBUG if (serverSettings.ServerName == "localhost") { serverSettings.Port += 2; serverSettings.Transport = ServiceTransport.Http; } #endif Proxies.Initialize(serverSettings, true); Config.Current.ServerName = serverSettings.ServerName; Config.Current.Port = serverSettings.Port; Config.Current.MacAddresses = serverSettings.WakeOnLan.MacAddresses; Config.Current.IpAddress = serverSettings.WakeOnLan.IPAddress; Config.Current.UserName = serverSettings.UserName; Config.Current.Password = serverSettings.Password; } else { Config.Current.ServerName = String.Empty; Config.Current.Port = ServerSettings.DefaultHttpsPort; } 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 to ARGUS TV." + Environment.NewLine + Environment.NewLine + ex.Message, null, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } finally { Cursor.Current = Cursors.Default; } return false; }
public static ArgusTV.ServiceProxy.ServerSettings GetServerSettings() { var serverSettings = new ArgusTV.ServiceProxy.ServerSettings(); serverSettings.ServerName = config.GetProperty("ftrUrlHost"); serverSettings.Transport = ArgusTV.ServiceProxy.ServiceTransport.Http; serverSettings.Port = Convert.ToInt32(config.GetProperty("ftrUrlPort")); var password = config.GetProperty("ftrUrlPassword"); var userName = config.GetProperty("ftrUserName"); if (!string.IsNullOrEmpty(userName)) { serverSettings.UserName = userName; } if (!string.IsNullOrEmpty(password)) { serverSettings.Password = password; } return serverSettings; }
internal static ServerSettings LoadServerSettings() { using (Settings xmlreader = new MPSettings()) { ServerSettings serverSettings = new ServerSettings(); serverSettings.ServerName = xmlreader.GetValueAsString(_settingSection, TvHome.SettingName.Server, "localhost"); #if DEBUG if (!Dns.GetHostName().Equals("tcf") && !Dns.GetHostName().Equals("Iznajar")) { serverSettings.ServerName = "mediaserver"; } #endif serverSettings.Port = xmlreader.GetValueAsInt(_settingSection, TvHome.SettingName.TcpPort, ServerSettings.DefaultHttpPort); if (serverSettings.Port == 49942) { // Auto-adjust old net.tcp port to HTTP. serverSettings.Port = 49943; } serverSettings.WakeOnLan.MacAddresses = xmlreader.GetValueAsString(_settingSection, TvHome.SettingName.MacAddresses, String.Empty); serverSettings.WakeOnLan.IPAddress = xmlreader.GetValueAsString(_settingSection, TvHome.SettingName.IPAddress, String.Empty); serverSettings.WakeOnLan.Enabled = xmlreader.GetValueAsBool(_settingSection, TvHome.SettingName.UseWakeOnLan, false); serverSettings.WakeOnLan.TimeoutSeconds = xmlreader.GetValueAsInt(_settingSection, TvHome.SettingName.WakeOnLanTimeoutSeconds, 10); return serverSettings; } }
private async void InitializeConnectionToArgusTV() { if (!String.IsNullOrEmpty(Config.Current.ServerName)) { ServerSettings serverSettings = new ServerSettings(); serverSettings.ServerName = Config.Current.ServerName; serverSettings.Port = Config.Current.Port; serverSettings.UserName = Config.Current.UserName; serverSettings.Password = Config.Current.Password; serverSettings.Transport = ServiceTransport.Https; this.IsConnected = await Proxies.InitializeAsync(serverSettings, false, new ProxyLogger()); if (this.IsConnected) { SetStatusIcon(ServerStatus.Idle); } else { SetStatusIcon(ServerStatus.NotConnected); } } }
private void SendWakeOnLan(object state) { SendWakeOnLanArgs args = state as SendWakeOnLanArgs; if (args != null && !String.IsNullOrEmpty(args.ServerName)) { ServerSettings serverSettings = new ServerSettings(); serverSettings.ServerName = args.ServerName; serverSettings.Port = args.Port; serverSettings.Transport = ServiceTransport.Https; serverSettings.UserName = args.UserName; serverSettings.Password = args.Password; serverSettings.WakeOnLan.IPAddress = args.IpAddress; serverSettings.WakeOnLan.MacAddresses = args.MacAddresses; serverSettings.WakeOnLan.Enabled = true; Proxies.Initialize(serverSettings, false, new ProxyLogger()); } }
/// <summary> /// Initialize the proxies for the given server settings. /// </summary> /// <param name="serverSettings">Where to locate the ARGUS TV Scheduler service.</param> /// <param name="throwError">If set to true an exception may be thrown, if false any errors will be swallowed.</param> /// <param name="logger">An optional logger that should be thread-safe and that will be used to log any errors that occur in the proxy.</param> /// <param name="logLevel">The optional logging level, currently ignored and always set to the default of Error.</param> /// <returns>If throwError was false, a boolean indicating success or failure.</returns> public static async Task<bool> InitializeAsync(ServerSettings serverSettings, bool throwError = true, IServiceProxyLogger logger = null, SourceLevels logLevel = SourceLevels.Error) { return await Proxies.Instance.InternalInitialize(serverSettings, throwError, logger, logLevel).ConfigureAwait(false); }
private bool InternalInitialize(ServerSettings serverSettings, bool throwError, IServiceProxyLogger logger, SourceLevels logLevel = SourceLevels.Error)
private bool InternalInitialize(ServerSettings serverSettings, bool throwError, IServiceProxyLogger logger, SourceLevels logLevel = SourceLevels.Error)
public ConnectionProfile(string name, ServerSettings serverSettings, bool savePassword) { this.Name = name; this.ServerSettings = serverSettings; this.SavePassword = savePassword; }
private async Task<bool> InternalInitialize(ServerSettings serverSettings, bool throwError, IServiceProxyLogger logger, SourceLevels logLevel = SourceLevels.Error) #endif { #if DOTNET4 lock (Instance._syncLock) #else using (await _asyncLock.LockAsync().ConfigureAwait(false)) #endif { ServerSettings previousServerSettings = _serverSettings; bool previousIsInitialized = _isInitialized; IServiceProxyLogger previousLogger = _logger; try { _isInitialized = false; _serverSettings = serverSettings; _logger = logger ?? new DefaultLogger(); WakeOnLan.EnsureServerAwake(serverSettings); DateTime firstTryTime = DateTime.Now; for (; ; ) { try { #if DOTNET4 PingAndCheckServer(serverSettings).Wait(); #else await PingAndCheckServer(serverSettings).ConfigureAwait(false); #endif break; } catch { TimeSpan span = DateTime.Now - firstTryTime; if (!serverSettings.WakeOnLan.Enabled || span.TotalSeconds >= serverSettings.WakeOnLan.TimeoutSeconds) { throw; } System.Threading.Thread.Sleep(1000); } } } catch { _serverSettings = previousServerSettings; _logger = previousLogger; _isInitialized = previousIsInitialized; if (!throwError) { return false; } throw; } ResetProxies(); _isInitialized = true; return true; } }
internal static bool InitializeConnectionToArgusTV() { ArgusTV.ServiceProxy.ServerSettings serverSettings = Service.GetServerSettings(); return(Proxies.Initialize(serverSettings, false)); }
private async Task PingAndCheckServer(ServerSettings serverSettings) { var proxy = new CoreServiceProxy(); int apiComparison; try { apiComparison = await proxy.Ping(Constants.RestApiVersion).ConfigureAwait(false); } catch (ArgusTVException ex) { throw new ArgusTVNotFoundException(ex, "'{0}:{1}' not found, is the service running?", serverSettings.ServerName, serverSettings.Port); } if (apiComparison < 0) { throw new ArgusTVException("ARGUS TV Recorder on server is more recent, upgrade client"); } else if (apiComparison > 0) { throw new ArgusTVException("ARGUS TV Recorder on server is too old, upgrade server"); } serverSettings.WakeOnLan.MacAddresses = String.Join(";", await proxy.GetMacAddresses().ConfigureAwait(false)); serverSettings.WakeOnLan.IPAddress = WakeOnLan.GetIPAddress(serverSettings.ServerName); }
private static void InitializeArgusTVServiceChannelFactories(out string errorMessage) { try { errorMessage = null; ServerSettings serverSettings = new ServerSettings(); serverSettings.ServerName = Properties.Settings.Default.ArgusTVServerName; serverSettings.Transport = ServiceTransport.Http; serverSettings.Port = Properties.Settings.Default.ArgusTVPort; Proxies.Initialize(serverSettings, true); } catch (Exception ex) { errorMessage = ex.Message; } }
static void Main(string[] args) { try { #if DEBUG Thread.Sleep(5000); _checkInterval = 3000; #endif if (args.Length == 8) { string playerExe = args[0]; bool isLiveStream = args[6] == "L"; string rtspUrl = args[7]; Process liveStreamPlayerProcess = null; if (rtspUrl.StartsWith("rtsp://")) { liveStreamPlayerProcess = new Process(); liveStreamPlayerProcess.StartInfo.FileName = playerExe; liveStreamPlayerProcess.StartInfo.Arguments = rtspUrl; liveStreamPlayerProcess.StartInfo.CreateNoWindow = true; liveStreamPlayerProcess.EnableRaisingEvents = true; liveStreamPlayerProcess.Exited += new EventHandler(livePlayerProcess_Exited); liveStreamPlayerProcess.Start(); } ServerSettings serverSettings = new ServerSettings(); serverSettings.ServerName = args[1]; serverSettings.Port = Int32.Parse(args[2]); serverSettings.Transport = (ServiceTransport)Enum.Parse(typeof(ServiceTransport), args[3]); serverSettings.UserName = args[4]; serverSettings.Password = args[5]; Proxies.Initialize(serverSettings, false); if (Proxies.IsInitialized) { if (isLiveStream) { PlayLiveStream(rtspUrl, liveStreamPlayerProcess); } else { PlayRecordingStream(rtspUrl, liveStreamPlayerProcess); } } else { MessageBox.Show("Unable to connect to the ARGUS TV Scheduler service!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (liveStreamPlayerProcess != null && !liveStreamPlayerProcess.HasExited) { liveStreamPlayerProcess.CloseMainWindow(); liveStreamPlayerProcess.WaitForExit(1000); if (!liveStreamPlayerProcess.HasExited) { liveStreamPlayerProcess.Kill(); } } } } catch (Exception ex) { MessageBox.Show(ex.Message, null, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { _playerExitedEvent.Close(); } }
private void EnsureArgusTVConnection() { if (!Proxies.IsInitialized) { ServerSettings serverSettings = new ServerSettings(); serverSettings.ServerName = Properties.Settings.Default.ArgusTVServerName; serverSettings.Transport = ServiceTransport.Http; serverSettings.Port = Properties.Settings.Default.ArgusTVHttpPort; try { Proxies.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 void LoadSettings(bool onlyServerSettings) { _serverSettings = PluginMain.LoadServerSettings(); int timeout = _serverSettings.WakeOnLan.TimeoutSeconds; bool valueFoundInList = false; for (int i = 0; i <= 100; i++) { _WolTimeoutButton.AddSpinLabel(i.ToString(), 0); if (i == timeout) valueFoundInList = true; } if (valueFoundInList) { _WolTimeoutButton.SpinValue = timeout; } else { _WolTimeoutButton.AddSpinLabel(timeout.ToString(), 0); _WolTimeoutButton.SpinValue = _WolTimeoutButton.SpinMaxValue() - 1; } _serverNameButton.Label = _serverSettings.ServerName; _tcpPortButton.Label = _serverSettings.Port.ToString(); _enableWolButton.Selected = _serverSettings.WakeOnLan.Enabled; if (!onlyServerSettings) { _standbyOnHomeButton.Selected = PluginMain.NoClientStandbyWhenNotHome; _autoStreamingButton.Selected = PluginMain.AutoStreamingMode; _rtspStreamingTVButton.Selected = PluginMain.PreferRtspForLiveTv; _rtspStreamingRecButton.Selected = PluginMain.PlayRecordingsOverRtsp; using (Settings xmlreader = new MPSettings()) { _recordingNotificationButton.Selected = xmlreader.GetValueAsBool("mytv", "enableRecNotifier", false); _autoFullScreenButton.Selected = xmlreader.GetValueAsBool("mytv", "autofullscreen", true); _showChannelNumbersButton.Selected = xmlreader.GetValueAsBool("mytv", "showchannelnumber", false); _hideAllChannelsGroupButton.Selected = xmlreader.GetValueAsBool("mytv", "hideAllChannelsGroup", false); _dvbSubtitlesButton.Selected = xmlreader.GetValueAsBool("tvservice", "dvbbitmapsubtitles", false); _teletextSubtitleButton.Selected = xmlreader.GetValueAsBool("tvservice", "dvbttxtsubtitles", false); _preferAC3Button.Selected = xmlreader.GetValueAsBool("tvservice", "preferac3", false); } } }