コード例 #1
0
ファイル: VarType.cs プロジェクト: stallonederek/meddle
        public VarType(PythonBoss pyBoss, VarTypes varTypes, XElement element)
        {
            // Load this variable type

            _pyBoss = pyBoss;

            // Load the scripts
            foreach (XElement el in element.Elements("global_script"))
            {
                if (!_pyBoss.AddCode(el.Value, "variable types <global_script>"))
                {
                    return;
                }
            }
            foreach (XElement el in element.Elements("local_script"))
            {
                _pyLocal += "\r\n" + element.Value;
            }

            // Load the name
            XElement name = element.Element("name");

            if (name != null)
            {
                _name = name.Value;
            }

            _parent = varTypes;
        }
コード例 #2
0
ファイル: Controller.cs プロジェクト: stallonederek/meddle
        public Controller(string startScript, string[] args)
        {
            _scriptPath = System.IO.Path.GetFullPath(startScript);

            // Now that we slightly verified the xml structure, lets initialize
            _pyBoss = new PythonBoss(_scriptPath);
            string filename = System.IO.Path.GetFileName(startScript);

            if (filename.EndsWith(".py"))
            {
                filename = filename.Substring(0, filename.Length - 3);
            }

            if (!_pyBoss.AddCode(String.Format(@"from {0} import *", filename), startScript))
            {
                return;
            }

            try
            {
                // Create the controller
                var pyTypeController = _pyBoss.PyScope.GetVariable("Controller");
                PyController = _pyBoss.PyEngine.Operations.CreateInstance(pyTypeController, this);

                // Create the new process dispatcher check
                ProcessWatcher procWatcher = new ProcessWatcher();
                procWatcher.ProcessCreated += new ProcessEventHandler(procWatcher_ProcessCreated);
                procWatcher.Start();

                // Execute the controller main function
                try
                {
                    PyController.main(args);
                }
                catch (Exception e)
                {
                    Console.WriteLine("ERROR: Python class controller.main() not found or failed while executing.");
                    Console.WriteLine(e.ToString());
                    return;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("ERROR: Python class controller(...) not found or failed while executing constructor.");
                Console.WriteLine(e.ToString());
                return;
            }


            // Success, this controller is now loaded
            Initialized = true;
        }