-
Notifications
You must be signed in to change notification settings - Fork 722
feat: new extension API WithExecCommand
#10779
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
Closed
Closed
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7a96637
init
DeagleGross d792a64
impl?
DeagleGross 90906df
cleanup resources as well
DeagleGross 878dd12
merge main
DeagleGross 14ab65e
cleanup ContainerExecsMap as well
DeagleGross fe2dfed
address PR comments x1
DeagleGross 7e645d9
revert backchannel type rename
DeagleGross cb38034
address PR comments x1
DeagleGross 87db4da
stabilize and refactor
DeagleGross File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
173 changes: 173 additions & 0 deletions
173
src/Aspire.Hosting/ApplicationModel/ResourceCommandAnnotationBase.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Diagnostics; | ||
|
|
||
| namespace Aspire.Hosting.ApplicationModel; | ||
|
|
||
| /// <summary> | ||
| /// Represents a command annotation for a resource. | ||
| /// </summary> | ||
| [DebuggerDisplay("Type = {GetType().Name,nq}, Name = {Name}")] | ||
| public abstract class ResourceCommandAnnotationBase : IResourceAnnotation | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="ResourceCommandAnnotation"/> class. | ||
| /// </summary> | ||
| public ResourceCommandAnnotationBase( | ||
| string name, | ||
| string displayName, | ||
| string? displayDescription, | ||
| object? parameter, | ||
| string? confirmationMessage, | ||
| string? iconName, | ||
| IconVariant? iconVariant, | ||
| bool isHighlighted) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(name); | ||
| ArgumentNullException.ThrowIfNull(displayName); | ||
|
|
||
| Name = name; | ||
| DisplayName = displayName; | ||
| DisplayDescription = displayDescription; | ||
| Parameter = parameter; | ||
| ConfirmationMessage = confirmationMessage; | ||
| IconName = iconName; | ||
| IconVariant = iconVariant; | ||
| IsHighlighted = isHighlighted; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The name of command. The name uniquely identifies the command. | ||
| /// </summary> | ||
| public string Name { get; } | ||
|
|
||
| /// <summary> | ||
| /// The display name visible in UI. | ||
| /// </summary> | ||
| public string DisplayName { get; } | ||
|
|
||
| /// <summary> | ||
| /// Optional description of the command, to be shown in the UI. | ||
| /// Could be used as a tooltip. May be localized. | ||
| /// </summary> | ||
| public string? DisplayDescription { get; } | ||
|
|
||
| /// <summary> | ||
| /// Optional parameter that configures the command in some way. | ||
| /// Clients must return any value provided by the server when invoking the command. | ||
| /// </summary> | ||
| public object? Parameter { get; } | ||
|
|
||
| /// <summary> | ||
| /// When a confirmation message is specified, the UI will prompt with an OK/Cancel dialog | ||
| /// and the confirmation message before starting the command. | ||
| /// </summary> | ||
| public string? ConfirmationMessage { get; } | ||
|
|
||
| /// <summary> | ||
| /// The icon name for the command. The name should be a valid FluentUI icon name. https://aka.ms/fluentui-system-icons | ||
| /// </summary> | ||
| public string? IconName { get; } | ||
|
|
||
| /// <summary> | ||
| /// The icon variant for the command. | ||
| /// </summary> | ||
| public IconVariant? IconVariant { get; } | ||
|
|
||
| /// <summary> | ||
| /// A flag indicating whether the command is highlighted in the UI. | ||
| /// </summary> | ||
| public bool IsHighlighted { get; } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The icon variant. | ||
| /// </summary> | ||
| public enum IconVariant | ||
| { | ||
| /// <summary> | ||
| /// Regular variant of icons. | ||
| /// </summary> | ||
| Regular, | ||
| /// <summary> | ||
| /// Filled variant of icons. | ||
| /// </summary> | ||
| Filled | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// A factory for <see cref="ExecuteCommandResult"/>. | ||
| /// </summary> | ||
| public static class CommandResults | ||
| { | ||
| /// <summary> | ||
| /// Produces a success result. | ||
| /// </summary> | ||
| public static ExecuteCommandResult Success() => new() { Success = true }; | ||
|
|
||
| /// <summary> | ||
| /// Produces an unsuccessful result with an error message. | ||
| /// </summary> | ||
| /// <param name="errorMessage">An optional error message.</param> | ||
| public static ExecuteCommandResult Failure(string? errorMessage = null) => new() { Success = false, ErrorMessage = errorMessage }; | ||
|
|
||
| /// <summary> | ||
| /// Produces an unsuccessful result from an <see cref="Exception"/>. <see cref="Exception.Message"/> is used as the error message. | ||
| /// </summary> | ||
| /// <param name="exception">The exception to get the error message from.</param> | ||
| public static ExecuteCommandResult Failure(Exception exception) => Failure(exception.Message); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The result of executing a command. Returned from <see cref="ResourceCommandAnnotation.ExecuteCommand"/>. | ||
| /// </summary> | ||
| public sealed class ExecuteCommandResult | ||
| { | ||
| /// <summary> | ||
| /// A flag that indicates whether the command was successful. | ||
| /// </summary> | ||
| public required bool Success { get; init; } | ||
|
|
||
| /// <summary> | ||
| /// An optional error message that can be set when the command is unsuccessful. | ||
| /// </summary> | ||
| public string? ErrorMessage { get; init; } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Context for <see cref="ResourceCommandAnnotation.UpdateState"/>. | ||
| /// </summary> | ||
| public sealed class UpdateCommandStateContext | ||
| { | ||
| /// <summary> | ||
| /// The resource snapshot. | ||
| /// </summary> | ||
| public required CustomResourceSnapshot ResourceSnapshot { get; init; } | ||
|
|
||
| /// <summary> | ||
| /// The service provider. | ||
| /// </summary> | ||
| public required IServiceProvider ServiceProvider { get; init; } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Context for <see cref="ResourceCommandAnnotation.ExecuteCommand"/>. | ||
| /// </summary> | ||
| public sealed class ExecuteCommandContext | ||
| { | ||
| /// <summary> | ||
| /// The service provider. | ||
| /// </summary> | ||
| public required IServiceProvider ServiceProvider { get; init; } | ||
|
|
||
| /// <summary> | ||
| /// The resource name. | ||
| /// </summary> | ||
| public required string ResourceName { get; init; } | ||
|
|
||
| /// <summary> | ||
| /// The cancellation token. | ||
| /// </summary> | ||
| public required CancellationToken CancellationToken { get; init; } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.