Skip to content

Commit 26b5ab5

Browse files
authored
Merge pull request #6 from CodeFactoryLLC/StandardNDF
Standard NDF initial release
2 parents cc6b2a7 + 771f4bc commit 26b5ab5

File tree

7 files changed

+449
-0
lines changed

7 files changed

+449
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProductVersion>8.0.30703</ProductVersion>
8+
<SchemaVersion>2.0</SchemaVersion>
9+
<ProjectGuid>{CF0F98B6-E6C9-4BBA-B61F-20E00260676F}</ProjectGuid>
10+
<OutputType>Library</OutputType>
11+
<AppDesignerFolder>Properties</AppDesignerFolder>
12+
<RootNamespace>CodeFactory.Automation.Standard.NDF.Logic</RootNamespace>
13+
<AssemblyName>CodeFactory.Automation.Standard.NDF.Logic</AssemblyName>
14+
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
15+
<FileAlignment>512</FileAlignment>
16+
<StartAction>Program</StartAction>
17+
<StartProgram Condition="'$(DevEnvDir)' != ''">$(DevEnvDir)devenv.exe</StartProgram>
18+
</PropertyGroup>
19+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
20+
<DebugSymbols>true</DebugSymbols>
21+
<DebugType>full</DebugType>
22+
<Optimize>false</Optimize>
23+
<OutputPath>bin\Debug\</OutputPath>
24+
<DefineConstants>DEBUG;TRACE</DefineConstants>
25+
<ErrorReport>prompt</ErrorReport>
26+
<WarningLevel>4</WarningLevel>
27+
</PropertyGroup>
28+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
29+
<DebugType>pdbonly</DebugType>
30+
<Optimize>true</Optimize>
31+
<OutputPath>bin\Release\</OutputPath>
32+
<DefineConstants>TRACE</DefineConstants>
33+
<ErrorReport>prompt</ErrorReport>
34+
<WarningLevel>4</WarningLevel>
35+
</PropertyGroup>
36+
<ItemGroup>
37+
<PackageReference Include="CodeFactory.WinVs.SDK" Version="2.23157.1-PreRelease" />
38+
<Reference Include="System" />
39+
<Reference Include="System.Core" />
40+
<Reference Include="System.Xml.Linq" />
41+
<Reference Include="System.Data.DataSetExtensions" />
42+
<Reference Include="Microsoft.CSharp" />
43+
<Reference Include="System.Data" />
44+
<Reference Include="System.Xml" />
45+
<Reference Include="PresentationCore" />
46+
<Reference Include="PresentationFramework" />
47+
<Reference Include="System.Xaml" />
48+
<Reference Include="WindowsBase" />
49+
</ItemGroup>
50+
<ItemGroup>
51+
<Compile Include="Properties\AssemblyInfo.cs" />
52+
</ItemGroup>
53+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
54+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
55+
Other similar extension points exist, see Microsoft.Common.targets.
56+
<Target Name="BeforeBuild">
57+
</Target>
58+
<Target Name="AfterBuild">
59+
</Target> -->
60+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using CodeFactory.WinVs;
2+
using System.Reflection;
3+
using System.Runtime.CompilerServices;
4+
using System.Runtime.InteropServices;
5+
6+
// General Information about an assembly is controlled through the following
7+
// set of attributes. Change these attribute values to modify the information
8+
// associated with an assembly.
9+
[assembly: AssemblyTitle("CodeFactory.Automation.Standard.NDF.Logic")]
10+
[assembly: AssemblyDescription("")]
11+
[assembly: AssemblyConfiguration("")]
12+
[assembly: AssemblyCompany("")]
13+
[assembly: AssemblyProduct("CodeFactory.Automation.Standard.NDF.Logic")]
14+
[assembly: AssemblyCopyright("Copyright © 2023")]
15+
[assembly: AssemblyTrademark("")]
16+
[assembly: AssemblyCulture("")]
17+
18+
// Setting ComVisible to false makes the types in this assembly not visible
19+
// to COM components. If you need to access a type in this assembly from
20+
// COM, set the ComVisible attribute to true on that type.
21+
[assembly: ComVisible(false)]
22+
23+
// The following GUID is for the ID of the typelib if this project is exposed to COM
24+
[assembly: Guid("cf0f98b6-e6c9-4bba-b61f-20e00260676f")]
25+
26+
// Version information for an assembly consists of the following four values:
27+
//
28+
// Major Version
29+
// Minor Version
30+
// Build Number
31+
// Revision
32+
//
33+
// You can specify all the values or you can default the Build and Revision Numbers
34+
// by using the '*' as shown below:
35+
// [assembly: AssemblyVersion("1.0.*")]
36+
[assembly: AssemblyVersion("1.0.0.0")]
37+
[assembly: AssemblyFileVersion("1.0.0.0")]
38+
[assembly: AssemblyCFEnvironment("CFVSW")]
39+
[assembly: AssemblyCFSdkVersion("2.23157.0.1")]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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.Logic;
14+
15+
namespace CodeFactory.Automation.Standard
16+
{
17+
/// <summary>
18+
/// Code factory command for automation of a C# document when selected from a project in solution explorer.
19+
/// </summary>
20+
public class AddMissingMembers : CSharpSourceCommandBase
21+
{
22+
private static readonly string commandTitle = "Add Missing Interface Members";
23+
private static readonly string commandDescription = "Adds interface members that are missing from the implementation of the class.";
24+
25+
/// <summary>
26+
/// Name of the Microsoft logging library.
27+
/// </summary>
28+
private const string MicrosoftLoggingNamespace = "Microsoft.Extensions.Logging";
29+
30+
#pragma warning disable CS1998
31+
32+
/// <inheritdoc />
33+
public AddMissingMembers(ILogger logger, IVsActions vsActions) : base(logger, vsActions, commandTitle, commandDescription)
34+
{
35+
//Intentionally blank
36+
}
37+
38+
#region External Configuration
39+
40+
/// <summary>
41+
/// The fully qualified name of the command to be used with configuration.
42+
/// </summary>
43+
public static string Type = typeof(AddMissingMembers).FullName;
44+
45+
/// <summary>
46+
/// Loads the external configuration definition for this command.
47+
/// </summary>
48+
/// <returns>Will return the command configuration or null if this command does not support external configurations.</returns>
49+
public override ConfigCommand LoadExternalConfigDefinition()
50+
{
51+
return null;
52+
}
53+
#endregion
54+
55+
#region Overrides of VsCommandBase<IVsCSharpDocument>
56+
57+
/// <summary>
58+
/// Validation logic that will determine if this command should be enabled for execution.
59+
/// </summary>
60+
/// <param name="result">The target model data that will be used to determine if this command should be enabled.</param>
61+
/// <returns>Boolean flag that will tell code factory to enable this command or disable it.</returns>
62+
public override async Task<bool> EnableCommandAsync(VsCSharpSource result)
63+
{
64+
//Result that determines if the command is enabled and visible in the context menu for execution.
65+
bool isEnabled = false;
66+
67+
try
68+
{
69+
//Getting the first class in the source code file.
70+
var sourceClass = result.SourceCode?.Classes?.FirstOrDefault();
71+
72+
//enable if only a class was found.
73+
isEnabled = sourceClass != null;
74+
75+
//If enabled if no interface members are missing then do not show.
76+
if (isEnabled) isEnabled = sourceClass.GetMissingInterfaceMembers().Any();
77+
78+
}
79+
catch (Exception unhandledError)
80+
{
81+
_logger.Error($"The following unhandled error occurred while checking if the solution explorer C# document command {commandTitle} is enabled. ",
82+
unhandledError);
83+
isEnabled = false;
84+
}
85+
86+
return isEnabled;
87+
}
88+
89+
/// <summary>
90+
/// Code factory framework calls this method when the command has been executed.
91+
/// </summary>
92+
/// <param name="result">The code factory model that has generated and provided to the command to process.</param>
93+
public override async Task ExecuteCommandAsync(VsCSharpSource result)
94+
{
95+
try
96+
{
97+
//Getting the hosting project
98+
var project = await result.GetHostingProjectAsync()
99+
?? throw new CodeFactoryException($"Cannot load the project information for C# source code file '{result.Name}' cannot add members.");
100+
101+
var references = await project.GetProjectReferencesAsync();
102+
103+
var hasLogging = references.Any(r => r.Name.StartsWith(MicrosoftLoggingNamespace));
104+
105+
var sourceClass = result?.SourceCode?.Classes?.FirstOrDefault()
106+
?? throw new CodeFactoryException(
107+
"The class could not be loaded cannot add members.");
108+
109+
var updatedClass = await VisualStudioActions.AddMissingMembersStandardAsync(result.SourceCode, sourceClass, hasLogging);
110+
111+
}
112+
catch (Exception unhandledError)
113+
{
114+
_logger.Error($"The following unhandled error occurred while executing the solution explorer C# document command {commandTitle}. ",
115+
unhandledError);
116+
117+
}
118+
119+
}
120+
121+
#endregion
122+
}
123+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProductVersion>8.0.30703</ProductVersion>
8+
<SchemaVersion>2.0</SchemaVersion>
9+
<ProjectGuid>{DF91E081-52B7-4698-AB4A-9ABAE2DBEEBE}</ProjectGuid>
10+
<OutputType>Library</OutputType>
11+
<AppDesignerFolder>Properties</AppDesignerFolder>
12+
<RootNamespace>CodeFactory.Automation.Standard.NDF</RootNamespace>
13+
<AssemblyName>CodeFactory.Automation.Standard.NDF</AssemblyName>
14+
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
15+
<FileAlignment>512</FileAlignment>
16+
<StartAction>Program</StartAction>
17+
<StartProgram Condition="'$(DevEnvDir)' != ''">$(DevEnvDir)devenv.exe</StartProgram>
18+
</PropertyGroup>
19+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
20+
<DebugSymbols>true</DebugSymbols>
21+
<DebugType>full</DebugType>
22+
<Optimize>false</Optimize>
23+
<OutputPath>bin\Debug\</OutputPath>
24+
<DefineConstants>DEBUG;TRACE</DefineConstants>
25+
<ErrorReport>prompt</ErrorReport>
26+
<WarningLevel>4</WarningLevel>
27+
</PropertyGroup>
28+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
29+
<DebugType>pdbonly</DebugType>
30+
<Optimize>true</Optimize>
31+
<OutputPath>bin\Release\</OutputPath>
32+
<DefineConstants>TRACE</DefineConstants>
33+
<ErrorReport>prompt</ErrorReport>
34+
<WarningLevel>4</WarningLevel>
35+
</PropertyGroup>
36+
<ItemGroup>
37+
<PackageReference Include="CodeFactory.WinVs.SDK" Version="2.23157.1-PreRelease" />
38+
<Reference Include="System" />
39+
<Reference Include="System.Core" />
40+
<Reference Include="System.Xml.Linq" />
41+
<Reference Include="System.Data.DataSetExtensions" />
42+
<Reference Include="Microsoft.CSharp" />
43+
<Reference Include="System.Data" />
44+
<Reference Include="System.Xml" />
45+
<Reference Include="PresentationCore" />
46+
<Reference Include="PresentationFramework" />
47+
<Reference Include="System.Xaml" />
48+
<Reference Include="WindowsBase" />
49+
</ItemGroup>
50+
<ItemGroup>
51+
<Compile Include="Properties\AssemblyInfo.cs" />
52+
</ItemGroup>
53+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
54+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
55+
Other similar extension points exist, see Microsoft.Common.targets.
56+
<Target Name="BeforeBuild">
57+
</Target>
58+
<Target Name="AfterBuild">
59+
</Target> -->
60+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using CodeFactory.WinVs;
2+
using System.Reflection;
3+
using System.Runtime.CompilerServices;
4+
using System.Runtime.InteropServices;
5+
6+
// General Information about an assembly is controlled through the following
7+
// set of attributes. Change these attribute values to modify the information
8+
// associated with an assembly.
9+
[assembly: AssemblyTitle("CodeFactory.Automation.Standard.NDF")]
10+
[assembly: AssemblyDescription("")]
11+
[assembly: AssemblyConfiguration("")]
12+
[assembly: AssemblyCompany("")]
13+
[assembly: AssemblyProduct("CodeFactory.Automation.Standard.NDF")]
14+
[assembly: AssemblyCopyright("Copyright © 2023")]
15+
[assembly: AssemblyTrademark("")]
16+
[assembly: AssemblyCulture("")]
17+
18+
// Setting ComVisible to false makes the types in this assembly not visible
19+
// to COM components. If you need to access a type in this assembly from
20+
// COM, set the ComVisible attribute to true on that type.
21+
[assembly: ComVisible(false)]
22+
23+
// The following GUID is for the ID of the typelib if this project is exposed to COM
24+
[assembly: Guid("df91e081-52b7-4698-ab4a-9abae2dbeebe")]
25+
26+
// Version information for an assembly consists of the following four values:
27+
//
28+
// Major Version
29+
// Minor Version
30+
// Build Number
31+
// Revision
32+
//
33+
// You can specify all the values or you can default the Build and Revision Numbers
34+
// by using the '*' as shown below:
35+
// [assembly: AssemblyVersion("1.0.*")]
36+
[assembly: AssemblyVersion("1.0.0.0")]
37+
[assembly: AssemblyFileVersion("1.0.0.0")]
38+
[assembly: AssemblyCFEnvironment("CFVSW")]
39+
[assembly: AssemblyCFSdkVersion("2.23157.0.1")]

0 commit comments

Comments
 (0)