mirror of
https://github.com/ashstrahle/PowerShellBlazor.git
synced 2025-12-31 19:49:52 +10:00
Merge branch 'master' into Ash
This commit is contained in:
13
PowerShellBlazor/Data/WeatherForecast.cs
Normal file
13
PowerShellBlazor/Data/WeatherForecast.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace PowerShellBlazor.Data;
|
||||
|
||||
public class WeatherForecast
|
||||
{
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
public int TemperatureC { get; set; }
|
||||
|
||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
||||
|
||||
public string? Summary { get; set; }
|
||||
}
|
||||
|
||||
20
PowerShellBlazor/Data/WeatherForecastService.cs
Normal file
20
PowerShellBlazor/Data/WeatherForecastService.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
namespace PowerShellBlazor.Data;
|
||||
|
||||
public class WeatherForecastService
|
||||
{
|
||||
private static readonly string[] Summaries = new[]
|
||||
{
|
||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
||||
};
|
||||
|
||||
public Task<WeatherForecast[]> GetForecastAsync(DateTime startDate)
|
||||
{
|
||||
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
|
||||
{
|
||||
Date = startDate.AddDays(index),
|
||||
TemperatureC = Random.Shared.Next(-20, 55),
|
||||
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
|
||||
}).ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
@page "/"
|
||||
@page "/"
|
||||
@inject IPowerShellService PowerShellService
|
||||
|
||||
<EditForm EditContext="@editContext" OnSubmit="RunScript">
|
||||
<DataAnnotationsValidator />
|
||||
<div class="mb-3">
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
global using PowerShellBlazor.Models;
|
||||
global using PowerShellBlazor.Models;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Web;
|
||||
using PowerShellBlazor.Services;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
for ($i=1; $i -le 5; $i++) {
|
||||
for ($i=1; $i -le 5; $i++) {
|
||||
Write-Progress "Loop $i - progress output (Write-Progress)"
|
||||
Write-Information "Here's some information (Write-Information)"
|
||||
Write-Output "Normal output text (Write-Output)"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
|
||||
namespace PowerShellBlazor.Services
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Management.Automation;
|
||||
using System.Management.Automation;
|
||||
|
||||
namespace PowerShellBlazor.Services
|
||||
{
|
||||
@@ -83,6 +83,122 @@ namespace PowerShellBlazor.Services
|
||||
shell.Streams.Error.DataAdded += delegate (object? sender, DataAddedEventArgs e)
|
||||
{
|
||||
AddOutput(PSStream.Error, shell.Streams.Error[e.Index].ToString());
|
||||
=======
|
||||
public List<string> Output { get; set; } = new();
|
||||
|
||||
private void AddOutput(string str)
|
||||
{
|
||||
Output.Add(str);
|
||||
OutputChanged.Invoke(this, Output);
|
||||
}
|
||||
|
||||
public event EventHandler<List<string>> 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("<b>Executing: </b>" + shell.Commands.Commands[0].ToString());
|
||||
string prevmsg = "";
|
||||
string msg = "";
|
||||
|
||||
AddOutput("<br><b>BEGIN</b>");
|
||||
AddOutput("<br>_________________________________________________________________________");
|
||||
|
||||
var psOutput = new PSDataCollection<PSObject>();
|
||||
|
||||
// Collect powershell OUTPUT
|
||||
psOutput.DataAdded += delegate (object? sender, DataAddedEventArgs e)
|
||||
{
|
||||
msg = psOutput[e.Index].ToString();
|
||||
|
||||
if (msg != prevmsg)
|
||||
{
|
||||
AddOutput("<br><span><font color=black " + fontstr + ">" + msg + "</font></span>");
|
||||
}
|
||||
else
|
||||
{
|
||||
AddOutput(".");
|
||||
}
|
||||
prevmsg = msg;
|
||||
if (sender is not null)
|
||||
{
|
||||
var psoutput = (PSDataCollection<PSObject>)sender;
|
||||
Collection<PSObject> 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("<br><span><font color=green " + fontstr + ">" + msg + "</font></span>");
|
||||
}
|
||||
else
|
||||
{
|
||||
AddOutput(".");
|
||||
}
|
||||
prevmsg = msg;
|
||||
if (sender is not null)
|
||||
{
|
||||
var psprogress = (PSDataCollection<ProgressRecord>)sender;
|
||||
Collection<ProgressRecord> 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("<br><span><font color=orange " + fontstr + "><b>***WARNING***:</b> " + msg + "</font></span>");
|
||||
}
|
||||
else
|
||||
{
|
||||
AddOutput(".");
|
||||
}
|
||||
prevmsg = msg;
|
||||
if (sender is not null)
|
||||
{
|
||||
var pswarning = (PSDataCollection<WarningRecord>)sender;
|
||||
Collection<WarningRecord> 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("<br><span><font color=red " + fontstr + "><b>***ERROR***:</b> " + msg + "</font></span>");
|
||||
}
|
||||
else
|
||||
{
|
||||
AddOutput(".");
|
||||
}
|
||||
prevmsg = msg;
|
||||
if (sender is not null)
|
||||
{
|
||||
var pserror = (PSDataCollection<ErrorRecord>)sender;
|
||||
Collection<ErrorRecord> results = pserror.ReadAll();
|
||||
}
|
||||
};
|
||||
|
||||
// Execute powershell command
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@inherits LayoutComponentBase
|
||||
@inherits LayoutComponentBase
|
||||
|
||||
<PageTitle>PowerShell Blazor</PageTitle>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user