Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSOE-815: Adding CommandExtensions.ExecuteUntilOutputAsync(), fixing analyzer violations #310

Open
wants to merge 13 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading