예제 #1
0
        public static void InitRemoteEngine(string engine)
        {
            EngineManager = new EngineManager(_FrontendConfig,
                                              _MainWindow.UI);
            try {
                try {
                    Console.WriteLine(
                        _("Connecting to remote engine '{0}'..."), engine
                        );
                    EngineManager.Connect(engine);
                    Console.WriteLine(_("Connection established"));
                } catch (Exception ex) {
#if LOG4NET
                    _Logger.Error(ex);
#endif
                    Console.WriteLine(
                        _("Connection failed! Error: {1}"),
                        engine,
                        ex.Message
                        );
                    Environment.Exit(1);
                }

                Session     = EngineManager.Session;
                _UserConfig = EngineManager.UserConfig;
                ConnectEngineToGUI();
            } catch (Exception ex) {
#if LOG4NET
                _Logger.Error(ex);
#endif
                EngineManager.Disconnect();
                throw;
            }
        }
예제 #2
0
파일: Frontend.cs 프로젝트: licnep/smuxi
        public static void Init(string[] args)
        {
            System.Threading.Thread.CurrentThread.Name = "Main";

            if (!(args.Length >= 1))
            {
                Console.Error.WriteLine("Usage: smuxi-test.exe profile");
                Environment.Exit(1);
            }

#if LOG4NET
            _Logger.Info("smuxi-test starting");
#endif

            _FrontendConfig = new FrontendConfig("Test");
            _FrontendConfig.Load();

            string profile = args[0];
            if (String.IsNullOrEmpty(profile))
            {
                Console.Error.WriteLine("profile parameter must not be empty!");
                Environment.Exit(1);
            }

            IFrontendUI ui = new TestUI();

            Session session = null;
            if (profile == "local")
            {
                Engine.Engine.Init();
                session = new Engine.Session(Engine.Engine.Config,
                                             Engine.Engine.ProtocolManagerFactory,
                                             "local");
                session.RegisterFrontendUI(ui);
            }
            else
            {
                // remote engine
                EngineManager engineManager = new EngineManager(_FrontendConfig, ui);
                engineManager.Connect(profile);
                session = engineManager.Session;
            }

            if (session == null)
            {
                Console.Error.WriteLine("Session is null, something went wrong setting up or connecting to the engine!");
                Environment.Exit(1);
            }

            _Session         = session;
            _UserConfig      = session.UserConfig;
            _FrontendManager = session.GetFrontendManager(ui);
            _FrontendManager.Sync();

            if (_UserConfig.IsCaching)
            {
                // when our UserConfig is cached, we need to invalidate the cache
                _FrontendManager.ConfigChangedDelegate = new SimpleDelegate(_UserConfig.ClearCache);
            }

            while (true)
            {
                string line = Console.ReadLine();
                // TODO: remove the entered line from output
                //Console.WriteLine(Escape+"M");

                _ExecuteCommand(line);
            }
        }
예제 #3
0
파일: Frontend.cs 프로젝트: txdv/smuxi
        public static void InitRemoteEngine(string engine)
        {
            var manager = new EngineManager(_FrontendConfig,
                                            _MainWindow.UI);
            try {
                try {
                    Console.WriteLine(
                        _("Connecting to remote engine '{0}'..."), engine
                    );
                    manager.Connect(engine);
                    Console.WriteLine(_("Connection established"));
                } catch (Exception ex) {
            #if LOG4NET
                    _Logger.Error(ex);
            #endif
                    Console.WriteLine(
                        _("Connection failed! Error: {1}"),
                        engine,
                        ex.Message
                    );
                    Environment.Exit(1);
                }

                _Session = manager.Session;
                _UserConfig = manager.UserConfig;
                _EngineVersion = manager.EngineVersion;
                ConnectEngineToGUI();
            } catch (Exception ex) {
            #if LOG4NET
                _Logger.Error(ex);
            #endif
                manager.Disconnect();
                throw;
            }
        }
예제 #4
0
        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();
            }
        }