Пример #1
0
 public void InvokeEndFileEventMode(EndFileEventMode arg)
 {
     Task.Run(() =>
     {
         PowerShellScript.Execute(File.ReadAllText(FilePath), new string[] { arg.ToString() });
     });
 }
Пример #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);
                    }
                }
            }
        }
Пример #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);
                    }
                }
            }
        }
Пример #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[] {});
            });
        }
Пример #5
0
 public void InvokeStrings(string[] args)
 {
     Task.Run(() => PowerShellScript.Execute(File.ReadAllText(FilePath), args));
 }
Пример #6
0
 public void Invoke() => Task.Run(() => { PowerShellScript.Execute(File.ReadAllText(FilePath), null); });
Пример #7
0
 public void Invoke()
 {
     Task.Run(() => { PowerShellScript.Execute(File.ReadAllText(FilePath), new string[] { }); });
 }
Пример #8
0
 public void InvokeStrings(string[] args) => PowerShellScript.Execute(Filepath, args);
Пример #9
0
 public void InvokeEndFile(EndFileEventMode arg) => PowerShellScript.Execute(Filepath, arg.ToString());
Пример #10
0
 public void Invoke() => PowerShellScript.Execute(Filepath);