From 0ada1fb875227df817712b1c63692c967a0b51b5 Mon Sep 17 00:00:00 2001 From: adecler Date: Mon, 9 Aug 2021 15:28:06 +0800 Subject: [PATCH 1/4] Add method to detect if an item is part of the curated BHoM --- Reflection_Engine/Query/AssemblyPath.cs | 74 ++++++++++++++++++++++ Reflection_Engine/Query/IsPrototype.cs | 73 +++++++++++++++++++++ Reflection_Engine/Reflection_Engine.csproj | 2 + 3 files changed, 149 insertions(+) create mode 100644 Reflection_Engine/Query/AssemblyPath.cs create mode 100644 Reflection_Engine/Query/IsPrototype.cs diff --git a/Reflection_Engine/Query/AssemblyPath.cs b/Reflection_Engine/Query/AssemblyPath.cs new file mode 100644 index 000000000..ce957f4b9 --- /dev/null +++ b/Reflection_Engine/Query/AssemblyPath.cs @@ -0,0 +1,74 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2021, the respective contributors. All rights reserved. + * + * Each contributor holds copyright over their respective contributions. + * The project versioning (Git) records all such contribution source information. + * + * + * The BHoM is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3.0 of the License, or + * (at your option) any later version. + * + * The BHoM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + */ + +using BH.oM.Reflection.Attributes; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Reflection; + +namespace BH.Engine.Reflection +{ + public static partial class Query + { + /***************************************************/ + /**** Interface Methods ****/ + /***************************************************/ + + [Description("Return the path of the assembly containing this item")] + public static string IAssemblyPath(this object item) + { + return AssemblyPath(item as dynamic); + } + + /***************************************************/ + /**** Public Methods ****/ + /***************************************************/ + + [Description("Return the path of the assembly containing this method")] + public static string AssemblyPath(this MethodBase method) + { + return method.DeclaringType.Assembly.Location; + } + + /***************************************************/ + + [Description("Return the path of the assembly containing this type")] + public static string AssemblyPath(this Type type) + { + return type.Assembly.Location; + } + + /***************************************************/ + + [Description("Return the path of the assembly containing this type of object")] + public static string AssemblyPath(object item) + { + return item.GetType().AssemblyPath(); + } + + /***************************************************/ + } +} + + diff --git a/Reflection_Engine/Query/IsPrototype.cs b/Reflection_Engine/Query/IsPrototype.cs new file mode 100644 index 000000000..443dbb8ba --- /dev/null +++ b/Reflection_Engine/Query/IsPrototype.cs @@ -0,0 +1,73 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2021, the respective contributors. All rights reserved. + * + * Each contributor holds copyright over their respective contributions. + * The project versioning (Git) records all such contribution source information. + * + * + * The BHoM is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3.0 of the License, or + * (at your option) any later version. + * + * The BHoM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this code. If not, see . + */ + +using BH.oM.Reflection.Attributes; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Linq; +using System.Reflection; + +namespace BH.Engine.Reflection +{ + public static partial class Query + { + /***************************************************/ + /**** Public Methods ****/ + /***************************************************/ + + [Description("Return the path of the assembly containing this item")] + public static bool IsPrototype(this object item) + { + if (m_CoreAssemblyPaths == null) + ExtractCoreAssemblyPaths(); + + return !m_CoreAssemblyPaths.Contains(System.IO.Path.GetFileName(item.IAssemblyPath())); + } + + + /***************************************************/ + /**** Private Methods ****/ + /***************************************************/ + + private static void ExtractCoreAssemblyPaths() + { + string refFile = @"C:\ProgramData\BHoM\Settings\IncludedDlls.txt"; + + if (File.Exists(refFile)) + m_CoreAssemblyPaths = new HashSet(File.ReadAllLines(refFile).Select(x => System.IO.Path.GetFileName(x))); + else + m_CoreAssemblyPaths = new HashSet(); + } + + /***************************************************/ + /**** Private Fields ****/ + /***************************************************/ + + private static HashSet m_CoreAssemblyPaths = null; + + /***************************************************/ + } +} + + diff --git a/Reflection_Engine/Reflection_Engine.csproj b/Reflection_Engine/Reflection_Engine.csproj index 22a543fff..a12b8136f 100644 --- a/Reflection_Engine/Reflection_Engine.csproj +++ b/Reflection_Engine/Reflection_Engine.csproj @@ -116,6 +116,7 @@ + @@ -133,6 +134,7 @@ + From c1461b669abd128a3f6d786b587df118be155bbd Mon Sep 17 00:00:00 2001 From: Fraser Greenroyd Date: Tue, 10 Aug 2021 15:04:55 +0100 Subject: [PATCH 2/4] Update Reflection_Engine/Query/IsPrototype.cs --- Reflection_Engine/Query/IsPrototype.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Reflection_Engine/Query/IsPrototype.cs b/Reflection_Engine/Query/IsPrototype.cs index 443dbb8ba..5308b0fce 100644 --- a/Reflection_Engine/Query/IsPrototype.cs +++ b/Reflection_Engine/Query/IsPrototype.cs @@ -36,7 +36,7 @@ public static partial class Query /**** Public Methods ****/ /***************************************************/ - [Description("Return the path of the assembly containing this item")] + [Description("Determines whether the assembly the item is housed in is part of a prototype assembly.")] public static bool IsPrototype(this object item) { if (m_CoreAssemblyPaths == null) @@ -70,4 +70,3 @@ private static void ExtractCoreAssemblyPaths() } } - From 0a5d1b122120de646170c0baff65d1415e4f0982 Mon Sep 17 00:00:00 2001 From: adecler Date: Wed, 11 Aug 2021 09:51:13 +0800 Subject: [PATCH 3/4] Do not tag components as prototypes if IncludedDll file doesn't exist --- Reflection_Engine/Query/IsPrototype.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Reflection_Engine/Query/IsPrototype.cs b/Reflection_Engine/Query/IsPrototype.cs index 5308b0fce..39e4a9fec 100644 --- a/Reflection_Engine/Query/IsPrototype.cs +++ b/Reflection_Engine/Query/IsPrototype.cs @@ -42,7 +42,7 @@ public static bool IsPrototype(this object item) if (m_CoreAssemblyPaths == null) ExtractCoreAssemblyPaths(); - return !m_CoreAssemblyPaths.Contains(System.IO.Path.GetFileName(item.IAssemblyPath())); + return m_CoreAssemblyPaths.Count > 0 && !m_CoreAssemblyPaths.Contains(System.IO.Path.GetFileName(item.IAssemblyPath())); } From bad8b60a25bdb79ba4ec659d6988bbf5e335d158 Mon Sep 17 00:00:00 2001 From: adecler Date: Wed, 11 Aug 2021 09:55:33 +0800 Subject: [PATCH 4/4] Matching file name casing from the installer --- Reflection_Engine/Query/IsPrototype.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Reflection_Engine/Query/IsPrototype.cs b/Reflection_Engine/Query/IsPrototype.cs index 39e4a9fec..f5a8f3a82 100644 --- a/Reflection_Engine/Query/IsPrototype.cs +++ b/Reflection_Engine/Query/IsPrototype.cs @@ -52,7 +52,7 @@ public static bool IsPrototype(this object item) private static void ExtractCoreAssemblyPaths() { - string refFile = @"C:\ProgramData\BHoM\Settings\IncludedDlls.txt"; + string refFile = @"C:\ProgramData\BHoM\Settings\IncludedDLLs.txt"; if (File.Exists(refFile)) m_CoreAssemblyPaths = new HashSet(File.ReadAllLines(refFile).Select(x => System.IO.Path.GetFileName(x)));