-
Notifications
You must be signed in to change notification settings - Fork 3
Collect environment #94
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
Changes from all commits
1c9363c
742f554
709e8c4
6375955
c3a8c03
331051f
649b880
d7a3a56
4ce1f53
6eeac63
9309643
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,4 +83,61 @@ public IEnumerable<ICommandDescription> GetAllCommands() | |
| { | ||
| return new List<ICommandDescription>(_commands.Values); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public IControllerEnvironmentContext GetEnvironment(ICommandFactory commandFactory) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(commandFactory); | ||
|
|
||
| var controllerEnvironment = new ControllerEnvironmentContext(); | ||
| foreach (var commandDescription in GetAllCommands()) | ||
| { | ||
| ApplyDefaultEnvironment(controllerEnvironment, commandDescription, commandFactory); | ||
| } | ||
|
|
||
| return controllerEnvironment; | ||
| } | ||
|
|
||
| private static void ApplyDefaultEnvironment(IControllerEnvironmentContext controllerEnvironment, ICommandDescription commandDescription, ICommandFactory commandFactory, int depth = 0) | ||
| { | ||
| if (!string.IsNullOrWhiteSpace(commandDescription.FullTypeName)) | ||
| { | ||
| AddCommandDefaults(controllerEnvironment, commandDescription, commandFactory); | ||
| } | ||
|
|
||
| if (commandDescription.SubCommands.Count == 0) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| foreach (var subCommand in commandDescription.SubCommands.Values) | ||
| { | ||
| AddCommandDefaults(controllerEnvironment, subCommand, commandFactory); | ||
| } | ||
| } | ||
|
Comment on lines
101
to
117
|
||
|
|
||
| private static void AddCommandDefaults(IControllerEnvironmentContext controllerEnvironment, ICommandDescription commandDescription, ICommandFactory commandFactory) | ||
| { | ||
| var commandInstance = commandFactory.CreateCommand(commandDescription.FullTypeName, commandDescription.PackageDescription.FullPath); | ||
| try | ||
| { | ||
| var defaultEnvironment = commandInstance.GetDefaultEnvironment(); | ||
| if (defaultEnvironment.Count == 0) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| var commandName = NamesValidator.GetValidCommandName(commandDescription.BaseCommand); | ||
| controllerEnvironment.UpdateEnvironment(defaultEnvironment, commandName); | ||
| } | ||
| finally | ||
| { | ||
| commandInstance | ||
| .DisposeAsync() | ||
| .AsTask() | ||
| .ConfigureAwait(false) | ||
| .GetAwaiter() | ||
| .GetResult(); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.