Example #1
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 globals = CreateGlobals(usedPlugins, globalProviders);

                var pluginTypes = usedPlugins.Select(x => x.GetType()).Select(x => new { x.Assembly, x.Namespace }).ToList();

                Engine.Runtime.AddReferences(pluginTypes.Select(x => x.Assembly).Distinct().ToArray());

                var scope = CreateScope(globals);

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

                pluginStarted.Wait();

                Engine.SetSearchPaths(GetPythonPaths());

                script = PreProcessScript(script, usedPlugins, globals);

                RunLoop(Engine.CreateScriptSourceFromString(script).Compile(), scope);
            }));

            thread.Name = "PythonEngine Worker";
            thread.Start();
        }
Example #2
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();
        }