Skip to content

Commit 771f4bc

Browse files
committed
NDF Integration
1 parent 3efff90 commit 771f4bc

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
using CodeFactory.WinVs;
2+
using CodeFactory.WinVs.Commands;
3+
using CodeFactory.WinVs.Commands.SolutionExplorer;
4+
using CodeFactory.WinVs.Logging;
5+
using CodeFactory.WinVs.Models.CSharp;
6+
using CodeFactory.WinVs.Models.CSharp.Builder;
7+
using CodeFactory.WinVs.Models.ProjectSystem;
8+
using System;
9+
using System.Collections.Generic;
10+
using System.Linq;
11+
using System.Text;
12+
using System.Threading.Tasks;
13+
using CodeFactory.Automation.Standard.NDF.Logic;
14+
15+
namespace CodeFactory.Automation.Standard.NDF
16+
{
17+
/// <summary>
18+
/// Code factory command for automation of a project when selected from solution explorer.
19+
/// </summary>
20+
public class RegisterTransientServices : ProjectCommandBase
21+
{
22+
private static readonly string commandTitle = "Register Transient Services";
23+
private static readonly string commandDescription = "Registers Transient classes with a NDF dependency injection loader for a target project.";
24+
25+
#pragma warning disable CS1998
26+
27+
/// <inheritdoc />
28+
public RegisterTransientServices(ILogger logger, IVsActions vsActions) : base(logger, vsActions, commandTitle, commandDescription)
29+
{
30+
//Intentionally blank
31+
}
32+
#pragma warning disable CS1998
33+
34+
#region External Configuration
35+
36+
/// <summary>
37+
/// The fully qualified name of the command to be used with configuration.
38+
/// </summary>
39+
public static string Type = typeof(RegisterTransientServices).FullName;
40+
41+
/// <summary>
42+
/// Loads the external configuration definition for this command.
43+
/// </summary>
44+
/// <returns>Will return the command configuration or null if this command does not support external configurations.</returns>
45+
public override ConfigCommand LoadExternalConfigDefinition()
46+
{
47+
return null;
48+
}
49+
#endregion
50+
51+
#region Overrides of VsCommandBase<VsProject>
52+
53+
/// <summary>
54+
/// Validation logic that will determine if this command should be enabled for execution.
55+
/// </summary>
56+
/// <param name="result">The target model data that will be used to determine if this command should be enabled.</param>
57+
/// <returns>Boolean flag that will tell code factory to enable this command or disable it.</returns>
58+
public override async Task<bool> EnableCommandAsync(VsProject result)
59+
{
60+
//Result that determines if the command is enabled and visible in the context menu for execution.
61+
bool isEnabled = false;
62+
63+
try
64+
{
65+
isEnabled = await result.CanRegisterTransientClassesAsync();
66+
}
67+
catch (Exception unhandledError)
68+
{
69+
_logger.Error($"The following unhandled error occurred while checking if the solution explorer project command {commandTitle} is enabled. ",
70+
unhandledError);
71+
isEnabled = false;
72+
}
73+
74+
return isEnabled;
75+
}
76+
77+
/// <summary>
78+
/// Code factory framework calls this method when the command has been executed.
79+
/// </summary>
80+
/// <param name="result">The code factory model that has generated and provided to the command to process.</param>
81+
public override async Task ExecuteCommandAsync(VsProject result)
82+
{
83+
try
84+
{
85+
await VisualStudioActions.RegisterTransientClassesAsync(result);
86+
}
87+
catch (Exception unhandledError)
88+
{
89+
_logger.Error($"The following unhandled error occurred while executing the solution explorer project command {commandTitle}. ",
90+
unhandledError);
91+
92+
}
93+
}
94+
95+
#endregion
96+
}
97+
}

0 commit comments

Comments
 (0)