Files
PowerShellBlazor/PowerShellBlazor/Pages/Index.razor
2022-08-23 18:19:08 +10:00

46 lines
1.1 KiB
Plaintext

@page "/"
@inject IPowerShellService PowerShellService
<EditForm EditContext="@editContext" OnSubmit="RunScript">
<DataAnnotationsValidator />
<div class="mb-3">
<label for="Name" class="form-label">Script</label>
<div class="col-md-4">
<InputText class="form-control" @bind-Value="script" required="required" />
</div>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Run</button>
</div>
</EditForm>
<hr />
@foreach (var message in PowerShellService.Output)
{
<div class="@message.PSStream">
@((MarkupString)message.Data)
</div>
}
@code
{
protected EditContext editContext;
protected override void OnInitialized()
{
editContext = new(script);
}
protected string script { get; set; } = "";
protected void RunScript()
{
PowerShellService.Output = new();
PowerShellService.OutputChanged += OutputChanged;
Task.Run(() => PowerShellService.RunScript(script));
}
private void OutputChanged(object sender, List<Message> newOutput)
{
InvokeAsync(() => this.StateHasChanged());
}
}