Skip to content

Commit

Permalink
Fix script output.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed Jul 27, 2023
1 parent 105f811 commit 3d33fe1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
6 changes: 3 additions & 3 deletions Server/Pages/DeviceDetails.razor
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ else
<td>@scriptResult.TimeStamp</td>
<td>@scriptResult.SenderUserName</td>
<td>@scriptResult.RunTime</td>
<td>@GetTrimmedText($"{scriptResult.ScriptInput}", 25)</td>
<td>@GetTrimmedText($"{scriptResult.StandardOutput}", 25)</td>
<td>@GetTrimmedText($"{scriptResult.ErrorOutput}", 25)</td>
<td>@GetTrimmedText(scriptResult.ScriptInput, 25)</td>
<td>@GetTrimmedText(scriptResult.StandardOutput, 25)</td>
<td>@GetTrimmedText(scriptResult.ErrorOutput, 25)</td>
<td>
<button class="btn btn-sm btn-primary" @onclick="() => ShowFullScriptOutput(scriptResult)">Show Full</button>
</td>
Expand Down
12 changes: 9 additions & 3 deletions Server/Pages/DeviceDetails.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private void GetScriptHistory()
}
}

private string GetTrimmedText(string source, int stringLength)
private string GetTrimmedText(string? source, int stringLength)
{
if (string.IsNullOrWhiteSpace(source))
{
Expand All @@ -171,6 +171,12 @@ private string GetTrimmedText(string source, int stringLength)
return source[0..25] + "...";
}

private string GetTrimmedText(string[]? source, int stringLength)
{
source ??= Array.Empty<string>();
return GetTrimmedText(string.Join("", source), stringLength);
}

private Task HandleValidSubmit()
{
if (_device is null)
Expand Down Expand Up @@ -215,8 +221,8 @@ private void ShowFullScriptOutput(ScriptResult result)
{
void outputModal(RenderTreeBuilder builder)
{
var output = string.Join("\r\n", $"{result.StandardOutput}");
var error = string.Join("\r\n", $"{result.ErrorOutput}");
var output = string.Join("\r\n", result.StandardOutput ?? Array.Empty<string>());
var error = string.Join("\r\n", result.ErrorOutput ?? Array.Empty<string>());
var textareaStyle = "width: 100%; height: 200px; white-space: pre;";

builder.AddMarkupContent(0, "<h5>Input</h5>");
Expand Down

0 comments on commit 3d33fe1

Please sign in to comment.