Skip to content

Commit 3b27cdc

Browse files
Merged PR 110: added assembly scanner; default templates
2 parents 22b38ee + 2c38101 commit 3b27cdc

20 files changed

+408
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp3.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
</Project>
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
using System;
2+
using System.IO;
3+
using System.Linq;
4+
using System.Reflection;
5+
using System.Text.Json;
6+
using System.Text.Json.Serialization;
7+
8+
namespace AssemblyScanner
9+
{
10+
public class AssemblyInfo
11+
{
12+
public string FullName { get; set; }
13+
public string PublicKeyToken { get; set; }
14+
public string Name { get; set; }
15+
public string Location { get; set; }
16+
public string ImageRuntimeVersion { get; set; }
17+
public bool GlobalAssemblyCache { get; set; }
18+
public Version Version { get; set; }
19+
public string Title { get; set; }
20+
public string Configuration { get; set; }
21+
public string Description { get; set; }
22+
public string Company { get; set; }
23+
public string Product { get; set; }
24+
public string Copyright { get; set; }
25+
public string Trademark { get; set; }
26+
public string DelaySign { get; set; }
27+
public string KeyName { get; set; }
28+
public string ClsCompliant { get; set; }
29+
public string ComVisible { get; set; }
30+
public string IsJITTrackingEnabled { get; set; }
31+
public string IsJITOptimizerDisabled { get; set; }
32+
public string DebuggingFlags { get; set; }
33+
public string CompilationRelaxations { get; set; }
34+
public string WrapNonExceptionThrows { get; set; }
35+
public TypeInfo[] Types { get; set; }
36+
}
37+
38+
public class Error
39+
{
40+
public string Message { get; set; }
41+
public int Code { get; set; }
42+
}
43+
44+
public class TypeInfo
45+
{
46+
public string Name { get; set; }
47+
public string BaseType { get; set; }
48+
public string[] Interfaces { get; set; }
49+
}
50+
51+
static class Program
52+
{
53+
static string Error(int code, string message)
54+
{
55+
string json = JsonSerializer.Serialize(new Error() { Code = code, Message = message });
56+
57+
return json;
58+
}
59+
60+
static void Main(string[] args)
61+
{
62+
if (args.Length == 0)
63+
{
64+
Console.Write(Error(100, "No command line parameters present"));
65+
66+
return;
67+
}
68+
69+
var file = args[0];
70+
71+
if (!File.Exists(file))
72+
{
73+
Console.Write(Error(200, $"File {file} could not be found."));
74+
75+
return;
76+
}
77+
78+
var assembly = Assembly.LoadFrom(Path.GetFullPath(file));
79+
{
80+
var returnObject = new AssemblyInfo()
81+
{
82+
FullName = assembly.FullName.ToString(),
83+
PublicKeyToken = assembly.FullName.Substring(assembly.FullName.IndexOf("PublicKeyToken="))?.Replace("PublicKeyToken=", ""),
84+
Name = assembly.ManifestModule?.Name,
85+
Location = assembly.Location,
86+
ImageRuntimeVersion = assembly.ImageRuntimeVersion,
87+
GlobalAssemblyCache = assembly.GlobalAssemblyCache,
88+
Version = assembly.GetName().Version,
89+
Title = assembly.GetCustomProperty("Title", "Title"),
90+
Configuration = assembly.GetCustomProperty("Configuration", "Configuration"),
91+
Description = assembly.GetCustomProperty("Description", "Description"),
92+
Company = assembly.GetCustomProperty("Company", "Company"),
93+
Product = assembly.GetCustomProperty("Product", "Product"),
94+
Copyright = assembly.GetCustomProperty("Copyright", "Copyright"),
95+
Trademark = assembly.GetCustomProperty("Trademark", "Trademark"),
96+
DelaySign = assembly.GetCustomProperty("DelaySign", "DelaySign"),
97+
KeyName = assembly.GetCustomProperty("KeyName", "KeyName"),
98+
ClsCompliant = assembly.GetCustomProperty("ClsCompliant", "IsCompliant"),
99+
ComVisible = assembly.GetCustomProperty("ComVisible", "Value"),
100+
IsJITTrackingEnabled = assembly.GetCustomProperty("System.Diagnostics.DebuggableAttribute", "IsJITTrackingEnabled"),
101+
IsJITOptimizerDisabled = assembly.GetCustomProperty("System.Diagnostics.DebuggableAttribute", "IsJITOptimizerDisabled"),
102+
DebuggingFlags = assembly.GetCustomProperty("System.Diagnostics.DebuggableAttribute", "DebuggingFlags"),
103+
CompilationRelaxations = assembly.GetCustomProperty("CompilationRelaxations", "CompilationRelaxations"),
104+
WrapNonExceptionThrows = assembly.GetCustomProperty("System.Runtime.CompilerServices.RuntimeCompatibilityAttribute", "WrapNonExceptionThrows"),
105+
Types = assembly.GetExportedTypes()
106+
.Select(t => new TypeInfo()
107+
{
108+
Name = t.FullName,
109+
BaseType = t.BaseType.Name,
110+
Interfaces = t.GetInterfaces().Select(i => i.FullName).ToArray()
111+
}).ToArray()
112+
};
113+
114+
string json = JsonSerializer.Serialize(returnObject);
115+
Console.Write(json);
116+
}
117+
}
118+
119+
private static string GetCustomProperty(this Assembly assembly, string typeName, string property)
120+
{
121+
foreach (var attribute in assembly.GetCustomAttributes(false))
122+
{
123+
if (attribute.GetType().ToString().Contains(typeName))
124+
{
125+
if (!string.IsNullOrEmpty(property))
126+
{
127+
try
128+
{
129+
return attribute.GetType().GetProperty(property).GetValue(attribute).ToString();
130+
}
131+
catch (Exception)
132+
{
133+
return null;
134+
}
135+
}
136+
else
137+
{
138+
return attribute.ToString();
139+
}
140+
}
141+
}
142+
143+
return null;
144+
}
145+
}
146+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"profiles": {
3+
"AssemblyScanner": {
4+
"commandName": "Project",
5+
"commandLineArgs": "\"C:\\Dev\\Trash\\SamplePlugin\\bin\\Debug\\net452\\SamplePlugin.dll\""
6+
}
7+
}
8+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net452</TargetFramework>
5+
<SignAssembly>true</SignAssembly>
6+
<AssemblyOriginatorKeyFile>SamplePlugin.snk</AssemblyOriginatorKeyFile>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.CrmSdk.CoreAssemblies" Version="8.0.2.1" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29418.71
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SamplePlugin", "SamplePlugin.csproj", "{CC86F50E-554F-456F-B919-9D059910C52F}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{CC86F50E-554F-456F-B919-9D059910C52F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{CC86F50E-554F-456F-B919-9D059910C52F}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{CC86F50E-554F-456F-B919-9D059910C52F}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{CC86F50E-554F-456F-B919-9D059910C52F}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {5437CB88-6594-4A79-80E8-92DCB1AD7795}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using Microsoft.Xrm.Sdk;
3+
4+
namespace SamplePlugin
5+
{
6+
public class SamplePlugin : IPlugin
7+
{
8+
public void Execute(IServiceProvider serviceProvider)
9+
{
10+
var tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
11+
var executionContext = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
12+
13+
tracingService.Trace("Plugin started");
14+
}
15+
}
16+
}
596 Bytes
Binary file not shown.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net452</TargetFramework>
5+
<SignAssembly>true</SignAssembly>
6+
<AssemblyOriginatorKeyFile>SamplePlugin.snk</AssemblyOriginatorKeyFile>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.CrmSdk.CoreAssemblies" Version="8.1.0.2" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29418.71
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SamplePlugin", "SamplePlugin.csproj", "{CC86F50E-554F-456F-B919-9D059910C52F}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{CC86F50E-554F-456F-B919-9D059910C52F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{CC86F50E-554F-456F-B919-9D059910C52F}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{CC86F50E-554F-456F-B919-9D059910C52F}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{CC86F50E-554F-456F-B919-9D059910C52F}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {5437CB88-6594-4A79-80E8-92DCB1AD7795}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using Microsoft.Xrm.Sdk;
3+
4+
namespace SamplePlugin
5+
{
6+
public class SamplePlugin : IPlugin
7+
{
8+
public void Execute(IServiceProvider serviceProvider)
9+
{
10+
var tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
11+
var executionContext = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
12+
13+
tracingService.Trace("Plugin started");
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)