From 5ac2495e3ab628d8e72c9b535d7e0221ee63a87f Mon Sep 17 00:00:00 2001 From: Ashley Strahle Date: Tue, 23 Aug 2022 18:30:25 +1000 Subject: [PATCH] Init --- .../Services/PowerShellService.cs | 121 ------------------ 1 file changed, 121 deletions(-) diff --git a/PowerShellBlazor/Services/PowerShellService.cs b/PowerShellBlazor/Services/PowerShellService.cs index 9ae9063..271ab46 100644 --- a/PowerShellBlazor/Services/PowerShellService.cs +++ b/PowerShellBlazor/Services/PowerShellService.cs @@ -49,12 +49,7 @@ namespace PowerShellBlazor.Services PowerShell shell = PowerShell.Create(); shell.AddCommand(pscommand); - string fontstr = ""; - AddOutput(PSStream.Output, "Executing: " + shell.Commands.Commands[0].ToString()); - string prevmsg = ""; - string msg = ""; - AddOutput(PSStream.Output, "BEGIN"); AddOutput(PSStream.Output, "_________________________________________________________________________"); @@ -83,122 +78,6 @@ namespace PowerShellBlazor.Services shell.Streams.Error.DataAdded += delegate (object? sender, DataAddedEventArgs e) { AddOutput(PSStream.Error, shell.Streams.Error[e.Index].ToString()); -======= - public List Output { get; set; } = new(); - - private void AddOutput(string str) - { - Output.Add(str); - OutputChanged.Invoke(this, Output); - } - - public event EventHandler> OutputChanged; - - public async Task RunScript(PowerShell shell, bool varwidth) - { - if (shell == null) - { - AddOutput("Shell empty - nothing to execute"); - } - else - { - string fontstr = ""; - if (varwidth != true) - { - fontstr = "face='monospace' size=3"; - } - - AddOutput("Executing: " + shell.Commands.Commands[0].ToString()); - string prevmsg = ""; - string msg = ""; - - AddOutput("
BEGIN"); - AddOutput("
_________________________________________________________________________"); - - var psOutput = new PSDataCollection(); - - // Collect powershell OUTPUT - psOutput.DataAdded += delegate (object? sender, DataAddedEventArgs e) - { - msg = psOutput[e.Index].ToString(); - - if (msg != prevmsg) - { - AddOutput("
" + msg + ""); - } - else - { - AddOutput("."); - } - prevmsg = msg; - if (sender is not null) - { - var psoutput = (PSDataCollection)sender; - Collection results = psoutput.ReadAll(); - } - }; - - prevmsg = ""; - // Collect powershell PROGRESS output - shell.Streams.Progress.DataAdded += delegate (object? sender, DataAddedEventArgs e) - { - msg = shell.Streams.Progress[e.Index].Activity.ToString(); - if (msg != prevmsg) - { - AddOutput("
" + msg + ""); - } - else - { - AddOutput("."); - } - prevmsg = msg; - if (sender is not null) - { - var psprogress = (PSDataCollection)sender; - Collection results = psprogress.ReadAll(); - } - }; - - prevmsg = ""; - // Collect powershell WARNING output - shell.Streams.Warning.DataAdded += delegate (object? sender, DataAddedEventArgs e) - { - msg = shell.Streams.Warning[e.Index].ToString(); - if (msg != prevmsg) - { - AddOutput("
***WARNING***: " + msg + ""); - } - else - { - AddOutput("."); - } - prevmsg = msg; - if (sender is not null) - { - var pswarning = (PSDataCollection)sender; - Collection results = pswarning.ReadAll(); - } - }; - - prevmsg = ""; - // Collect powershell ERROR output - shell.Streams.Error.DataAdded += delegate (object? sender, DataAddedEventArgs e) - { - msg = shell.Streams.Error[e.Index].ToString(); - if (msg != prevmsg) - { - AddOutput("
***ERROR***: " + msg + ""); - } - else - { - AddOutput("."); - } - prevmsg = msg; - if (sender is not null) - { - var pserror = (PSDataCollection)sender; - Collection results = pserror.ReadAll(); - } }; // Execute powershell command