/// <summary> /// Try to connect to the core service, if not connected. /// </summary> /// <param name="showHomeOnError"></param> /// <param name="schowError"></param> /// <returns></returns> internal static bool EnsureConnection(bool showHomeOnError, bool schowError) { if (!Proxies.IsInitialized) { bool succeeded = false; string errorMessage = string.Empty; ServerSettings serverSettings = LoadServerSettings(); if (IsSingleSeat) { StartServices(serverSettings.ServerName); } /*else * { * if (!NetworkAvailable) * { * if (((showHomeOnError || !_connectionErrorShown) * && GUIWindowManager.ActiveWindow != 0) && schowError) * { * GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK); * dlg.Reset(); * dlg.SetHeading(Utility.GetLocalizedText(TextId.Error)); * dlg.SetLine(1, "Failed to connect to ARGUS TV"); * dlg.SetLine(2, "No internet connection!"); * dlg.SetLine(3, ""); * dlg.DoModal(GUIWindowManager.ActiveWindow); * _connectionErrorShown = true; * } * * _connected = false; * return false; * } * }*/ succeeded = Utility.InitialiseServerSettings(serverSettings, out errorMessage); if (!succeeded && !IsSingleSeat) { StartServices(serverSettings.ServerName); succeeded = Utility.InitialiseServerSettings(serverSettings, out errorMessage); } if (!succeeded) { if (((showHomeOnError || !_connectionErrorShown) && GUIWindowManager.ActiveWindow != 0) && schowError) { GUIDialogOK dlg = (GUIDialogOK)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_OK); dlg.Reset(); dlg.SetHeading("Failed to connect to ARGUS TV"); dlg.SetLine(1, serverSettings.ServiceUrlPrefix); dlg.SetLine(2, errorMessage); dlg.SetLine(3, "Check plugin setup in Configuration"); dlg.DoModal(GUIWindowManager.ActiveWindow); _connectionErrorShown = true; } } } if (!Proxies.IsInitialized) { if (showHomeOnError && GUIWindowManager.ActiveWindow != 0) { using (Settings xmlreader = new MPSettings()) { bool _startWithBasicHome = xmlreader.GetValueAsBool("gui", "startbasichome", false); if (_startWithBasicHome && System.IO.File.Exists(GUIGraphicsContext.Skin + @"\basichome.xml")) { GUIWindowManager.ActivateWindow((int)GUIWindow.Window.WINDOW_SECOND_HOME); } else { GUIWindowManager.ActivateWindow((int)GUIWindow.Window.WINDOW_HOME); } } } _connected = false; return(false); } _connected = true; return(true); }
private bool TestConnection() { bool wasConnected = false; bool portChanged = false; bool serverChanged = false; string errorMessage = string.Empty; PluginMain.ForceNoConnection = true; if (ServiceChannelFactories.IsInitialized) { wasConnected = true; if (_serverNameButton.Label != ServiceChannelFactories.ServerSettings.ServerName) { serverChanged = true; } if (Int32.Parse(_tcpPortButton.Label) != ServiceChannelFactories.ServerSettings.Port) { portChanged = true; } } _serverSettings.ServerName = _serverNameButton.Label; _serverSettings.Transport = ServiceTransport.NetTcp; _serverSettings.Port = Int32.Parse(_tcpPortButton.Label); _serverSettings.WakeOnLan.Enabled = _enableWolButton.Selected; _serverSettings.WakeOnLan.TimeoutSeconds = Int32.Parse(_WolTimeoutButton.SpinLabel); _isSingleSeat = Utility.IsThisASingleSeatSetup(_serverSettings.ServerName); if (Utility.InitialiseServerSettings(_serverSettings, out errorMessage)) { GUIDialogOK pDlgOK = (GUIDialogOK)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_OK); if (pDlgOK != null) { pDlgOK.Reset(); pDlgOK.SetHeading(Utility.GetLocalizedText(TextId.Information)); pDlgOK.SetLine(1, Utility.GetLocalizedText(TextId.ConnectionSucceeded)); pDlgOK.SetLine(2, "Single seat:" + _isSingleSeat); pDlgOK.DoModal(this.GetID); } SaveSettings(true); PluginMain.ForceNoConnection = false; if (wasConnected && (serverChanged || portChanged)) { //we switched between 2 different servers, we suggest to restart mp. _mpRestartNeeded = true; } return(true); } else { if (wasConnected) { //load settings that worked before the test button was pressed. LoadSettings(true); UpdateButtons(); string error; if (Utility.InitialiseServerSettings(_serverSettings, out error)) { PluginMain.ForceNoConnection = false; } } GUIDialogOK pDlgOK = (GUIDialogOK)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_OK); if (pDlgOK != null) { pDlgOK.Reset(); pDlgOK.SetHeading(Utility.GetLocalizedText(TextId.Error)); pDlgOK.SetLine(1, Utility.GetLocalizedText(TextId.ConnectionFailed)); pDlgOK.SetLine(2, errorMessage); pDlgOK.DoModal(this.GetID); } } return(false); }