Esempio n. 1
0
 public void InvokeEndFileEventMode(EndFileEventMode arg)
 {
     Task.Run(() =>
     {
         PowerShellScript.Execute(File.ReadAllText(FilePath), new string[] { arg.ToString() });
     });
 }
Esempio n. 2
0
        public static void LoadScripts()
        {
            if (Directory.Exists(Application.StartupPath + "\\Scripts"))
            {
                string[] startupScripts = Directory.GetFiles(Application.StartupPath + "\\Scripts");

                foreach (string scriptPath in startupScripts)
                {
                    if (scriptPath.EndsWith(".lua") || scriptPath.EndsWith(".js"))
                    {
                        commandv("load-script", $"{scriptPath}");
                    }
                }

                foreach (string scriptPath in startupScripts)
                {
                    if (Path.GetExtension(scriptPath) == ".py")
                    {
                        PythonScripts.Add(new PythonScript(File.ReadAllText(scriptPath)));
                    }
                }

                foreach (string scriptPath in startupScripts)
                {
                    if (Path.GetExtension(scriptPath) == ".ps1")
                    {
                        PowerShellScript.Init(scriptPath);
                    }
                }
            }

            if (Directory.Exists(ConfigFolder + "Scripts"))
            {
                foreach (string scriptPath in Directory.GetFiles(ConfigFolder + "Scripts"))
                {
                    if (Path.GetExtension(scriptPath) == ".py")
                    {
                        PythonScripts.Add(new PythonScript(File.ReadAllText(scriptPath)));
                    }
                    else if (Path.GetExtension(scriptPath) == ".ps1")
                    {
                        PowerShellScript.Init(scriptPath);
                    }
                }
            }
        }
Esempio n. 3
0
        public static void LoadScripts()
        {
            string[] jsLua          = { ".lua", ".js" };
            string[] startupScripts = Directory.GetFiles(Application.StartupPath + "\\Scripts");

            foreach (var scriptPath in startupScripts)
            {
                if (jsLua.Contains(Path.GetExtension(scriptPath).ToLower()))
                {
                    commandv("load-script", $"{scriptPath}");
                }
            }

            foreach (var scriptPath in startupScripts)
            {
                if (Path.GetExtension(scriptPath) == ".py")
                {
                    PythonScripts.Add(new PythonScript(File.ReadAllText(scriptPath)));
                }
            }

            foreach (var scriptPath in startupScripts)
            {
                if (Path.GetExtension(scriptPath) == ".ps1")
                {
                    PowerShellScript.Init(scriptPath);
                }
            }

            if (Directory.Exists(ConfFolder + "Scripts"))
            {
                foreach (var scriptPath in Directory.GetFiles(ConfFolder + "Scripts"))
                {
                    if (Path.GetExtension(scriptPath) == ".py")
                    {
                        PythonScripts.Add(new PythonScript(File.ReadAllText(scriptPath)));
                    }
                    else if (Path.GetExtension(scriptPath) == ".ps1")
                    {
                        PowerShellScript.Init(scriptPath);
                    }
                }
            }
        }
Esempio n. 4
0
        public static void Init(string filePath)
        {
            foreach (var eventInfo in typeof(mp).GetEvents())
            {
                if (eventInfo.Name.ToLower() ==
                    Path.GetFileNameWithoutExtension(filePath).ToLower().Replace("-", ""))
                {
                    PowerShellEventObject eventObject = new PowerShellEventObject();
                    MethodInfo            mi;
                    eventObject.FilePath = filePath;

                    if (eventInfo.EventHandlerType == typeof(Action))
                    {
                        mi = eventObject.GetType().GetMethod(nameof(PowerShellEventObject.Invoke));
                    }
                    else if (eventInfo.EventHandlerType == typeof(Action <EndFileEventMode>))
                    {
                        mi = eventObject.GetType().GetMethod(nameof(PowerShellEventObject.InvokeEndFileEventMode));
                    }
                    else if (eventInfo.EventHandlerType == typeof(Action <string[]>))
                    {
                        mi = eventObject.GetType().GetMethod(nameof(PowerShellEventObject.InvokeStrings));
                    }
                    else
                    {
                        throw new Exception();
                    }

                    eventObject.EventInfo = eventInfo;
                    Delegate handler = Delegate.CreateDelegate(eventInfo.EventHandlerType, eventObject, mi);
                    eventObject.Delegate = handler;
                    eventInfo.AddEventHandler(eventObject, handler);
                    return;
                }
            }
            Task.Run(() =>
            {
                PowerShellScript.Execute(File.ReadAllText(filePath), new string[] {});
            });
        }
Esempio n. 5
0
 public void InvokeStrings(string[] args)
 {
     Task.Run(() => PowerShellScript.Execute(File.ReadAllText(FilePath), args));
 }
Esempio n. 6
0
 public void Invoke() => Task.Run(() => { PowerShellScript.Execute(File.ReadAllText(FilePath), null); });
Esempio n. 7
0
 public void Invoke()
 {
     Task.Run(() => { PowerShellScript.Execute(File.ReadAllText(FilePath), new string[] { }); });
 }
Esempio n. 8
0
 public void InvokeStrings(string[] args) => PowerShellScript.Execute(Filepath, args);
Esempio n. 9
0
 public void InvokeEndFile(EndFileEventMode arg) => PowerShellScript.Execute(Filepath, arg.ToString());
Esempio n. 10
0
 public void Invoke() => PowerShellScript.Execute(Filepath);