Skip to content

Commit

Permalink
Merge pull request #310 from Lombiq/issue/OSOE-815-combined
Browse files Browse the repository at this point in the history
OSOE-815: Adding `CommandExtensions.ExecuteUntilOutputAsync()`, fixing analyzer violations
  • Loading branch information
Piedone authored Jan 29, 2025
2 parents ce8cff9 + ee75483 commit 3298019
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using System;

namespace Lombiq.HelpfulLibraries.AspNetCore.Mvc;

[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = true)]
public sealed class FromJsonQueryStringAttribute : ModelBinderAttribute
{
public FromJsonQueryStringAttribute()
Expand Down
15 changes: 12 additions & 3 deletions Lombiq.HelpfulLibraries.Cli/Extensions/CommandExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,26 @@ public static class CommandExtensions
/// Executes a <see cref="Command"/> as a <c>dotnet</c> command that starts a long-running application, and waits
/// for the app to be started.
/// </summary>
public static async Task ExecuteDotNetApplicationAsync(
public static Task ExecuteDotNetApplicationAsync(
this Command command,
Action<StandardErrorCommandEvent>? stdErrHandler = default,
CancellationToken cancellationToken = default) =>
command.ExecuteUntilOutputAsync("Application started. Press Ctrl+C to shut down.", stdErrHandler, cancellationToken);

/// <summary>
/// Executes a <see cref="Command"/> until the given output is received, then returns.
/// </summary>
public static async Task ExecuteUntilOutputAsync(
this Command command,
string outputToWaitFor,
Action<StandardErrorCommandEvent>? stdErrHandler = default,
CancellationToken cancellationToken = default)
{
await using var enumerator = command.ListenAsync(cancellationToken).GetAsyncEnumerator(cancellationToken);

while (await enumerator.MoveNextAsync())
{
if (enumerator.Current is StandardOutputCommandEvent stdOut &&
stdOut.Text.ContainsOrdinalIgnoreCase("Application started. Press Ctrl+C to shut down."))
if (enumerator.Current is StandardOutputCommandEvent stdOut && stdOut.Text.ContainsOrdinalIgnoreCase(outputToWaitFor))
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using OrchardCore.DisplayManagement.Entities;
Expand Down Expand Up @@ -33,7 +33,7 @@ protected JsonSectionDisplayDriver(
_hca = hca;
}

public async override Task<IDisplayResult> EditAsync(ISite model, TSection section, BuildEditorContext context) =>
public override async Task<IDisplayResult> EditAsync(ISite model, TSection section, BuildEditorContext context) =>
await AuthorizeAsync()
? Initialize<JsonViewModel<TAdditionalData>>(
ShapeType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private static bool HasRequiredAttribute(ModelExpression modelExpression) =>
.GetCustomAttributes(typeof(RequiredAttribute), inherit: false)
.FirstOrDefault() is RequiredAttribute;

private static void AddBoolAttribute(IDictionary<string, object> attributes, bool value, string attributeName)
private static void AddBoolAttribute(Dictionary<string, object> attributes, bool value, string attributeName)
{
if (value)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static string GenerateRandomPassword(int minLength)
}

passwordChars = [.. passwordChars.OrderBy(c => rng.Next(0, int.MaxValue))];
string password = new(passwordChars.ToArray());
string password = new([.. passwordChars]);

return password;
}
Expand Down

0 comments on commit 3298019

Please sign in to comment.