ReconnectEngineToGUI() public static method

public static ReconnectEngineToGUI ( ) : void
return void
Ejemplo n.º 1
0
        void OnStateChanged(State state)
        {
            Trace.Call(state);

            if (Frontend.Session == null)
            {
                return;
            }

            switch (state)
            {
            case State.Disconnected:
                if (!Frontend.IsLocalEngine)
                {
                    ChatViewManager.IsSensitive = false;
                }
                break;

            case State.Connected:
                if (Frontend.IsLocalEngine)
                {
                    // reconnect local protocol managers
                    foreach (var protocolManager in Frontend.Session.ProtocolManagers)
                    {
                        protocolManager.Reconnect(Frontend.FrontendManager);
                    }
                }
                else
                {
                    Frontend.ReconnectEngineToGUI();
                    ChatViewManager.IsSensitive = true;
                }
                break;
            }
        }
Ejemplo n.º 2
0
        void OnStateChanged(int state)
        {
            Trace.Call(state);

            if (!Frontend.HadSession)
            {
                return;
            }

            switch (state)
            {
            case (int)StateNM9.Disconnecting:
                if (!Frontend.IsLocalEngine)
                {
                    Frontend.DisconnectEngineFromGUI(true);
                }
                break;

            case (int)StateNM8.Disconnected:
            case (int)StateNM9.Disconnected:
                WasLocalEngine = Frontend.IsLocalEngine;
                if (!Frontend.IsLocalEngine)
                {
                    Frontend.DisconnectEngineFromGUI(false);
                }
                break;

            case (int)StateNM8.Connected:
            case (int)StateNM9.ConnectedSite:
            case (int)StateNM9.ConnectedGlobal:
                if (WasLocalEngine)
                {
                    // reconnect local protocol managers
                    foreach (var protocolManager in Frontend.Session.ProtocolManagers)
                    {
                        var pm = protocolManager;
                        // run in background so it can't block the GUI
                        ThreadPool.QueueUserWorkItem(delegate {
                            try {
                                pm.Reconnect(Frontend.FrontendManager);
                            } catch (Exception ex) {
                                Frontend.ShowException(ex);
                            }
                        });
                    }
                }
                else
                {
                    Frontend.ReconnectEngineToGUI(false);
                }
                break;
            }
        }
Ejemplo n.º 3
0
        public static bool ShowReconnectDialog(Gtk.Window parent)
        {
            Trace.Call(parent);

            Gtk.MessageDialog md = new Gtk.MessageDialog(parent,
                                                         Gtk.DialogFlags.Modal, Gtk.MessageType.Error,
                                                         Gtk.ButtonsType.OkCancel, _("The frontend has lost the connection to the server.\nDo you want to reconnect now?"));
            Gtk.ResponseType res = (Gtk.ResponseType)md.Run();
            md.Destroy();

            if (res != Gtk.ResponseType.Ok)
            {
                Quit();
                return(false);
            }

            while (true)
            {
                try {
                    Frontend.ReconnectEngineToGUI();
                    // yay, we made it
                    _InReconnectHandler = false;
                    break;
                } catch (Exception e) {
#if LOG4NET
                    _Logger.Error("ShowReconnectDialog(): Reconnect failed, exception:", e);
#endif
                    var msg = _("Reconnecting to the server has failed.\nDo you want to try again?");
                    // the parent window is hidden (MainWindow) at this
                    // point thus modal doesn't make sense here
                    md = new Gtk.MessageDialog(parent,
                                               Gtk.DialogFlags.DestroyWithParent,
                                               Gtk.MessageType.Error,
                                               Gtk.ButtonsType.OkCancel, msg);
                    md.SetPosition(Gtk.WindowPosition.CenterAlways);
                    res = (Gtk.ResponseType)md.Run();
                    md.Destroy();

                    if (res != Gtk.ResponseType.Ok)
                    {
                        // give up
                        Quit();
                        return(false);
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 4
0
        private static bool CheckFrontendManagerStatus()
        {
            Trace.Call();

            if (_FrontendManager == null)
            {
                // we lost the frontend manager, nothing to check
                return(false);
            }

            if (_FrontendManager.IsAlive)
            {
                // everything is fine
                return(true);
            }

#if LOG4NET
            _Logger.Error("CheckFrontendManagerStatus(): frontend manager is not alive anymore!");
#endif
            Gtk.Application.Invoke(delegate {
                Gtk.MessageDialog md = new Gtk.MessageDialog(_MainWindow,
                                                             Gtk.DialogFlags.Modal, Gtk.MessageType.Error,
                                                             Gtk.ButtonsType.OkCancel, _("The server has lost the connection to the frontend.\nDo you want to reconnect now?"));
                Gtk.ResponseType res = (Gtk.ResponseType)md.Run();
                md.Destroy();

                if (res != Gtk.ResponseType.Ok)
                {
                    // the frontend is unusable in this state -> say good bye
                    Frontend.Quit();
                    return;
                }

                Frontend.ReconnectEngineToGUI();
            });

            return(false);
        }
Ejemplo n.º 5
0
        public static void ShowException(Gtk.Window parent, Exception ex)
        {
            Trace.Call(parent, ex != null ? ex.GetType() : null);

            if (parent == null)
            {
                parent = _MainWindow;
            }

            if (!IsGuiThread())
            {
                Gtk.Application.Invoke(delegate {
                    ShowException(parent, ex);
                });
                return;
            }

            if (ex is NotImplementedException)
            {
                // don't quit on NotImplementedException
                ShowError(parent, ex);
                return;
            }

#if LOG4NET
            _Logger.Error("ShowException(): Exception:", ex);
#endif

            // HACK: ugly MS .NET throws underlaying SocketException instead of
            // wrapping those into a nice RemotingException, see:
            // http://projects.qnetp.net/issues/show/232
            if (ex is System.Runtime.Remoting.RemotingException ||
                ex is System.Net.Sockets.SocketException)
            {
                if (_InReconnectHandler || _InCrashHandler)
                {
                    // one reconnect is good enough and a crash we won't survive
                    return;
                }

                Frontend.ReconnectEngineToGUI();
                return;
            }

            if (_InCrashHandler)
            {
                // only show not more than one crash dialog, else the user
                // will not be able to copy/paste the stack trace and stuff
                return;
            }
            _InCrashHandler = true;

            CrashDialog cd = new CrashDialog(parent, ex);
            cd.Run();
            cd.Destroy();

            if (SysDiag.Debugger.IsAttached)
            {
                // allow the debugger to examine the situation
                //SysDiag.Debugger.Break();
                // HACK: Break() would be nicer but crashes the runtime
                throw ex;
            }

            Quit();
        }
Ejemplo n.º 6
0
        public static void ShowException(Gtk.Window parent, Exception ex)
        {
            Trace.Call(parent, ex != null ? ex.GetType() : null);

            if (parent == null)
            {
                parent = _MainWindow;
            }

            if (!IsGuiThread())
            {
                Gtk.Application.Invoke(delegate {
                    ShowException(parent, ex);
                });
                return;
            }

            if (ex is NotImplementedException)
            {
                // don't quit on NotImplementedException
                ShowError(parent, ex);
                return;
            }

#if LOG4NET
            _Logger.Error("ShowException(): Exception:", ex);
#endif

            // HACK: ugly MS .NET throws underlaying SocketException instead of
            // wrapping those into a nice RemotingException, see:
            // http://projects.qnetp.net/issues/show/232
            if (ex is System.Runtime.Remoting.RemotingException ||
                ex is System.Net.Sockets.SocketException)
            {
                if (_InReconnectHandler || _InCrashHandler)
                {
                    // one reconnect is good enough and a crash we won't survive
                    return;
                }

                Frontend.ReconnectEngineToGUI();
                return;
            }

            if (_InCrashHandler)
            {
                // only show not more than one crash dialog, else the user
                // will not be able to copy/paste the stack trace and stuff
                return;
            }
            _InCrashHandler = true;

            // we are using a remote engine, we are not running on Mono and an
            // IConvertible issue happened
            if (!Frontend.IsLocalEngine &&
                Type.GetType("Mono.Runtime") == null &&
                ex is InvalidCastException &&
                ex.Message.Contains("IConvertible"))
            {
                var msg = _(
                    "A fatal error has been detected because of a protocol incompatibility with the smuxi-server!\n\n" +
                    "Please install Mono on the frontend side so it matches the smuxi-server.\n\n" +
                    "More details about this issue can be found here:\n" +
                    "https://smuxi.im/issues/show/589"
                    );
                var dialog = new Gtk.MessageDialog(
                    parent,
                    Gtk.DialogFlags.Modal,
                    Gtk.MessageType.Error,
                    Gtk.ButtonsType.Close,
                    true,
                    msg
                    );
                dialog.Run();
                dialog.Destroy();
                Quit();
                return;
            }

            CrashDialog cd = new CrashDialog(parent, ex);
            cd.Run();
            cd.Destroy();

            if (SysDiag.Debugger.IsAttached)
            {
                // allow the debugger to examine the situation
                //SysDiag.Debugger.Break();
                // HACK: Break() would be nicer but crashes the runtime
                throw ex;
            }

            Quit();
        }