-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3efff90
commit 771f4bc
Showing
1 changed file
with
97 additions
and
0 deletions.
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
src/Standard/NDF/CodeFactory.Automation.Standard.NDF/RegisterTransientServices.cs
This file contains 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,97 @@ | ||
using CodeFactory.WinVs; | ||
using CodeFactory.WinVs.Commands; | ||
using CodeFactory.WinVs.Commands.SolutionExplorer; | ||
using CodeFactory.WinVs.Logging; | ||
using CodeFactory.WinVs.Models.CSharp; | ||
using CodeFactory.WinVs.Models.CSharp.Builder; | ||
using CodeFactory.WinVs.Models.ProjectSystem; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using CodeFactory.Automation.Standard.NDF.Logic; | ||
|
||
namespace CodeFactory.Automation.Standard.NDF | ||
{ | ||
/// <summary> | ||
/// Code factory command for automation of a project when selected from solution explorer. | ||
/// </summary> | ||
public class RegisterTransientServices : ProjectCommandBase | ||
{ | ||
private static readonly string commandTitle = "Register Transient Services"; | ||
private static readonly string commandDescription = "Registers Transient classes with a NDF dependency injection loader for a target project."; | ||
|
||
#pragma warning disable CS1998 | ||
|
||
/// <inheritdoc /> | ||
public RegisterTransientServices(ILogger logger, IVsActions vsActions) : base(logger, vsActions, commandTitle, commandDescription) | ||
{ | ||
//Intentionally blank | ||
} | ||
#pragma warning disable CS1998 | ||
|
||
#region External Configuration | ||
|
||
/// <summary> | ||
/// The fully qualified name of the command to be used with configuration. | ||
/// </summary> | ||
public static string Type = typeof(RegisterTransientServices).FullName; | ||
|
||
/// <summary> | ||
/// Loads the external configuration definition for this command. | ||
/// </summary> | ||
/// <returns>Will return the command configuration or null if this command does not support external configurations.</returns> | ||
public override ConfigCommand LoadExternalConfigDefinition() | ||
{ | ||
return null; | ||
} | ||
#endregion | ||
|
||
#region Overrides of VsCommandBase<VsProject> | ||
|
||
/// <summary> | ||
/// Validation logic that will determine if this command should be enabled for execution. | ||
/// </summary> | ||
/// <param name="result">The target model data that will be used to determine if this command should be enabled.</param> | ||
/// <returns>Boolean flag that will tell code factory to enable this command or disable it.</returns> | ||
public override async Task<bool> EnableCommandAsync(VsProject result) | ||
{ | ||
//Result that determines if the command is enabled and visible in the context menu for execution. | ||
bool isEnabled = false; | ||
|
||
try | ||
{ | ||
isEnabled = await result.CanRegisterTransientClassesAsync(); | ||
} | ||
catch (Exception unhandledError) | ||
{ | ||
_logger.Error($"The following unhandled error occurred while checking if the solution explorer project command {commandTitle} is enabled. ", | ||
unhandledError); | ||
isEnabled = false; | ||
} | ||
|
||
return isEnabled; | ||
} | ||
|
||
/// <summary> | ||
/// Code factory framework calls this method when the command has been executed. | ||
/// </summary> | ||
/// <param name="result">The code factory model that has generated and provided to the command to process.</param> | ||
public override async Task ExecuteCommandAsync(VsProject result) | ||
{ | ||
try | ||
{ | ||
await VisualStudioActions.RegisterTransientClassesAsync(result); | ||
} | ||
catch (Exception unhandledError) | ||
{ | ||
_logger.Error($"The following unhandled error occurred while executing the solution explorer project command {commandTitle}. ", | ||
unhandledError); | ||
|
||
} | ||
} | ||
|
||
#endregion | ||
} | ||
} |