Esempio n. 1
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);
                }
            }
        }
Esempio n. 2
0
        public PowerShellScript(string path) : base(path, ScriptLanguage.PowerShell)
        {
            Runtime = new PowerShellRuntime();
            Runtime.ExecuteFile(path);
            var attributes = Runtime.GetVariable("__attributes");

            if (attributes != null)
            {
                Attributes = ((Hashtable)attributes).Cast <DictionaryEntry>().ToDictionary(kvp => (string)kvp.Key, kvp => (string)kvp.Value);
            }

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

            if (exports != null)
            {
                FunctionExports = new List <ScriptFunctionExport>();
                var funcs = (IEnumerable <object>)exports;
                foreach (Hashtable func in funcs)
                {
                    FunctionExports.Add(new ScriptFunctionExport(func["Name"].ToString(), func["Function"].ToString(), this));
                }
            }
        }
Esempio n. 3
0
 public PowerShellScript(string path) : base(path)
 {
     Runtime = new PowerShellRuntime();
     Runtime.ExecuteFile(path);
     supportedEvents = GetSupportedEvents();
 }
Esempio n. 4
0
 public PowerShellScript(string path) : base(path)
 {
     Runtime = new PowerShellRuntime();
     Runtime.ExecuteFile(path);
 }