public void SharedEngineVariables()
        {
            using (OleServiceProvider provider = new OleServiceProvider())
            {
                // Create an engine provider with an empty service provider.
                IPythonEngineProvider engineProvider = CreateEngineProvider(provider);
                // Get the shared engine.
                IEngine engine = engineProvider.GetSharedEngine();
                // The "engine" variable should always be defined.
                object engObj = engine.Evaluate("engine");
                Assert.IsNotNull(engObj);
                // The "dte" variable should be set to null.
                object dte = engine.Evaluate("dte");
                Assert.IsNull(dte);

                // Now add the EnvDTE.DTE service to the service provider.
                BaseMock dteMock = MockFactories.DTEFactory.GetInstance();
                provider.AddService(typeof(EnvDTE.DTE), dteMock, false);

                // Create a new engine provider.
                engineProvider = CreateEngineProvider(provider);
                // Get the shared engine.
                engine = engineProvider.GetSharedEngine();
                // The "engine" variable should always be defined.
                engObj = engine.Evaluate("engine");
                Assert.IsNotNull(engObj);
                // Now the "dte" variable should be set.
                dte = engine.Evaluate("dte");
                Assert.IsNotNull(dte);
            }
        }
        public void SharedEngineTest()
        {
            IPythonEngineProvider engineProvider = CreateEngineProvider(null);
            // Verify that the shared engine is created.
            IEngine engineObj = engineProvider.GetSharedEngine();

            Assert.IsNotNull(engineObj);

            // Verify that the object returned by GetSharedEngine is always the same.
            IEngine newEngine = engineProvider.GetSharedEngine();

            Assert.IsTrue(newEngine.Equals(engineObj));
        }
        /// <summary>
        /// Thread function used to run the IronPython engine in a different thread.
        /// This thread will run until the IConsole implementation of this window will return
        /// null from the ReadLine method.
        /// </summary>
        private void InitializeEngine()
        {
            // Get the engine provider service to set this console window as the console
            // object associated with the shared engine.
            IPythonEngineProvider engineProvider = (IPythonEngineProvider)globalProvider.GetService(typeof(IPythonEngineProvider));

            if (null != engineProvider)
            {
                IEngine engine = engineProvider.GetSharedEngine();
                engine.StdErr = textStream;
                engine.StdOut = textStream;
                string version = string.Format(System.Globalization.CultureInfo.CurrentCulture,
                                               Resources.EngineVersionFormat,
                                               engine.Version.Major,
                                               engine.Version.Minor,
                                               engine.Version.Build);

                // Write engine version end copyright on the console.
                using (StreamWriter writer = new StreamWriter(textStream as Stream))
                {
                    writer.WriteLine(version);
                    writer.WriteLine(engine.Copyright);
                }

                // Create the buffer that will handle the commands to the engine.
                inputBuffer = new CommandBuffer(engine);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Thread function used to run the IronPython engine in a different thread.
        /// This thread will run until the IConsole implementation of this window will return
        /// null from the ReadLine method.
        /// </summary>
        private void InitializeEngine()
        {
            // Get the engine provider service to set this console window as the console
            // object associated with the shared engine.
            IPythonEngineProvider engineProvider = (IPythonEngineProvider)globalProvider.GetService(typeof(IPythonEngineProvider));

            if (null != engineProvider)
            {
                IEngine engine = engineProvider.GetSharedEngine();
                engine.StdErr = textStream;
                engine.StdOut = textStream;
                string version = string.Format(System.Globalization.CultureInfo.CurrentCulture,
                                               Resources.EngineVersionFormat,
                                               engine.Version.Major,
                                               engine.Version.Minor,
                                               engine.Version.Build);
                // Remove the read-only flag from the text buffer.
                uint flags;
                Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(
                    textLines.GetStateFlags(out flags));
                flags &= ~(uint)Microsoft.VisualStudio.TextManager.Interop.BUFFERSTATEFLAGS.BSF_USER_READONLY;
                Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(
                    textLines.SetStateFlags(flags));

                // Write engine version end copyright on the console.
                using (StreamWriter writer = new StreamWriter(textStream as Stream))
                {
                    writer.WriteLine(version);
                    writer.WriteLine(engine.Copyright);
                }

                // Create the buffer that will handle the commands to the engine.
                inputBuffer = new CommandBuffer(engine);
            }
        }