Exemplo n.º 1
0
 public IronPythonScript(string path) : base(path)
 {
     Runtime = new IronPythonRuntime(Name);
     Runtime.ExecuteFile(path);
     SupportedEvents = GetSupportedEvents();
     SupportedMenus  = GetSupportedMenus();
 }
Exemplo n.º 2
0
        internal void ExecuteScriptAction(ScriptLanguage language, string script, Game game)
        {
            if (language == ScriptLanguage.PowerShell && !Scripting.PowerShell.PowerShellRuntime.IsInstalled)
            {
                throw new Exception(resources.GetString("LOCErrorPowerShellNotInstalled"));
            }

            logger.Info($"Executing script action in {language} runtime.");
            IScriptRuntime runtime = null;

            switch (language)
            {
            case ScriptLanguage.PowerShell:
                runtime = new Scripting.PowerShell.PowerShellRuntime();
                break;

            case ScriptLanguage.IronPython:
                runtime = new Scripting.IronPython.IronPythonRuntime();
                break;

            case ScriptLanguage.Batch:
                runtime = new Scripting.Batch.BatchRuntime();
                break;
            }

            using (runtime)
            {
                var dir = game.ExpandVariables(game.InstallDirectory, true);
                if (!dir.IsNullOrEmpty() && Directory.Exists(dir))
                {
                    runtime.Execute(script, dir);
                }
                else
                {
                    runtime.Execute(script);
                }
            }
        }
Exemplo n.º 3
0
        public IronPythonScript(string path) : base(path, ScriptLanguage.IronPython)
        {
            Runtime = new IronPythonRuntime();
            Runtime.ExecuteFile(path);

            var attributes = Runtime.GetVariable("__attributes");

            if (attributes != null)
            {
                Attributes = ((PythonDictionary)attributes).Cast <KeyValuePair <object, object> >().ToDictionary(a => a.Key.ToString(), b => b.Value.ToString());
            }

            var exports = Runtime.GetVariable("__exports");

            if (exports != null)
            {
                FunctionExports = new List <ScriptFunctionExport>();
                var funcs = (IEnumerable <object>)exports;
                foreach (PythonDictionary func in funcs)
                {
                    FunctionExports.Add(new ScriptFunctionExport(func["Name"].ToString(), func["Function"].ToString(), this));
                }
            }
        }
Exemplo n.º 4
0
 public IronPythonScript(string path) : base(path)
 {
     Runtime = new IronPythonRuntime();
     Runtime.ExecuteFile(path);
 }