Ejemplo n.º 1
0
        public void Start(string script, string scriptPath = null)
        {
            thread = new Thread(obj1 =>
            {
                ScriptScope scope = null;

                var ready = ExecuteSafe(() =>
                {
                    threadTimingFactory.SetDefault();

                    var pluginStarted = new CountdownEvent(0);

                    pluginStopped = new CountdownEvent(0);

                    usedPlugins = parser.InvokeAndConfigureAllScriptDependantPlugins(script).ToList();

                    var usedGlobalEnums = parser.GetAllUsedGlobalEnums(script);

                    var globals = CreateGlobals(usedPlugins, globalProviders);

                    Engine.Runtime.AddReferences(
                        usedPlugins.Select(x => x.GetType().Assembly)
                        .Concat(usedGlobalEnums.Select(t => t.Assembly))
                        .Distinct()
                        .ToArray());

                    scope = CreateScope(globals);

                    InitGlobalVariables(globals);

                    foreach (var plugin in usedPlugins)
                    {
                        StartPlugin(plugin, pluginStarted, pluginStopped);
                    }

                    pluginStarted.Wait();

                    var additionalPaths = new [] { scriptPath }.Where(p => !string.IsNullOrEmpty(p)).Select(p => fileSystem.GetDirectoryName(p));
                    Engine.SetSearchPaths(GetPythonPaths(additionalPaths));

                    script = PreProcessScript(script, usedGlobalEnums, globals);
                }, logToFile: true);

                if (ready)
                {
                    RunLoop(script, scope);
                }
            })
            {
                Name = "PythonEngine Worker"
            };

            thread.Start();
        }
Ejemplo n.º 2
0
        public void Start(string script)
        {
            thread = new Thread(obj1 => ExecuteSafe(() =>
            {
                var pluginStarted = new CountdownEvent(0);

                pluginStopped = new CountdownEvent(0);

                usedPlugins = parser.InvokeAndConfigureAllScriptDependantPlugins(script).ToList();

                var usedGlobalEnums = parser.GetAllUsedGlobalEnums(script);

                var globals = CreateGlobals(usedPlugins, globalProviders);

                Engine.Runtime.AddReferences(usedPlugins.Select(x => x.GetType().Assembly).Concat(usedGlobalEnums.Select(t => t.Assembly)).Distinct().ToArray());

                var scope = CreateScope(globals);

                foreach (var plugin in usedPlugins)
                {
                    StartPlugin(plugin, pluginStarted, pluginStopped);
                }

                pluginStarted.Wait();

                Engine.SetSearchPaths(GetPythonPaths());

                script = PreProcessScript(script, usedGlobalEnums, globals);

                threadTimingFactory.SetDefault();

                RunLoop(Engine.CreateScriptSourceFromString(script).Compile(), scope);
            }))
            {
                Name = "PythonEngine Worker"
            };

            thread.Start();
        }