Skip to content

Commit 6a9fa9d

Browse files
committed
Add custom sln for generation docs
1 parent 161581a commit 6a9fa9d

14 files changed

Lines changed: 1527 additions & 0 deletions
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35707.178 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SchemaDocumentationGenerator", "SchemaDocumentationGenerator\SchemaDocumentationGenerator.csproj", "{86DB3A0B-1F04-40F4-8591-807528B20488}"
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+
{86DB3A0B-1F04-40F4-8591-807528B20488}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{86DB3A0B-1F04-40F4-8591-807528B20488}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{86DB3A0B-1F04-40F4-8591-807528B20488}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{86DB3A0B-1F04-40F4-8591-807528B20488}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.ComponentModel;
5+
using System.Linq;
6+
using System.Reflection;
7+
using System.Text;
8+
using System.Text.RegularExpressions;
9+
using System.Threading.Tasks;
10+
11+
namespace SchemaDocumentationGenerator
12+
{
13+
public static class AssemblyLoader
14+
{
15+
[Description("Loads all .dll assemblies with names ending with oM, _Engine and _Adapter (with optional suffixes) from a given folder.")]
16+
public static List<Assembly> LoadAlloMAssemblies(List<string> organisations)
17+
{
18+
string regexFilter = @"oM$";
19+
List<Assembly> result = new List<Assembly>();
20+
21+
string folder = BHoMFolder();
22+
23+
Regex regex;
24+
if (!string.IsNullOrWhiteSpace(regexFilter))
25+
regex = new Regex(regexFilter);
26+
else
27+
regex = new Regex(".*");
28+
29+
SearchOption searchOption = SearchOption.TopDirectoryOnly;
30+
foreach (string file in Directory.GetFiles(folder, "*.dll", searchOption))
31+
{
32+
string name = Path.GetFileNameWithoutExtension(file);
33+
if (regex.IsMatch(name))
34+
{
35+
Assembly loaded = Assembly.LoadFrom(file);
36+
if (loaded != null && loaded.IsOmAssembly() && loaded.IsInOrg(organisations) && Settings.AssemblyIncluded.TryGetValue(loaded.GetName().Name, out bool included) && included)
37+
result.Add(loaded);
38+
}
39+
}
40+
41+
return result;
42+
}
43+
44+
[Description("Loads all .dll assemblies with names ending with oM, _Engine and _Adapter (with optional suffixes) from a given folder.")]
45+
public static List<Assembly> LoadAllEngineAssemblies(List<string> organisations)
46+
{
47+
string regexFilter = @"_Engine$";
48+
List<Assembly> result = new List<Assembly>();
49+
50+
string folder = BHoMFolder();
51+
52+
Regex regex;
53+
if (!string.IsNullOrWhiteSpace(regexFilter))
54+
regex = new Regex(regexFilter);
55+
else
56+
regex = new Regex(".*");
57+
58+
SearchOption searchOption = SearchOption.TopDirectoryOnly;
59+
foreach (string file in Directory.GetFiles(folder, "*.dll", searchOption))
60+
{
61+
string name = Path.GetFileNameWithoutExtension(file);
62+
if (regex.IsMatch(name))
63+
{
64+
Assembly loaded = Assembly.LoadFrom(file);
65+
if (loaded != null && loaded.IsEngineAssembly() && loaded.IsInOrg(organisations))
66+
result.Add(loaded);
67+
}
68+
}
69+
70+
return result;
71+
}
72+
73+
public static string BHoMFolder()
74+
{
75+
return System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonApplicationData), "BHoM", "Assemblies");
76+
}
77+
78+
[Description("Checks whether a given assembly is a BHoM oM assembly.")]
79+
public static bool IsOmAssembly(this Assembly assembly)
80+
{
81+
return assembly != null && assembly.GetName().Name.IsOmAssembly();
82+
}
83+
84+
/***************************************************/
85+
86+
[Description("Checks whether a given assembly name follows the BHoM oM assembly naming convention.")]
87+
public static bool IsOmAssembly(this string assemblyName)
88+
{
89+
return assemblyName != null && (assemblyName == "BHoM" || assemblyName.EndsWith("_oM") || assemblyName.Contains("_oM_"));
90+
}
91+
92+
/***************************************************/
93+
94+
[Description("Checks whether a given assembly is a BHoM oM assembly.")]
95+
public static bool IsEngineAssembly(this Assembly assembly)
96+
{
97+
return assembly != null && assembly.GetName().Name.IsEngineAssembly();
98+
}
99+
100+
/***************************************************/
101+
102+
[Description("Checks whether a given assembly name follows the BHoM oM assembly naming convention.")]
103+
public static bool IsEngineAssembly(this string assemblyName)
104+
{
105+
return assemblyName != null && (assemblyName.EndsWith("_Engine") || assemblyName.Contains("_Engine_"));
106+
}
107+
108+
/***************************************************/
109+
110+
[Description("Checks whether a given assembly name follows the BHoM oM assembly naming convention.")]
111+
public static bool IsInOrg(this Assembly assembly, List<string> orgs)
112+
{
113+
AssemblyDescriptionAttribute atr = assembly.GetCustomAttribute< AssemblyDescriptionAttribute>();
114+
if (atr != null)
115+
{
116+
return orgs.Any(x => atr.Description.Contains($"github.com/{x}"));
117+
}
118+
return false;
119+
}
120+
121+
/***************************************************/
122+
}
123+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.ComponentModel;
5+
using System.Linq;
6+
using System.Reflection;
7+
using System.Text;
8+
using System.Text.RegularExpressions;
9+
using System.Threading.Tasks;
10+
11+
namespace SchemaDocumentationGenerator
12+
{
13+
public static class ExtensionMethodsExtractor
14+
{
15+
[Description("Loads all .dll assemblies with names ending with oM, _Engine and _Adapter (with optional suffixes) from a given folder.")]
16+
public static Dictionary<Type, List<MethodInfo>> GetAllExtensionMethods(List<Assembly> engineAssemblies)
17+
{
18+
Dictionary<Type, List<MethodInfo>> extensionMethods = new Dictionary<Type, List<MethodInfo>>();
19+
20+
foreach (Assembly assembly in engineAssemblies)
21+
{
22+
try
23+
{
24+
25+
26+
foreach (Type type in assembly.GetTypes())
27+
{
28+
if (type.Name == "Query")
29+
{
30+
List<MethodInfo> allMethods = type.GetMethods(BindingFlags.Static | BindingFlags.Public).ToList();
31+
32+
List<MethodInfo> methods = allMethods.Where(x =>
33+
{
34+
var parameters = x.GetParameters();
35+
36+
if(parameters.Length == 0) //Rule out methods with no parameters
37+
return false;
38+
39+
if (parameters.Length == 1) //Keep methods with exactly one parameter
40+
return true;
41+
42+
//ALso keep for which the only additional parameters are tolerance parameters
43+
//Filtered as need to be double type with default value and name containing tol
44+
//Doing this to get methods like Area included (currently has a tolerance to check if curves are closed
45+
return parameters.Skip(1).All(x => x.HasDefaultValue);
46+
47+
}).ToList();
48+
49+
foreach (MethodInfo method in methods)
50+
{
51+
if (method.IsGenericMethod)
52+
{
53+
//TODO
54+
}
55+
else
56+
{
57+
Type paramType = method.GetParameters()[0].ParameterType;
58+
if (!extensionMethods.ContainsKey(paramType))
59+
extensionMethods[paramType] = new List<MethodInfo>();
60+
61+
extensionMethods[paramType].Add(method);
62+
}
63+
}
64+
}
65+
}
66+
}
67+
catch (Exception e)
68+
{
69+
Console.WriteLine(e.Message);
70+
71+
}
72+
}
73+
74+
return extensionMethods;
75+
}
76+
77+
}
78+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+

2+
3+
using BH.oM.Base;
4+
using SchemaDocumentationGenerator;
5+
using System.Reflection;
6+
7+
Console.WriteLine("Loading Settings.");
8+
Settings.LoadSettings(@"C:\Users\INaslund\Buro Happold\Design & Technology - Dev Docs\00756_oM_Documentation\oM_categorisation.csv");
9+
10+
Console.WriteLine("Loading Engine assemblies.");
11+
List<Assembly> engineAssemblies = AssemblyLoader.LoadAllEngineAssemblies(new List<string> { "BHoM" });
12+
Console.WriteLine("Extracting query methods.");
13+
Dictionary<Type, List<MethodInfo>> methods = ExtensionMethodsExtractor.GetAllExtensionMethods(engineAssemblies);
14+
15+
Console.WriteLine("Loading oM Asseblies");
16+
List<Assembly> oMAssemblies = AssemblyLoader.LoadAlloMAssemblies(new List<string> { "BHoM" });
17+
18+
Console.WriteLine("Mapping types");
19+
foreach (Assembly assembly in oMAssemblies)
20+
{
21+
foreach (Type type in assembly.GetTypes())
22+
{
23+
TypeToMarkdown.MapDependecies(type);
24+
}
25+
}
26+
27+
28+
TypeToMarkdown.SetupAssemblyFolders(@"C:\BHoMBot\Github", oMAssemblies);
29+
30+
foreach (Assembly assembly in oMAssemblies)
31+
{
32+
Console.WriteLine($"Generating {assembly.GetName().Name} type docs");
33+
foreach (Type type in assembly.GetTypes())
34+
{
35+
if (!(type.IsAbstract && type.IsSealed) && (type.IsEnum || typeof(IObject).IsAssignableFrom(type)))
36+
{
37+
TypeToMarkdown.WriteTypeToMarkdown(@"C:\Github\schemaDocumentation\docs\", type, methods);
38+
}
39+
}
40+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="System.Drawing.Common" Version="9.0.3" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<Reference Include="BHoM">
16+
<HintPath>..\..\..\..\..\ProgramData\BHoM\Assemblies\BHoM.dll</HintPath>
17+
</Reference>
18+
<Reference Include="Quantities_oM">
19+
<HintPath>..\..\..\..\..\ProgramData\BHoM\Assemblies\Quantities_oM.dll</HintPath>
20+
</Reference>
21+
</ItemGroup>
22+
23+
</Project>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Linq;
5+
using System.Reflection;
6+
using System.Security.AccessControl;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using BH.oM.Base;
10+
using BH.oM.Base.Attributes;
11+
using BH.oM.Quantities.Attributes;
12+
13+
namespace SchemaDocumentationGenerator
14+
{
15+
public static class Settings
16+
{
17+
public static bool LoadSettings(string settingsPath)
18+
{
19+
List<string> lines = File.ReadAllLines(settingsPath).ToList();
20+
21+
foreach (string line in lines.Skip(1))
22+
{
23+
string[] split = line.Split(',');
24+
if (split.Length != 4)
25+
{
26+
Console.WriteLine($"failed splitting the line {line}");
27+
continue;
28+
}
29+
30+
AssemblyLink[split[0]] = split[1];
31+
AssemblyCategory[split[0]] = split[2];
32+
AssemblyIncluded[split[0]] = bool.Parse(split[3]);
33+
}
34+
return true;
35+
}
36+
37+
public static Dictionary<string, string> AssemblyLink { get; set; } = new Dictionary<string, string>();
38+
public static Dictionary<string, string> AssemblyCategory { get; set; } = new Dictionary<string, string>();
39+
public static Dictionary<string, bool> AssemblyIncluded { get; set; } = new Dictionary<string, bool>();
40+
}
41+
}

0 commit comments

Comments
 (0)