Skip to content

Commit 3298019

Browse files
authored
Merge pull request #310 from Lombiq/issue/OSOE-815-combined
OSOE-815: Adding `CommandExtensions.ExecuteUntilOutputAsync()`, fixing analyzer violations
2 parents ce8cff9 + ee75483 commit 3298019

File tree

5 files changed

+18
-7
lines changed

5 files changed

+18
-7
lines changed

Lombiq.HelpfulLibraries.AspNetCore/Mvc/FromJsonQueryStringAttribute.cs

+2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using Microsoft.AspNetCore.Mvc;
22
using Microsoft.AspNetCore.Mvc.ModelBinding;
3+
using System;
34

45
namespace Lombiq.HelpfulLibraries.AspNetCore.Mvc;
56

7+
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = true)]
68
public sealed class FromJsonQueryStringAttribute : ModelBinderAttribute
79
{
810
public FromJsonQueryStringAttribute()

Lombiq.HelpfulLibraries.Cli/Extensions/CommandExtensions.cs

+12-3
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,26 @@ public static class CommandExtensions
1616
/// Executes a <see cref="Command"/> as a <c>dotnet</c> command that starts a long-running application, and waits
1717
/// for the app to be started.
1818
/// </summary>
19-
public static async Task ExecuteDotNetApplicationAsync(
19+
public static Task ExecuteDotNetApplicationAsync(
2020
this Command command,
2121
Action<StandardErrorCommandEvent>? stdErrHandler = default,
22+
CancellationToken cancellationToken = default) =>
23+
command.ExecuteUntilOutputAsync("Application started. Press Ctrl+C to shut down.", stdErrHandler, cancellationToken);
24+
25+
/// <summary>
26+
/// Executes a <see cref="Command"/> until the given output is received, then returns.
27+
/// </summary>
28+
public static async Task ExecuteUntilOutputAsync(
29+
this Command command,
30+
string outputToWaitFor,
31+
Action<StandardErrorCommandEvent>? stdErrHandler = default,
2232
CancellationToken cancellationToken = default)
2333
{
2434
await using var enumerator = command.ListenAsync(cancellationToken).GetAsyncEnumerator(cancellationToken);
2535

2636
while (await enumerator.MoveNextAsync())
2737
{
28-
if (enumerator.Current is StandardOutputCommandEvent stdOut &&
29-
stdOut.Text.ContainsOrdinalIgnoreCase("Application started. Press Ctrl+C to shut down."))
38+
if (enumerator.Current is StandardOutputCommandEvent stdOut && stdOut.Text.ContainsOrdinalIgnoreCase(outputToWaitFor))
3039
{
3140
return;
3241
}

Lombiq.HelpfulLibraries.OrchardCore/Contents/JsonSectionDisplayDriver.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Microsoft.AspNetCore.Authorization;
1+
using Microsoft.AspNetCore.Authorization;
22
using Microsoft.AspNetCore.Http;
33
using Microsoft.AspNetCore.Mvc.ModelBinding;
44
using OrchardCore.DisplayManagement.Entities;
@@ -33,7 +33,7 @@ protected JsonSectionDisplayDriver(
3333
_hca = hca;
3434
}
3535

36-
public async override Task<IDisplayResult> EditAsync(ISite model, TSection section, BuildEditorContext context) =>
36+
public override async Task<IDisplayResult> EditAsync(ISite model, TSection section, BuildEditorContext context) =>
3737
await AuthorizeAsync()
3838
? Initialize<JsonViewModel<TAdditionalData>>(
3939
ShapeType,

Lombiq.HelpfulLibraries.OrchardCore/TagHelpers/EditorFieldSetTagHelper.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ private static bool HasRequiredAttribute(ModelExpression modelExpression) =>
168168
.GetCustomAttributes(typeof(RequiredAttribute), inherit: false)
169169
.FirstOrDefault() is RequiredAttribute;
170170

171-
private static void AddBoolAttribute(IDictionary<string, object> attributes, bool value, string attributeName)
171+
private static void AddBoolAttribute(Dictionary<string, object> attributes, bool value, string attributeName)
172172
{
173173
if (value)
174174
{

Lombiq.HelpfulLibraries.OrchardCore/Users/PasswordHelper.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static string GenerateRandomPassword(int minLength)
3333
}
3434

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

3838
return password;
3939
}

0 commit comments

Comments
 (0)