Ejemplo n.º 1
0
 public void InvokeEndFileEventMode(EndFileEventMode arg)
 {
     Task.Run(() =>
     {
         PowerShellScript.Execute(File.ReadAllText(FilePath), new string[] { arg.ToString() });
     });
 }
Ejemplo n.º 2
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[] {});
            });
        }
Ejemplo n.º 3
0
 public void InvokeStrings(string[] args)
 {
     Task.Run(() => PowerShellScript.Execute(File.ReadAllText(FilePath), args));
 }
Ejemplo n.º 4
0
 public void Invoke() => Task.Run(() => { PowerShellScript.Execute(File.ReadAllText(FilePath), null); });
Ejemplo n.º 5
0
 public void Invoke()
 {
     Task.Run(() => { PowerShellScript.Execute(File.ReadAllText(FilePath), new string[] { }); });
 }
Ejemplo n.º 6
0
 public void InvokeStrings(string[] args) => PowerShellScript.Execute(Filepath, args);
Ejemplo n.º 7
0
 public void InvokeEndFile(EndFileEventMode arg) => PowerShellScript.Execute(Filepath, arg.ToString());
Ejemplo n.º 8
0
 public void Invoke() => PowerShellScript.Execute(Filepath);