示例#1
0
        public void Initialize(string[] args)
        {
            if (args.Length == 1 && args[0] == "/reset")
            {
                Properties.Settings.Default.Reset();
            }

            m_baseServicesDispatcher = new BaseServicesDispatcher();

            // Init mainwindow and display
            m_mainWindow         = new MainWindow(this);
            m_paragraphContainer = new ParagraphContainer();
            m_mainWindow.TextView.ParagraphContainer = m_paragraphContainer;
            ChiConsole.SetChiConsole(this);

            // Initialize ironpython
            IronPython.Compiler.Options.GenerateModulesAsSnippets = true;

            /*			IronPython.Compiler.Options.GenerateDynamicMethods = false;
             *                      IronPython.Compiler.Options.DebugMode = true;
             *                      IronPython.Compiler.Options.EngineDebug = true;
             *                      IronPython.Compiler.Options.ILDebug = true;
             *                      IronPython.Compiler.Options.Frames = true;
             */
            m_pythonEngine = new PythonEngine();
            //m_pythonEngine.CreateModule("globals", true);

            ChiPythonStream s = new ChiPythonStream();

            m_pythonEngine.SetStandardOutput(s);
            m_pythonEngine.SetStandardError(s);
            m_pythonEngine.SetStandardInput(s);
            m_pythonEngine.AddToPath(Application.StartupPath + "/lib");
#if DEBUG
            m_pythonEngine.AddToPath(@"../../../scripts/lib");
#endif
            m_pythonEngine.LoadAssembly(typeof(TriggerManager).Assembly);             // load ChiropteraBase
            m_pythonEngine.LoadAssembly(typeof(System.Drawing.Bitmap).Assembly);      // load System.Drawing
            m_pythonEngine.LoadAssembly(typeof(System.Windows.Forms.Keys).Assembly);  // load System.Windows.Forms

            // Network
            m_telnet = new Telnet();
            m_telnet.connectEvent    += new Telnet.ConnectDelegate(_ConnectEvent);
            m_telnet.disconnectEvent += new Telnet.DisconnectDelegate(_DisconnectEvent);
            m_telnet.receiveEvent    += new Telnet.ReceiveDelegate(_ReceiveEvent);
            m_telnet.promptEvent     += new Telnet.PromptDelegate(_PromptEvent);
            m_telnet.telnetEvent     += new Telnet.TelnetDelegate(_TelnetEvent);



            m_commandManager = new CommandManager(m_baseServicesDispatcher);
            AddBuiltinCommands();

            m_triggerManager = new TriggerManager(m_baseServicesDispatcher);
            m_triggerManager.SetTriggers(Properties.Settings.Default.Triggers);

            m_hiliteManager = new HiliteManager(m_triggerManager);

            m_keyManager = new KeyManager(m_baseServicesDispatcher);
            m_keyManager.SetKeyBindings(Properties.Settings.Default.KeyBindings);

            PythonInterface.Initialize(m_baseServicesDispatcher, m_triggerManager, m_commandManager, this,
                                       this, m_pythonEngine, m_keyManager, m_hiliteManager);

            try
            {
#if DEBUG
                PythonInterface.RunScript(Path.GetFullPath("../../../scripts/std/init_std.bc"));
#else
                PythonInterface.RunScript(Path.Combine(Environment.CurrentDirectory, "std/init_std.bc"));
#endif
            }
            catch (Exception e)
            {
                ChiConsole.WriteError("Error running init_std.bc", e);
            }

            try
            {
                string userScript = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Chiroptera/init.bc");
                if (File.Exists(userScript))
                {
                    PythonInterface.RunScript(userScript);
                }
            }
            catch (Exception e)
            {
                ChiConsole.WriteError("Error running init.bc", e);
            }

            Version currentVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
            Version baseVersion    = System.Reflection.Assembly.GetAssembly(typeof(Telnet)).GetName().Version;
            ChiConsole.WriteLine("Chiroptera version {0} (base {1})", currentVersion.ToString(2), baseVersion.ToString(2));
            ChiConsole.WriteLine("Using {0}", PythonEngine.VersionString);

            CheckClientVersion();
        }
示例#2
0
        public ClientCore()
        {
            s_clientCore = this;

            //Ansi.SendAnsiInit();

            m_synchronizedInvoke = new SynchronizedInvoke();

            // Services
            m_baseServicesDispatcher = new BaseServicesDispatcher();

            // Init console
            m_textConsole = new TextConsole();
            ChiConsole.SetChiConsole(m_textConsole);

            // Initialize ironpython
            IronPython.Compiler.Options.GenerateModulesAsSnippets = true;
            m_pythonEngine = new PythonEngine();

            ChiPythonStream s = new ChiPythonStream();

            m_pythonEngine.SetStandardOutput(s);
            m_pythonEngine.SetStandardError(s);
            m_pythonEngine.SetStandardInput(s);
            //m_pythonEngine.AddToPath(Environment.CurrentDirectory);
            //m_pythonEngine.AddToPath(Application.StartupPath + "/lib");
#if DEBUG
            m_pythonEngine.AddToPath(@"../../../scripts/lib");
#endif
            m_pythonEngine.LoadAssembly(typeof(TriggerManager).Assembly);             // load BatClientBase
            m_pythonEngine.LoadAssembly(typeof(System.Drawing.Bitmap).Assembly);      // load System.Drawing
            m_pythonEngine.LoadAssembly(typeof(System.Windows.Forms.Keys).Assembly);  // load System.Windows.Forms



            // Network
            m_telnet = new Telnet();
            m_telnet.connectEvent    += new Telnet.ConnectDelegate(_ConnectEvent);
            m_telnet.disconnectEvent += new Telnet.DisconnectDelegate(_DisconnectEvent);
            m_telnet.receiveEvent    += new Telnet.ReceiveDelegate(_ReceiveEvent);
            m_telnet.promptEvent     += new Telnet.PromptDelegate(_PromptEvent);
            m_telnet.telnetEvent     += new Telnet.TelnetDelegate(_TelnetEvent);

            m_netPipe = UnixPipes.CreatePipes();


            m_commandManager = new CommandManager(m_baseServicesDispatcher);
            AddBuiltinCommands();

            m_triggerManager = new TriggerManager(m_baseServicesDispatcher);

            m_keyManager = new KeyManager(m_baseServicesDispatcher);

            m_hiliteManager = new HiliteManager(m_triggerManager);

            PythonInterface.Initialize(m_baseServicesDispatcher, m_triggerManager, m_commandManager, this,
                                       m_textConsole, m_pythonEngine, m_keyManager, m_hiliteManager);

            // run init script

            Version currentVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
            Version baseVersion    = System.Reflection.Assembly.GetAssembly(typeof(Telnet)).GetName().Version;
            ChiConsole.WriteLine("Chiroptera version {0} (base {1})", currentVersion.ToString(2), baseVersion.ToString(2));
            ChiConsole.WriteLine("Using {0}", PythonEngine.VersionString);

            try
            {
#if DEBUG
                PythonInterface.RunScript(Path.GetFullPath("../../../scripts/std/init_std.bc"));
#else
                PythonInterface.RunScript(Path.Combine(Environment.CurrentDirectory, "std/init_std.bc"));
#endif
            }
            catch (Exception e)
            {
                ChiConsole.WriteError("Error running init_std.bc", e);
            }

/*
 *                      m_pythonEngine.Import("site");
 *
 *                      try
 *                      {
 *                              m_pythonEngine.ExecuteFile("init.py");
 *                      }
 *                      catch (Exception e)
 *                      {
 *                              ChiConsole.WriteError("Eval failed", e);
 *                      }
 */
        }