public static ConnectEngineToGUI ( ) : void | ||
Результат | void |
public static void ReconnectEngineToGUI() { Trace.Call(); Frontend.DisconnectEngineFromGUI(); _MainWindow.EngineManager.Reconnect(); Session = _MainWindow.EngineManager.Session; _UserConfig = _MainWindow.EngineManager.UserConfig; Frontend.ConnectEngineToGUI(); }
private void _OnUseLocalEngineButtonClicked(object obj, EventArgs args) { Trace.Call(obj, args); try { Gtk.MessageDialog md = new Gtk.MessageDialog(null, Gtk.DialogFlags.Modal, Gtk.MessageType.Warning, Gtk.ButtonsType.YesNo, _("Switching to local engine will disconnect you from the current engine!\n" + "Are you sure you want to do this?")); int result = md.Run(); md.Destroy(); if ((Gtk.ResponseType)result == Gtk.ResponseType.Yes) { Frontend.DisconnectEngineFromGUI(); Frontend.InitLocalEngine(); Frontend.ConnectEngineToGUI(); } } catch (Exception ex) { Frontend.ShowException(this, ex); } }
protected void OnUseLocalEngineActionActivated(object sender, EventArgs e) { Trace.Call(sender, e); try { var dialog = new Gtk.MessageDialog( Parent, Gtk.DialogFlags.Modal, Gtk.MessageType.Warning, Gtk.ButtonsType.YesNo, _("Switching to local engine will disconnect you from the current engine!\n" + "Are you sure you want to do this?") ); int result = dialog.Run(); dialog.Destroy(); if ((Gtk.ResponseType)result == Gtk.ResponseType.Yes) { Frontend.DisconnectEngineFromGUI(); Frontend.InitLocalEngine(); Frontend.ConnectEngineToGUI(); } } catch (Exception ex) { Frontend.ShowException(Parent, ex); } }
public static void ReconnectEngineToGUI(bool cleanly) { Trace.Call(cleanly); if (_InReconnectHandler) { #if LOG4NET _Logger.Debug("ReconnectEngineToGUI(): already in reconnect " + "handler, ignoring reconnect..."); #endif return; } _InReconnectHandler = true; var disconnectedEvent = new AutoResetEvent(false); ThreadPool.QueueUserWorkItem(delegate { try { // delay the disconnect to give the reconnect some extra // time as NetworkManager is not accurate about when the // network is really ready GLib.Timeout.Add(5 * 1000, delegate { Frontend.DisconnectEngineFromGUI(cleanly); disconnectedEvent.Set(); return(false); }); var successful = false; var attempt = 1; while (!successful) { Gtk.Application.Invoke(delegate { MainWindow.NetworkStatus = null; MainWindow.Status = String.Format( _("Reconnecting to engine... (attempt {0})"), attempt++ ); }); try { disconnectedEvent.WaitOne(); _MainWindow.EngineManager.Reconnect(); successful = true; } catch (Exception ex) { #if LOG4NET _Logger.Debug("ReconnectEngineToGUI(): Exception", ex); #endif disconnectedEvent.Set(); Thread.Sleep(30 * 1000); } } _UserConfig = _MainWindow.EngineManager.UserConfig; EngineAssemblyVersion = _MainWindow.EngineManager.EngineAssemblyVersion; EngineProtocolVersion = _MainWindow.EngineManager.EngineProtocolVersion; Session = _MainWindow.EngineManager.Session; Gtk.Application.Invoke(delegate { Frontend.ConnectEngineToGUI(); }); } catch (Exception ex) { Frontend.ShowException(ex); } finally { _InReconnectHandler = false; } }); }
private void _OnConnectButtonPressed() { if (_SelectedEngine == null || _SelectedEngine == String.Empty) { Gtk.MessageDialog md = new Gtk.MessageDialog(this, Gtk.DialogFlags.Modal, Gtk.MessageType.Error, Gtk.ButtonsType.Close, _("Please select an engine!")); md.Run(); md.Destroy(); // Re-run the Dialog Run(); return; } if (_SelectedEngine == "<" + _("Local Engine") + ">") { Frontend.InitLocalEngine(); Frontend.ConnectEngineToGUI(); Destroy(); return; } string engine = _SelectedEngine; try { _EngineManager.Connect(engine); var engineVersion = _EngineManager.EngineVersion; var frontendVersion = Frontend.Version; if ((engineVersion >= new Version("0.8") && engineVersion.Major != frontendVersion.Major) || (engineVersion < new Version("0.8") && (engineVersion.Major != frontendVersion.Major || engineVersion.Minor != frontendVersion.Minor))) { throw new ApplicationException(String.Format( _("Your frontend version ({0}) does not match the engine version ({1})!"), Frontend.Version, _EngineManager.EngineVersion)); } Frontend.Session = _EngineManager.Session; Frontend.UserConfig = _EngineManager.UserConfig; Frontend.EngineVersion = _EngineManager.EngineVersion; Frontend.ConnectEngineToGUI(); } catch (Exception ex) { #if LOG4NET _Logger.Error(ex); #endif // clean-up try { _EngineManager.Disconnect(); } catch (Exception disEx) { #if LOG4NET _Logger.Error(disEx); #endif } string error_msg = ex.Message + "\n"; if (ex.InnerException != null) { error_msg += " [" + ex.InnerException.Message + "]\n"; } string msg; msg = _("An error occurred while connecting to the engine!") + "\n\n"; msg += String.Format(_("Engine URL: {0}") + "\n", _EngineManager.EngineUrl); msg += String.Format(_("Error: {0}"), error_msg); Gtk.MessageDialog md = new Gtk.MessageDialog(this, Gtk.DialogFlags.Modal, Gtk.MessageType.Error, Gtk.ButtonsType.Close, msg); md.Run(); md.Destroy(); // Re-run the Dialog Run(); } }