From 2687c07cd6de7e3353659c064e64a878fa0dd7a6 Mon Sep 17 00:00:00 2001 From: Pawel Baran Date: Fri, 31 Jul 2026 18:54:53 +0200 Subject: [PATCH] .tsv-based reflection mechanism migrated to BHoM_Engine --- BHoM_UI/Global/AssemblyResolver.cs | 222 ---------------- BHoM_UI/Global/Initialisation.cs | 324 +++++------------------- BHoM_UI/Global/SearchMenu.cs | 14 +- BHoM_UI/Menus/ItemSelectorMenu.cs | 8 +- UI_Engine/Compute/ConstructorText.cs | 98 ------- UI_Engine/Compute/LoadNewAssemblies.cs | 123 --------- UI_Engine/Convert/CodeElementFromTsv.cs | 95 ------- UI_Engine/Convert/ToTsv.cs | 83 ------ UI_Engine/Query/AssemblyPath.cs | 70 ----- UI_Engine/Query/CodeElements.cs | 207 --------------- UI_Engine/Query/Items.cs | 141 ----------- UI_Engine/Query/OutputKeys.cs | 76 ------ UI_Engine/Query/SubFoldersForRuntime.cs | 85 ------- UI_Engine/Query/SystemTypes.cs | 62 ----- UI_Engine/Query/Weight.cs | 7 +- UI_oM/CodeElementRecord.cs | 61 ----- UI_oM/CodeElementType.cs | 54 ---- UI_oM/SearchItem.cs | 5 +- 18 files changed, 80 insertions(+), 1655 deletions(-) delete mode 100644 BHoM_UI/Global/AssemblyResolver.cs delete mode 100644 UI_Engine/Compute/ConstructorText.cs delete mode 100644 UI_Engine/Compute/LoadNewAssemblies.cs delete mode 100644 UI_Engine/Convert/CodeElementFromTsv.cs delete mode 100644 UI_Engine/Convert/ToTsv.cs delete mode 100644 UI_Engine/Query/AssemblyPath.cs delete mode 100644 UI_Engine/Query/CodeElements.cs delete mode 100644 UI_Engine/Query/OutputKeys.cs delete mode 100644 UI_Engine/Query/SubFoldersForRuntime.cs delete mode 100644 UI_Engine/Query/SystemTypes.cs delete mode 100644 UI_oM/CodeElementRecord.cs delete mode 100644 UI_oM/CodeElementType.cs diff --git a/BHoM_UI/Global/AssemblyResolver.cs b/BHoM_UI/Global/AssemblyResolver.cs deleted file mode 100644 index 12653ea2..00000000 --- a/BHoM_UI/Global/AssemblyResolver.cs +++ /dev/null @@ -1,222 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2026, 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.Engine.Base; -using BH.Engine.Base.Objects; -using BH.Engine.Reflection; -using BH.Engine.UI; -using BH.oM.Data.Requests; -using BH.oM.UI; -using BH.UI.Base.Components; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Diagnostics; -using System.Drawing; -using System.IO; -using System.Linq; -using System.Reflection; - -namespace BH.UI.Base.Global -{ - public class AssemblyResolver : IAssemblyResolver - { - /*************************************/ - /**** Constructors ****/ - /*************************************/ - - public AssemblyResolver(Dictionary> assemblyNamePerType = null, Dictionary>> assemblyNamesPerExtensionMethod = null) - { - if (assemblyNamePerType != null) - m_AssemblyNamePerType = assemblyNamePerType; - - if (assemblyNamesPerExtensionMethod != null) - m_AssemblyNamesPerExtensionMethod = assemblyNamesPerExtensionMethod; - } - - - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - [Description("Make sure assemblies that contain a type matching the input name are loaded. Return true if any assembly was loaded.")] - public bool MakeSureAssemblyIsLoadedForType(string type) - { - if (string.IsNullOrEmpty(type) || !type.StartsWith("BH.")) - return false; - - string[] parts = type.Split(','); - List assemblyNames = new List(); - - if (parts.Length > 1) - { - // Assembly is already in the type - assemblyNames.Add(parts[1].Trim()); - } - else if (parts.Length == 1) - { - // We don't have the assembly registered in the type so we need to deduce it - if (m_AssemblyNamePerType.ContainsKey(type)) - assemblyNames.AddRange(m_AssemblyNamePerType[type]); - } - - bool anyLoaded = false; - foreach (string assemblyName in assemblyNames.Where(x => !string.IsNullOrEmpty(x))) - { - if (!BH.Engine.Base.Query.IsAssemblyLoaded(assemblyName)) - { - string assemblyPath = BH.Engine.UI.Query.AssemblyPath(assemblyName); - if (!File.Exists(assemblyPath)) - { - BH.Engine.Base.Compute.RecordError($"Assembly file not found when trying to load assemblies for type {type}: {assemblyPath}"); - continue; - } - - try - { - Assembly assembly = BH.Engine.Base.Compute.LoadAssembly(assemblyPath); - if (assembly == null) - BH.Engine.Base.Compute.RecordError($"Failed to load assembly: {assemblyName}"); - else - anyLoaded = true; - } - catch (Exception ex) - { - BH.Engine.Base.Compute.RecordError(ex, $"Exception while loading assembly for type {type}: {assemblyPath}."); - return false; - } - } - } - - return anyLoaded; - } - - /***************************************************/ - - [Description("Make sure assemblies containing extension methods matching the input name and target type are loaded. Returns true if any assembly was loaded.")] - public bool MakeSureAssemblyIsLoadedForExtensionMethod(string methodName, Type targetType) - { - if (string.IsNullOrEmpty(methodName) || targetType == null) - return false; - - if (!m_AssemblyNamesPerExtensionMethod.ContainsKey(methodName)) - return false; - - Dictionary> typeToAssemblies = m_AssemblyNamesPerExtensionMethod[methodName]; - HashSet assembliesToLoad = new HashSet(); - - // 1. Exact type match - string exactTypeName = TypeKey(targetType); - if (typeToAssemblies.ContainsKey(exactTypeName)) - assembliesToLoad.UnionWith(typeToAssemblies[exactTypeName]); - - // 2. Base types - Type baseType = targetType.BaseType; - while (baseType != null && baseType != typeof(object)) - { - string baseTypeName = TypeKey(baseType); - if (typeToAssemblies.ContainsKey(baseTypeName)) - assembliesToLoad.UnionWith(typeToAssemblies[baseTypeName]); - baseType = baseType.BaseType; - } - - // 3. Interfaces - foreach (Type interfaceType in targetType.GetInterfaces()) - { - string interfaceName = TypeKey(interfaceType); - if (typeToAssemblies.ContainsKey(interfaceName)) - assembliesToLoad.UnionWith(typeToAssemblies[interfaceName]); - } - - // 4. Generic type definitions - if (targetType.IsGenericType) - { - Type genericDef = targetType.GetGenericTypeDefinition(); - string genericTypeName = TypeKey(genericDef); - if (typeToAssemblies.ContainsKey(genericTypeName)) - assembliesToLoad.UnionWith(typeToAssemblies[genericTypeName]); - } - - // Load all identified assemblies - bool anyLoaded = false; - foreach (string assemblyName in assembliesToLoad) - { - if (!BH.Engine.Base.Query.IsAssemblyLoaded(assemblyName)) - { - string assemblyPath = BH.Engine.UI.Query.AssemblyPath(assemblyName); - if (!File.Exists(assemblyPath)) - { - BH.Engine.Base.Compute.RecordNote($"Assembly not found for extension method {methodName}: {assemblyPath}"); - continue; - } - - try - { - Assembly assembly = BH.Engine.Base.Compute.LoadAssembly(assemblyPath); - if (assembly == null) - BH.Engine.Base.Compute.RecordWarning($"Failed to load assembly: {assemblyName}"); - else - anyLoaded = true; - } - catch (Exception ex) - { - BH.Engine.Base.Compute.RecordError(ex, $"Exception loading assembly for extension method {methodName}: {assemblyPath}"); - } - } - } - - return anyLoaded; - } - - - /*************************************/ - /**** Private Methods ****/ - /*************************************/ - - private static string TypeKey(Type type) - { - string key = type.FullName ?? type.Name; - int cut = key.IndexOfAny(new char[] { ',', '[' }); - if (cut > 0) - key = key.Substring(0, cut); - return key; - } - - - - /*************************************/ - /**** Private Fields ****/ - /*************************************/ - - Dictionary> m_AssemblyNamePerType = new Dictionary>(); - - Dictionary>> m_AssemblyNamesPerExtensionMethod = new Dictionary>>(); - - /*************************************/ - } -} - - - - - - diff --git a/BHoM_UI/Global/Initialisation.cs b/BHoM_UI/Global/Initialisation.cs index 5541d967..d75545c5 100644 --- a/BHoM_UI/Global/Initialisation.cs +++ b/BHoM_UI/Global/Initialisation.cs @@ -20,23 +20,20 @@ * along with this code. If not, see . */ -using BH.Adapter; using BH.Engine.Base; using BH.Engine.Base.Objects; -using BH.Engine.Reflection; using BH.Engine.UI; using BH.oM.Base; +using BH.oM.Base.Reflection; using BH.oM.UI; using BH.UI.Base.Components; using System; -using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; using System.Reflection; -using System.Windows.Media; namespace BH.UI.Base.Global @@ -62,7 +59,7 @@ public static class Initialisation public static List SearchItems { get; set; } = new List(); - public static string AssemblyContentFilePath { get; set; } = Path.Combine(BH.Engine.Base.Query.BHoMFolderResources(), "AssemblyContent.tsv"); + public static string AssemblyContentFilePath { get; set; } = BH.Engine.Base.Objects.Initialisation.DefaultAssemblyContentFilePath; public static List CustomRibbonEntries { get; set; } = new List(); @@ -96,7 +93,7 @@ public static bool LoadToolkitSettings() stopwatch.Start(); string directory = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonApplicationData), "BHoM", "Settings"); - if(!Directory.Exists(directory)) + if (!Directory.Exists(directory)) { BH.Engine.Base.Compute.RecordWarning($"{directory} doesn't exist. Toolkit settings are not loaded."); return false; @@ -128,7 +125,7 @@ private static bool LoadInitialisationSettings(List allSettings) bool success = true; List initialisationSettings = allSettings.OfType().ToList(); - foreach (var settings in initialisationSettings) + foreach (IInitialisationSettings settings in initialisationSettings) { try { @@ -151,9 +148,9 @@ private static bool LoadCustomRibbons(List allSettings) bool success = true; List ribbonSettings = allSettings.OfType().ToList(); - foreach (var settings in ribbonSettings) + foreach (CustomRibbonSettings settings in ribbonSettings) { - foreach (var entry in settings.Entries) + foreach (CustomRibbonEntry entry in settings.Entries) { try { @@ -194,7 +191,7 @@ private static bool InitialiseToolkit(IInitialisationSettings settings) // Make sure the assembly is loaded for that method if (!string.IsNullOrEmpty(settings.InitialisationAssembly) && !BH.Engine.Base.Query.IsAssemblyLoaded(settings.InitialisationAssembly)) { - string initAssemblyPath = BH.Engine.UI.Query.AssemblyPath(settings.InitialisationAssembly); + string initAssemblyPath = BH.Engine.Base.Objects.Initialisation.AssemblyFilePath(settings.InitialisationAssembly); BH.Engine.Base.Compute.LoadAssembly(initAssemblyPath); } @@ -235,26 +232,11 @@ private static bool LoadCodeElements() if (!File.Exists(AssemblyContentFilePath)) return true; - Stopwatch stopwatch = new Stopwatch(); - stopwatch.Start(); - - // Load the code elements - try - { - CodeElements = File.ReadAllLines(AssemblyContentFilePath) - .Select(x => BH.Engine.UI.Convert.CodeElementFromTsv(x)) - .Where(x => x != null) - .ToList(); - } - catch (Exception e) - { - BH.Engine.Base.Compute.RecordError(e, $"Failed to load the code elements from '{Path.GetFileName(AssemblyContentFilePath)}'."); + List loaded = BH.Engine.Base.Objects.Initialisation.LoadCodeElements(AssemblyContentFilePath, x => x.FromTsv()); + if (loaded == null) return false; - } - - stopwatch.Stop(); - BH.Engine.Base.Compute.RecordNote($"Time to load all code elements: {stopwatch.Elapsed.TotalMilliseconds / 1000} s."); + CodeElements = loaded; return true; } @@ -262,214 +244,21 @@ private static bool LoadCodeElements() private static bool CreateAssemblyResolver() { - // Collect the relation between types and the assembly they belong to - Dictionary> assemblyNamesPerType = CodeElements - .Where(x => x.Type == CodeElementType.Type) - .GroupBy(x => x.DisplayText) - .ToDictionary(group => group.Key, group => group.Select(x => x.AssemblyName).Distinct().ToList()); - - // Collect the relation between extension methods and the assembly they belong to - Dictionary>> assemblyNamesPerExtensionMethod - = BuildExtensionMethodDictionary(CodeElements); - - // Create the assembly resolver and link it the the BHoM engine - AssemblyResolver = new AssemblyResolver(assemblyNamesPerType, assemblyNamesPerExtensionMethod); + AssemblyResolver = BH.Engine.Base.Objects.Initialisation.CreateAssemblyResolver(CodeElements); BH.Engine.Base.Compute.SetAssemblyResolver(AssemblyResolver); - return true; } /*************************************/ - private static Dictionary>> BuildExtensionMethodDictionary( - List codeElements) - { - Dictionary>> result - = new Dictionary>>(); - - foreach (CodeElementRecord record in codeElements.Where(x => - x.Type == CodeElementType.Method_Query || - x.Type == CodeElementType.Method_Compute || - x.Type == CodeElementType.Method_Convert || - x.Type == CodeElementType.Method_Modify)) - { - try - { - // Extract first parameter type from JSON - string firstParamTypeName = ExtractFirstParameterType(record.Json); - - if (!string.IsNullOrEmpty(firstParamTypeName)) - { - // Extract method name from DisplayText - string methodName = ExtractMethodName(record.DisplayText); - - // Build nested dictionary - if (!result.ContainsKey(methodName)) - result[methodName] = new Dictionary>(); - - if (!result[methodName].ContainsKey(firstParamTypeName)) - result[methodName][firstParamTypeName] = new List(); - - if (!result[methodName][firstParamTypeName].Contains(record.AssemblyName)) - result[methodName][firstParamTypeName].Add(record.AssemblyName); - } - } - catch (Exception ex) - { - BH.Engine.Base.Compute.RecordWarning($"Failed to parse extension method from {record.DisplayText}: {ex.Message}"); - } - } - - return result; - } - - /*************************************/ - - private static string ExtractFirstParameterType(string json) - { - if (string.IsNullOrEmpty(json)) - return null; - - try - { - // Find the Parameters array in the JSON - int parametersIndex = json.IndexOf("\"Parameters\""); - if (parametersIndex < 0) - return null; - - // Find the opening bracket of the Parameters array - int arrayStartIndex = json.IndexOf('[', parametersIndex); - if (arrayStartIndex < 0) - return null; - - // Find the end of the first parameter (first element in array) - // The first element starts after [ and is a JSON string itself - int firstParamStart = arrayStartIndex + 1; - - // Skip whitespace - while (firstParamStart < json.Length && char.IsWhiteSpace(json[firstParamStart])) - firstParamStart++; - - // Check if array is empty - if (firstParamStart >= json.Length || json[firstParamStart] == ']') - return null; - - // The first parameter is a JSON string, find "Name" property within it - // Look for "Name" : "..." pattern in the first parameter - int nameIndex = json.IndexOf("\\\"Name\\\"", firstParamStart); - if (nameIndex < 0) - return null; - - // Find the opening quote of the Name value - int nameValueStart = json.IndexOf("\\\"", nameIndex + 8); // Skip past \"Name\" - if (nameValueStart < 0) - return null; - - nameValueStart += 2; // Skip past \" - - // Find the closing quote of the Name value - int nameValueEnd = json.IndexOf("\\\"", nameValueStart); - if (nameValueEnd < 0) - return null; - - // Extract the type name - string typeName = json.Substring(nameValueStart, nameValueEnd - nameValueStart); - - // Remove assembly qualification: "Type, Assembly" -> "Type" - int commaIndex = typeName.IndexOf(','); - if (commaIndex > 0) - typeName = typeName.Substring(0, commaIndex).Trim(); - - return typeName; - } - catch (Exception ex) - { - // Silent fail - BH.Engine.Base.Compute.RecordNote($"Could not extract parameter type: {ex.Message}"); - } - - return null; - } - - /*************************************/ - - private static string ExtractMethodName(string displayText) - { - // Format: "BH.Engine.Namespace.Query.MethodName(params)" or with generics - int openParen = displayText.IndexOf('('); - if (openParen < 0) - return displayText; - - string beforeParams = displayText.Substring(0, openParen); - - // Remove generic type parameters if present - int genericStart = beforeParams.IndexOf('<'); - if (genericStart > 0) - beforeParams = beforeParams.Substring(0, genericStart); - - // Get last segment after last dot - int lastDot = beforeParams.LastIndexOf('.'); - if (lastDot >= 0) - return beforeParams.Substring(lastDot + 1); - - return beforeParams; - } - - /*************************************/ - private static bool LoadNewAssemblies() { - Stopwatch stopwatch = new Stopwatch(); - stopwatch.Start(); - - Dictionary lastAssemblyUpdateTimes = CodeElements - .GroupBy(x => x.AssemblyName) - .ToDictionary(x => x.Key, x => x.First().AssemblyModifiedTime); - - List loadedAssemblies = BH.Engine.UI.Compute.LoadNewAssemblies(lastAssemblyUpdateTimes); - - stopwatch.Stop(); - BH.Engine.Base.Compute.RecordNote($"Time to load all updated/new assemblies from current domain: {stopwatch.Elapsed.TotalMilliseconds / 1000} s."); - - UpdateCodeElements(loadedAssemblies); - - return true; - } - - /*************************************/ - - private static bool UpdateCodeElements(List loadedAssemblies) - { - List loadedCodeElements = BH.Engine.UI.Query.CodeElements() - .Where(x => loadedAssemblies.Contains(x.AssemblyName, StringComparer.OrdinalIgnoreCase)) - .ToList(); - - if (loadedCodeElements.Count == 0) - return true; - - Stopwatch stopwatch = new Stopwatch(); - stopwatch.Start(); - - CodeElements = CodeElements.Where(x => !loadedAssemblies.Contains(x.AssemblyName)) - .Concat(loadedCodeElements) - .ToList(); - - List lines = CodeElements - .Select(x => x.ToTsv()) - .Where(x => !string.IsNullOrEmpty(x)) - .ToList(); - - try - { - File.WriteAllLines(AssemblyContentFilePath, lines); - } - catch (Exception e) - { - BH.Engine.Base.Compute.RecordError(e, $"Failed to save the assembly content to {AssemblyContentFilePath}."); - } - - stopwatch.Stop(); - BH.Engine.Base.Compute.RecordNote($"Time to update the code elements with the content of the updated/new assemblies: {stopwatch.Elapsed.TotalMilliseconds / 1000} s."); + CodeElements = BH.Engine.Base.Objects.Initialisation.RefreshFromNewAssemblies( + CodeElements, + BH.Engine.Base.Objects.Initialisation.DefaultAssemblyNameFilter, + AssemblyContentFilePath, + x => x.ToTsv(), + names => BH.Engine.Reflection.Query.CodeElements(names)); return true; } @@ -486,18 +275,18 @@ private static bool CreateSearchItems(List codeElements) // All code elements SearchItems.AddRange(codeElements - .Select(x => new SearchItem { CallerType = GetCallerType(x.Type), Icon = GetIcon(x.Type), Text = x.DisplayText, Json = x.Json, InputKeys = x.InputKeys, OutputKeys = x.OutputKeys })); + .Select(x => new SearchItem { CallerType = GetCallerType(x), Icon = GetIcon(x), Text = x.DisplayText, InputKeys = x.InputKeys, OutputKeys = x.OutputKeys })); // All data libraries SearchItems.AddRange(BH.Engine.UI.Query.LibraryItems() .Select(x => new SearchItem { CallerType = typeof(CreateDataCaller), Icon = Properties.Resources.BHoM_Data, Text = x.Replace(Path.DirectorySeparatorChar, '.'), Item = x })); // All system types - SearchItems.AddRange(BH.Engine.UI.Query.SystemTypes() + SearchItems.AddRange(BH.Engine.Reflection.Query.SystemTypes() .Select(x => new SearchItem { CallerType = typeof(CreateTypeCaller), Icon = Properties.Resources.Type, Text = x.ToText(true), Item = x })); // Filter out excluded toolkits - if (ExcludedToolkits?.Count > 0) + if (ExcludedToolkits?.Count > 0) SearchItems = SearchItems.Where(x => !ExcludedToolkits.Contains(x.Toolkit())).ToList(); stopwatch.Stop(); @@ -508,18 +297,24 @@ private static bool CreateSearchItems(List codeElements) /*************************************/ - private static Type GetCallerType(CodeElementType codeElementType) + private static Type GetCallerType(CodeElementRecord codeElement) { - switch (codeElementType) + switch (codeElement.Type) { - case CodeElementType.AdapterConstructor: - return typeof(CreateAdapterCaller); - case CodeElementType.ConstructableObject: - return typeof(CreateObjectCaller); - case CodeElementType.ConstructableRequest: - return typeof(CreateRequestCaller); + case CodeElementType.Constructor: + if (codeElement.IsAdapterConstructor()) + return typeof(CreateAdapterCaller); + if (codeElement.IsRequestConstructor()) + return typeof(CreateRequestCaller); + else + return typeof(CreateObjectCaller); case CodeElementType.Enum: return typeof(CreateEnumCaller); + case CodeElementType.Method_Create: + if (codeElement.IsRequestCreator()) + return typeof(CreateRequestCaller); + else + return typeof(CreateObjectCaller); case CodeElementType.Method_Compute: return typeof(ComputeCaller); case CodeElementType.Method_Convert: @@ -530,10 +325,6 @@ private static Type GetCallerType(CodeElementType codeElementType) return typeof(ModifyCaller); case CodeElementType.Method_Query: return typeof(QueryCaller); - case CodeElementType.ObjectCreator: - return typeof(CreateObjectCaller); - case CodeElementType.RequestCreator: - return typeof(CreateRequestCaller); case CodeElementType.Type: return typeof(CreateTypeCaller); default: @@ -543,18 +334,45 @@ private static Type GetCallerType(CodeElementType codeElementType) /*************************************/ - private static Bitmap GetIcon(CodeElementType codeElementType) + private static bool IsAdapterConstructor(this CodeElementRecord codeElement) + { + return codeElement.Type == CodeElementType.Constructor && codeElement.OutputKeys.Contains("BH.oM.Adapter.IBHoMAdapter"); + } + + /*************************************/ + + private static bool IsRequestConstructor(this CodeElementRecord codeElement) + { + return codeElement.Type == CodeElementType.Constructor && codeElement.OutputKeys.Contains("BH.oM.Data.Requests.IRequest"); + } + + /*************************************/ + + private static bool IsRequestCreator(this CodeElementRecord codeElement) + { + return codeElement.Type == CodeElementType.Method_Create && codeElement.OutputKeys.Contains("BH.oM.Data.Requests.IRequest"); + } + + /*************************************/ + + private static Bitmap GetIcon(CodeElementRecord codeElement) { - switch (codeElementType) + switch (codeElement.Type) { - case CodeElementType.AdapterConstructor: - return Properties.Resources.Adapter; - case CodeElementType.ConstructableObject: - return Properties.Resources.CreateBHoM; - case CodeElementType.ConstructableRequest: - return Properties.Resources.CreateRequest; + case CodeElementType.Constructor: + if (codeElement.IsAdapterConstructor()) + return Properties.Resources.Adapter; + if (codeElement.IsRequestConstructor()) + return Properties.Resources.CreateRequest; + else + return Properties.Resources.CreateBHoM; case CodeElementType.Enum: return Properties.Resources.BHoM_Enum; + case CodeElementType.Method_Create: + if (codeElement.IsRequestCreator()) + return Properties.Resources.CreateRequest; + else + return Properties.Resources.CreateBHoM; case CodeElementType.Method_Compute: return Properties.Resources.Compute; case CodeElementType.Method_Convert: @@ -565,10 +383,6 @@ private static Bitmap GetIcon(CodeElementType codeElementType) return Properties.Resources.Modify; case CodeElementType.Method_Query: return Properties.Resources.Query; - case CodeElementType.ObjectCreator: - return Properties.Resources.CreateBHoM; - case CodeElementType.RequestCreator: - return Properties.Resources.CreateRequest; case CodeElementType.Type: return Properties.Resources.Type; default: diff --git a/BHoM_UI/Global/SearchMenu.cs b/BHoM_UI/Global/SearchMenu.cs index ade69fda..078a778f 100644 --- a/BHoM_UI/Global/SearchMenu.cs +++ b/BHoM_UI/Global/SearchMenu.cs @@ -20,18 +20,11 @@ * along with this code. If not, see . */ -using BH.Engine.Base; -using BH.Engine.Reflection; using BH.Engine.UI; -using BH.oM.Data.Requests; using BH.oM.UI; -using BH.UI.Base.Components; using System; using System.Collections.Generic; -using System.Diagnostics; -using System.Drawing; using System.Linq; -using System.Reflection; namespace BH.UI.Base.Global { @@ -103,11 +96,12 @@ protected void NotifySelection(SearchItem item, BH.oM.Geometry.Point location) ItemSelected?.Invoke(this, null); else { - if (item.Item == null && !string.IsNullOrEmpty(item.Json)) - item.Item = BH.Engine.Serialiser.Convert.FromJson(item.Json); + if (item.Item == null && !string.IsNullOrEmpty(item.Text)) + item.Item = BH.Engine.Base.Query.ItemByKey(item.Text); + ItemSelected?.Invoke(this, new ComponentRequest { CallerType = item.CallerType, SelectedItem = item.Item, Location = location }); } - + } /*************************************/ diff --git a/BHoM_UI/Menus/ItemSelectorMenu.cs b/BHoM_UI/Menus/ItemSelectorMenu.cs index 06f58357..4f520fe5 100644 --- a/BHoM_UI/Menus/ItemSelectorMenu.cs +++ b/BHoM_UI/Menus/ItemSelectorMenu.cs @@ -24,9 +24,6 @@ using BH.oM.UI; using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace BH.UI.Base.Menus { @@ -98,8 +95,9 @@ protected void ReturnSelectedItem(SearchItem item) ItemSelected.Invoke(this, null); else { - if (item.Item == null && !string.IsNullOrEmpty(item.Json)) - item.Item = BH.Engine.Serialiser.Convert.FromJson(item.Json); + if (item.Item == null && !string.IsNullOrEmpty(item.Text)) + item.Item = BH.Engine.Base.Query.ItemByKey(item.Text); + ItemSelected.Invoke(this, item.Item); } } diff --git a/UI_Engine/Compute/ConstructorText.cs b/UI_Engine/Compute/ConstructorText.cs deleted file mode 100644 index a23a316f..00000000 --- a/UI_Engine/Compute/ConstructorText.cs +++ /dev/null @@ -1,98 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2026, 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.Engine.Base; -using BH.oM.Base.Attributes; -using BH.oM.UI; -using System; -using System.CodeDom.Compiler; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Linq.Expressions; -using System.Reflection; - -namespace BH.Engine.UI -{ - public static partial class Compute - { - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - [Description("Generate the text representing the input constructor")] - [Input("type", "The type of object to create a constructor for.")] - [Input("maxParams", "The maximum number of parameters to include in the text.")] - [Input("maxChars", "The maximum number of characters for the output text.")] - [Output("text", "The text corresponding to the description of the constructor generated for that type.")] - public static string ConstructorText(this Type type, int maxParams = 5, int maxChars = 40) - { - string text = type.Namespace + "." + type.Name + "." + type.Name + "() {"; - - try - { - string[] excluded = new string[] { "BHoM_Guid", "Fragments", "Tags", "CustomData" }; - PropertyInfo[] properties = type.GetProperties().Where(x => !excluded.Contains(x.Name)).ToArray(); - - string propertiesText = ""; - if (properties.Length > 0) - { - // Collect parameters text - for (int i = 0; i < properties.Count(); i++) - { - string singlePropertyText = properties[i].PropertyType.ToText() + " " + properties[i].Name; - - if (i > 0) - propertiesText += ", "; - - if (i >= maxParams || string.Join(propertiesText, singlePropertyText).Length > maxChars) - { - propertiesText += $"and {properties.Length - i} more inputs"; - break; - } - else - propertiesText += singlePropertyText; - } - } - - text += propertiesText; - } - catch (Exception e) - { - Engine.Base.Compute.RecordWarning("Type " + type.Name + " failed to load its properties.\nError: " + e.ToString()); - text += "?"; - } - text += "}"; - - return text; - } - - /*************************************/ - } -} - - - - - - - diff --git a/UI_Engine/Compute/LoadNewAssemblies.cs b/UI_Engine/Compute/LoadNewAssemblies.cs deleted file mode 100644 index 646bc5db..00000000 --- a/UI_Engine/Compute/LoadNewAssemblies.cs +++ /dev/null @@ -1,123 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2026, 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.Base; -using BH.oM.Base.Attributes; -using BH.oM.UI; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Text.RegularExpressions; -using System.Threading.Tasks; - -namespace BH.Engine.UI -{ - public static partial class Compute - { - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - [Description("Loads all BHoM assemblies from the current domain.")] - [Input("lastAssemblyUpdateTimes", "records of the last time each assembly was updated.")] - [Output("loadedAssemblies", "Assemblies loaded as considered new.")] - public static List LoadNewAssemblies(Dictionary lastAssemblyUpdateTimes) - { - if (lastAssemblyUpdateTimes == null) - { - BH.Engine.Base.Compute.RecordError("lastAssemblyUpdateTimes was not provided. No assembly was loaded."); - return new List(); - } - - // Make sure the keys for the assemblies are in lower case to avoid casing mismatching - Dictionary lastUpdateTimes = lastAssemblyUpdateTimes.ToDictionary(x => x.Key.ToLower(), x => x.Value); - HashSet loadedAssemblies = new HashSet(StringComparer.OrdinalIgnoreCase); - HashSet visitedAssemblies = new HashSet(StringComparer.OrdinalIgnoreCase); - - // Pass 1: runtime-specific subdirectory (preferred over flat folder when present) - string bhomFolder = BH.Engine.Base.Query.BHoMFolder(); - foreach (string subFolder in BH.Engine.UI.Query.SubFoldersForRuntime()) - { - string runtimeFolder = Path.Combine(bhomFolder, subFolder); - LoadNewAssembliesForFolder(runtimeFolder, lastUpdateTimes, loadedAssemblies, visitedAssemblies); - } - - // Pass 2: flat folder, skipping any assembly already handled by the runtime subdir pass - LoadNewAssembliesForFolder(bhomFolder, lastUpdateTimes, loadedAssemblies, visitedAssemblies); - - return loadedAssemblies.ToList(); - } - - - /*************************************/ - /**** Private Methods ****/ - /*************************************/ - - private static void LoadNewAssembliesForFolder(string folderPath, Dictionary lastUpdateTimes, HashSet loadedAssemblies, HashSet visitedAssemblies) - { - if (!Directory.Exists(folderPath)) - return; - - foreach (string file in Directory.GetFiles(folderPath, "*.dll", SearchOption.TopDirectoryOnly)) - { - string name = Path.GetFileNameWithoutExtension(file); - - if (m_AssemblyNameFilter.IsMatch(name) && !visitedAssemblies.Contains(name)) - { - visitedAssemblies.Add(name); - string key = name.ToLower(); - - if (!lastUpdateTimes.ContainsKey(key) || lastUpdateTimes[key] < File.GetLastWriteTimeUtc(file)) - { - Assembly assembly = BH.Engine.Base.Compute.LoadAssembly(file); - if (assembly != null) - { - BH.Engine.Base.Compute.RecordNote($"Assembly {name} loaded as it was newer than its last recorded update time."); - loadedAssemblies.Add(name); - } - } - } - } - } - - - /*************************************/ - /**** Private Fields ****/ - /*************************************/ - - private static readonly Regex m_AssemblyNameFilter = new Regex(@"oM$|_Engine$|_Adapter$"); - - /*************************************/ - - } -} - - - - - - diff --git a/UI_Engine/Convert/CodeElementFromTsv.cs b/UI_Engine/Convert/CodeElementFromTsv.cs deleted file mode 100644 index b4b4cffa..00000000 --- a/UI_Engine/Convert/CodeElementFromTsv.cs +++ /dev/null @@ -1,95 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2026, 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.Engine.Reflection; -using BH.oM.Base.Attributes; -using BH.oM.UI; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Engine.UI -{ - public static partial class Convert - { - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - [Description("Convert a row in an Excel file (in tsv format) into a code element record.")] - [Input("tsv", "Excel row that contains the data related to the code element in a tsv format.")] - [Output("codeElement", "Converted code element.")] - public static CodeElementRecord CodeElementFromTsv(this string tsv) - { - string[] parts = tsv.Split('\t'); - if (parts.Length < 5) - { - BH.Engine.Base.Compute.RecordError("Failed to extract code element record from tvs content because it doesn't contain 5 parts. Input tsv: " + tsv); - return null; - } - - if (!Enum.TryParse(parts[1], out CodeElementType type)) - { - BH.Engine.Base.Compute.RecordError($"Failed to extract code element record from tvs content because the code element type ({parts[1]}) is not recognised. Input tsv: " + tsv); - return null; - } - - if (!long.TryParse(parts[4], out long utcTime)) - { - BH.Engine.Base.Compute.RecordError($"Failed to extract code element record from tvs content because the provided time ({parts[4]}) is not valid. Input tsv: " + tsv); - return null; - } - - List inputKeys = new List(); - List outputKeys = new List(); - if (parts.Length >= 7) - { - inputKeys = string.IsNullOrEmpty(parts[5]) ? new List() : parts[5].Split(',').ToList(); - outputKeys = string.IsNullOrEmpty(parts[6]) ? new List() : parts[6].Split(',').ToList(); - } - - return new CodeElementRecord - { - AssemblyName = parts[0], - Type = type, - DisplayText = parts[2], - Json = parts[3], - AssemblyModifiedTime = DateTime.FromFileTimeUtc(utcTime), - InputKeys = inputKeys, - OutputKeys = outputKeys - }; - - } - - /*************************************/ - } -} - - - - - - diff --git a/UI_Engine/Convert/ToTsv.cs b/UI_Engine/Convert/ToTsv.cs deleted file mode 100644 index 6c5008c4..00000000 --- a/UI_Engine/Convert/ToTsv.cs +++ /dev/null @@ -1,83 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2026, 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.Engine.Reflection; -using BH.oM.Base.Attributes; -using BH.oM.UI; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Engine.UI -{ - public static partial class Convert - { - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - [Description("Convert a code element record into a row in an Excel file (in tsv format).")] - [Input("codeElement", "Code element to convert.")] - [Output("tsv", "Excel row containing the data related to the code element in a tsv format.")] - public static string ToTsv(this CodeElementRecord codeElement) - { - return $"{codeElement.AssemblyName}" + - $"\t{codeElement.Type}" + - $"\t{codeElement.DisplayText}" + - $"\t{codeElement.Json}" + - $"\t{codeElement.AssemblyModifiedTime.ToFileTimeUtc()}" + - $"\t{ToCommaSeparatedList(codeElement.InputKeys)}" + - $"\t{ToCommaSeparatedList(codeElement.OutputKeys)}"; - } - - - /*************************************/ - /**** Private Methods ****/ - /*************************************/ - - private static string ToCommaSeparatedList(List keys) - { - switch (keys?.Count) - { - case 0: - case null: - return ""; - case 1: - return keys.First(); - default: - return keys.Aggregate((a, b) => a + "," + b); - } - } - - /*************************************/ - } -} - - - - - - diff --git a/UI_Engine/Query/AssemblyPath.cs b/UI_Engine/Query/AssemblyPath.cs deleted file mode 100644 index 2d423523..00000000 --- a/UI_Engine/Query/AssemblyPath.cs +++ /dev/null @@ -1,70 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2026, 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.Engine.Base; -using BH.oM.Base.Attributes; -using BH.oM.UI; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Engine.UI -{ - public static partial class Query - { - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - [Description("Returns the best on-disk path for a BHoM assembly, preferring the runtime-specific subdirectory (netX.0\\ or netfx\\) over the flat folder.")] - [Input("assemblyName", "Assembly name without extension, e.g. 'SQL_Adapter'.")] - [Output("path", "Full path to the .dll file; the file may or may not exist.")] - public static string AssemblyPath(string assemblyName) - { - string bhomFolder = BH.Engine.Base.Query.BHoMFolder(); - - // First try to return an assembly from a runtime-specific folder - foreach (string subFolder in BH.Engine.UI.Query.SubFoldersForRuntime()) - { - string runtimePath = Path.Combine(bhomFolder, subFolder, assemblyName + ".dll"); - if (File.Exists(runtimePath)) - return runtimePath; - } - - //Then fallback to returning the assembly from the default rool folder - return Path.Combine(bhomFolder, assemblyName + ".dll"); - } - - /*************************************/ - } -} - - - - - - - diff --git a/UI_Engine/Query/CodeElements.cs b/UI_Engine/Query/CodeElements.cs deleted file mode 100644 index 146ba4d0..00000000 --- a/UI_Engine/Query/CodeElements.cs +++ /dev/null @@ -1,207 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2026, 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.Engine.Base; -using BH.Engine.Reflection; -using BH.Engine.Serialiser; -using BH.oM.Base; -using BH.oM.Base.Attributes; -using BH.oM.Data.Requests; -using BH.oM.UI; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.IO; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Engine.UI -{ - public static partial class Query - { - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - [Description("Collect all the code elements that can be used to create UI components from the loaded assemblies.")] - [Output("codeElements", "All code elements already loaded that can be used in the UI to create components.")] - public static List CodeElements() - { - List items = new List(); - - /// Types - - // All constructable BHoM objects and requests - items.AddRange(BH.Engine.UI.Query.ConstructableTypeItems() - .Select(x => CodeElement(x, GetConstructableType(x), x.ConstructorText()))); - - // All Enums - items.AddRange(BH.Engine.UI.Query.EnumItems() - .Select(x => CodeElement(x, CodeElementType.Enum, x.ToText(true)))); - - // All Types - items.AddRange(BH.Engine.UI.Query.TypeItems() - .Select(x => CodeElement(x, CodeElementType.Type, x.ToText(true)))); - - /// Methods - - // All adapter constructors - items.AddRange(BH.Engine.UI.Query.AdapterConstructorItems() - .Select(x => CodeElement(x, CodeElementType.AdapterConstructor, x.ToText(true)))); - - // All methods for the BHoM Engine (including creators) - items.AddRange(BH.Engine.Base.Query.BHoMMethodList() - .Where(x => x.IsExposed()) - .Select(x => CodeElement(x, GetMethodType(x), x.ToText(includePath: true, removeIForInterface: false)))); - - // All methods from external class - items.AddRange(BH.Engine.UI.Query.ExternalItems() - .Select(x => CodeElement(x, CodeElementType.Method_External, x.ToText(true)))); - - // Return the list - return items; - } - - - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - private static CodeElementRecord CodeElement(Type type, CodeElementType elementType, string displayText) - { - List inputTypes = type.GetProperties() - .Select(x => x.PropertyType?.UnderlyingType()?.Type) - .Where(x => x != null) - .Distinct() - .ToList(); - - return new CodeElementRecord - { - AssemblyName = AssemblyName(type), - AssemblyModifiedTime = AssemblyModifiedTime(type), - Type = elementType, - DisplayText = displayText, - Json = type.ToJson(), - InputKeys = inputTypes.Select(x => x.ToText(true)).ToList(), - OutputKeys = type.UnderlyingType()?.Type.OutputKeys() - }; - } - - /*************************************/ - - private static CodeElementRecord CodeElement(MethodBase method, CodeElementType elementType, string displayText) - { - Type outputType = (method is MethodInfo) ? ((MethodInfo)method).ReturnType : method.DeclaringType; - List inputTypes = method.GetParameters() - .Select(x => x.ParameterType?.UnderlyingType()?.Type) - .Where(x => x != null) - .Distinct() - .ToList(); - - return new CodeElementRecord - { - AssemblyName = AssemblyName(method), - AssemblyModifiedTime = AssemblyModifiedTime(method), - Type = elementType, - DisplayText = displayText, - Json = method.ToJson(), - InputKeys = inputTypes.Select(x => x.ToText(true)).ToList(), - OutputKeys = outputType.UnderlyingType()?.Type.OutputKeys() - }; - } - - /*************************************/ - - private static string AssemblyName(MethodBase method) - { - return AssemblyName(method.DeclaringType); - } - - /*************************************/ - - private static string AssemblyName(Type type) - { - return type.Assembly.GetName().Name; - } - - /*************************************/ - - private static DateTime AssemblyModifiedTime(MethodBase method) - { - return AssemblyModifiedTime(method.DeclaringType); - } - - /*************************************/ - - private static DateTime AssemblyModifiedTime(Type type) - { - if (string.IsNullOrEmpty(type?.Assembly?.Location)) - return DateTime.MinValue; - else - return File.GetLastWriteTimeUtc(type.Assembly.Location); - } - - /*************************************/ - - private static CodeElementType GetConstructableType(Type type) - { - if (typeof(IRequest).IsAssignableFrom(type)) - return CodeElementType.ConstructableRequest; - else - return CodeElementType.ConstructableObject; - } - - /*************************************/ - - private static CodeElementType GetMethodType(MethodInfo method) - { - switch (method.DeclaringType.Name) - { - case "Create": - if (typeof(IRequest).IsAssignableFrom(method.ReturnType)) - return CodeElementType.RequestCreator; - else - return CodeElementType.ObjectCreator; - case "Compute": - return CodeElementType.Method_Compute; - case "Convert": - return CodeElementType.Method_Convert; - case "Modify": - return CodeElementType.Method_Modify; - case "Query": - return CodeElementType.Method_Query; - default: - return CodeElementType.Undefined; - } - } - - /*************************************/ - } -} - - - - - - diff --git a/UI_Engine/Query/Items.cs b/UI_Engine/Query/Items.cs index 4c23987d..c62626bc 100644 --- a/UI_Engine/Query/Items.cs +++ b/UI_Engine/Query/Items.cs @@ -20,15 +20,11 @@ * along with this code. If not, see . */ -using BH.Adapter; -using BH.Engine.Reflection; using BH.oM.Base.Attributes; -using System; using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Linq; -using System.Reflection; namespace BH.Engine.UI { @@ -38,134 +34,6 @@ public static partial class Query /**** Public Methods ****/ /***************************************************/ - [Description("Extracts all BHoM methods to be grouped as Engine items in the UI (combined group of all 5 basic Engine classes).")] - [Output("items", "All BHoM methods to be grouped as Engine items.")] - public static IEnumerable EngineItems() - { - return Engine.Base.Query.BHoMMethodList().Where(x => x.IsExposed()); - } - - /***************************************************/ - - [Description("Extracts all BHoM methods to be grouped as Create items in the UI.")] - [Output("items", "All BHoM methods to be grouped as Create items.")] - public static IEnumerable CreateItems() - { - return Engine.Base.Query.BHoMMethodList() - .Where(x => !x.IsNotImplemented() && !x.IsDeprecated() && x.DeclaringType.Name == "Create"); - } - - /***************************************************/ - - [Description("Extracts all BHoM methods to be grouped as Compute items in the UI.")] - [Output("items", "All BHoM methods to be grouped as Compute items.")] - public static IEnumerable ComputeItems() - { - return Engine.Base.Query.BHoMMethodList() - .Where(x => !x.IsNotImplemented() && !x.IsDeprecated() && x.DeclaringType.Name == "Compute"); - } - - /***************************************************/ - - [Description("Extracts all BHoM methods to be grouped as Convert items in the UI.")] - [Output("items", "All BHoM methods to be grouped as Convert items.")] - public static IEnumerable ConvertItems() - { - return Engine.Base.Query.BHoMMethodList() - .Where(x => !x.IsNotImplemented() && !x.IsDeprecated() && x.DeclaringType.Name == "Convert"); - } - - /***************************************************/ - - [Description("Extracts all BHoM methods to be grouped as Modify items in the UI.")] - [Output("items", "All BHoM methods to be grouped as Modify items.")] - public static IEnumerable ModifyItems() - { - return Engine.Base.Query.BHoMMethodList() - .Where(x => !x.IsNotImplemented() && !x.IsDeprecated() && x.DeclaringType.Name == "Modify"); - } - - /***************************************************/ - - [Description("Extracts all BHoM methods to be grouped as Query items in the UI.")] - [Output("items", "All BHoM methods to be grouped as Query items.")] - public static IEnumerable QueryItems() - { - return Engine.Base.Query.BHoMMethodList() - .Where(x => !x.IsNotImplemented() && !x.IsDeprecated() && x.DeclaringType.Name == "Query"); - } - - /***************************************************/ - - [Description("Extracts all BHoM type constructors to be grouped as Create Adapter items in the UI.")] - [Output("items", "All BHoM type constructors to be grouped as Create Adapter items.")] - public static IEnumerable AdapterConstructorItems() - { - return Engine.Base.Query.AdapterTypeList() - .Where(x => x.IsSubclassOf(typeof(BHoMAdapter))) - .SelectMany(x => x.GetConstructors()) - .Where(x => !x.IsNotImplemented() && !x.IsDeprecated()); - } - - /***************************************************/ - - [Description("Extracts all BHoM type constructors to be grouped as Create Request items in the UI.")] - [Output("items", "All BHoM type constructors to be grouped as Create Request items.")] - public static IEnumerable CreateRequestItems() - { - return BH.Engine.Base.Query.BHoMMethodList() - .Where(x => x.DeclaringType.Name == "Create" - && typeof(BH.oM.Data.Requests.IRequest).IsAssignableFrom(x.ReturnType) - && !x.IsDeprecated()) - .OrderBy(x => x.Name); - } - - /***************************************************/ - - [Description("Extracts all BHoM types that implement IRequest interface and have a valid public constructor.")] - [Output("items", "All BHoM types that implement IRequest interface and have a valid public constructor.")] - public static IEnumerable ConstructableRequestItems() - { - return Engine.Base.Query.BHoMTypeList() - .Where(x => x != null && !x.IsNotImplemented() && !x.IsDeprecated() && !x.IsEnum && !x.IsAbstract) - .Where(x => typeof(BH.oM.Data.Requests.IRequest).IsAssignableFrom(x) && x.GetConstructors().Where(c => c.GetParameters().Count() > 0).Count() == 0); - } - - /***************************************************/ - - [Description("Extracts all types valid in BHoM.")] - [Output("items", "All types valid in BHoM.")] - public static IEnumerable TypeItems() - { - return Engine.Base.Query.AllTypeList() - .Where(x => x.Namespace.StartsWith("BH.")) - .Concat(SystemTypes()) - .Where(x => !x.IsNotImplemented() && !x.IsDeprecated()); - } - - /***************************************************/ - - [Description("Extracts all types that have a valid public constructor.")] - [Output("items", "All types that have a valid public constructor.")] - public static IEnumerable ConstructableTypeItems() - { - return Engine.Base.Query.BHoMTypeList() - .Where(x => x != null && !x.IsNotImplemented() && !x.IsDeprecated() && x.IsAutoConstructorAllowed() && !x.IsEnum && !x.IsAbstract) - .Where(x => x.GetConstructors().Where(c => c.GetParameters().Count() > 0).Count() == 0); - } - - /***************************************************/ - - [Description("Extracts all enum types valid in BHoM.")] - [Output("items", "All enum types valid in BHoM.")] - public static IEnumerable EnumItems() - { - return Engine.Base.Query.BHoMEnumList() - .Where(x => !x.IsNotImplemented() && !x.IsDeprecated()); - } - - /***************************************************/ - [Description("Extracts names of all BHoM library items.")] [Output("items", "Names of all BHoM library items.")] public static List LibraryItems() @@ -179,15 +47,6 @@ public static List LibraryItems() } /***************************************************/ - - [Description("Extracts all external methods in BHoM.")] - [Output("items", "All external methods in BHoM.")] - public static List ExternalItems() - { - return Engine.Base.Query.ExternalMethodList(); - } - - /***************************************************/ } } diff --git a/UI_Engine/Query/OutputKeys.cs b/UI_Engine/Query/OutputKeys.cs deleted file mode 100644 index 7c4d2695..00000000 --- a/UI_Engine/Query/OutputKeys.cs +++ /dev/null @@ -1,76 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2026, 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.Engine.Base; -using BH.Engine.Reflection; -using BH.oM.Base.Attributes; -using BH.oM.UI; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Engine.UI -{ - public static partial class Query - { - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - [Description("Gets all the text representations of types that accept the provided type as input.")] - [Input("type", "The type to get the output key from.")] - [Output("Keys", "Text representations of types that accept the provided type as input.")] - public static List OutputKeys(this Type type) - { - if (m_OutputTypeKeys.ContainsKey(type)) - return m_OutputTypeKeys[type]; - else - { - List keys = new List { type } - .Concat(type.BaseTypes().Where(x => x.Namespace?.StartsWith("BH.") == true)) - .Select(x => x.ToText(true)) - .ToList(); - - m_OutputTypeKeys[type] = keys; - return keys; - } - } - - /*************************************/ - /**** Private Fields ****/ - /*************************************/ - - private static Dictionary> m_OutputTypeKeys = new Dictionary>(); - - /*************************************/ - } -} - - - - - - - diff --git a/UI_Engine/Query/SubFoldersForRuntime.cs b/UI_Engine/Query/SubFoldersForRuntime.cs deleted file mode 100644 index 63b886d1..00000000 --- a/UI_Engine/Query/SubFoldersForRuntime.cs +++ /dev/null @@ -1,85 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2026, 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.Engine.Base; -using BH.oM.Base.Attributes; -using BH.oM.UI; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Engine.UI -{ - public static partial class Query - { - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - [Description("Returns the runtime-specific subdirectories of the BHoM Assemblies folder where assemblies compatible with the current .NET runtime can be found. " + - "Returns '.../Assemblies/netfx/' on .NET Framework and '.../Assemblies/netX.0/' on CoreCLR (.NET X).")] - [Output("subFolders", "runtime-specific subdirectories for the BHoM assemblies sorted in the order they should be traversed.")] - public static List SubFoldersForRuntime() - { - if (m_SubFoldersForRuntime != null) - return m_SubFoldersForRuntime; - - - var desc = RuntimeInformation.FrameworkDescription; - if (desc.StartsWith(".NET Framework", StringComparison.OrdinalIgnoreCase)) - { - // Return 'netfx' if the framework is a .NET Framework - m_SubFoldersForRuntime = new List { "netfx" }; - } - else - { - // For .NET Core, return exact TFM first, then descend to lower versions as fallback - m_SubFoldersForRuntime = new List(); - int major = Environment.Version.Major; - for (int v = major; v >= 5; v--) - m_SubFoldersForRuntime.Add($"net{v}.0"); - } - - return m_SubFoldersForRuntime; - } - - - /*************************************/ - /**** Private Fields ****/ - /*************************************/ - - private static List m_SubFoldersForRuntime = null; - - /*************************************/ - } -} - - - - - - - diff --git a/UI_Engine/Query/SystemTypes.cs b/UI_Engine/Query/SystemTypes.cs deleted file mode 100644 index 1a716cb7..00000000 --- a/UI_Engine/Query/SystemTypes.cs +++ /dev/null @@ -1,62 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2026, 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.Engine.Reflection; -using BH.oM.Base.Attributes; -using BH.oM.UI; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Engine.UI -{ - public static partial class Query - { - /*************************************/ - /**** Public Methods ****/ - /*************************************/ - - [Description("Extracts all basic system types.")] - [Output("items", "All basic system types.")] - public static IEnumerable SystemTypes() - { - return new List { typeof(Type), typeof(Enum), - typeof(object), typeof(bool), typeof(byte), - typeof(char), typeof(string), - typeof(float), typeof(double), typeof(decimal), typeof(short), typeof(int), typeof(long), - typeof(DateTime)}; - } - - /*************************************/ - } -} - - - - - - - diff --git a/UI_Engine/Query/Weight.cs b/UI_Engine/Query/Weight.cs index acd05cd3..558ff619 100644 --- a/UI_Engine/Query/Weight.cs +++ b/UI_Engine/Query/Weight.cs @@ -21,6 +21,7 @@ */ using BH.Engine.Base; +using BH.Engine.Reflection; using BH.oM.Base.Attributes; using BH.oM.UI; using System; @@ -28,8 +29,6 @@ using System.ComponentModel; using System.Linq; using System.Reflection; -using System.Text; -using System.Threading.Tasks; namespace BH.Engine.UI { @@ -154,7 +153,7 @@ public static double WeightForInput(this SearchItem item, string validKey) } else if (item.OutputKeys.Any(x => x == validKey)) return 0.75; - else + else return 0; } @@ -172,7 +171,7 @@ public static double WeightForOutput(this SearchItem item, List validKey return 1.0; else if (item.InputKeys.Intersect(validKeys).Any()) return 0.75; - else + else return 0; } diff --git a/UI_oM/CodeElementRecord.cs b/UI_oM/CodeElementRecord.cs deleted file mode 100644 index d90144b6..00000000 --- a/UI_oM/CodeElementRecord.cs +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2026, 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.Base; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.oM.UI -{ - public class CodeElementRecord : IObject - { - /***************************************************/ - /**** Properties ****/ - /***************************************************/ - - public virtual string AssemblyName { get; set; } = ""; - - public virtual DateTime AssemblyModifiedTime { get; set; } = DateTime.MinValue; - - public virtual CodeElementType Type { get; set; } = CodeElementType.Undefined; - - public virtual string DisplayText { get; set; } = ""; - - public virtual string Json { get; set; } = ""; - - public virtual List InputKeys {get; set; } = new List(); - - public virtual List OutputKeys { get; set; } = new List(); - - - /***************************************************/ - } -} - - - - - - diff --git a/UI_oM/CodeElementType.cs b/UI_oM/CodeElementType.cs deleted file mode 100644 index 46f9ce17..00000000 --- a/UI_oM/CodeElementType.cs +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This file is part of the Buildings and Habitats object Model (BHoM) - * Copyright (c) 2015 - 2026, 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 System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.oM.UI -{ - public enum CodeElementType - { - Undefined, - AdapterConstructor, - ConstructableObject, - ConstructableRequest, - Enum, - Library, - Method_Compute, - Method_Convert, - Method_External, - Method_Modify, - Method_Query, - ObjectCreator, - RequestCreator, - Type - } -} - - - - - - diff --git a/UI_oM/SearchItem.cs b/UI_oM/SearchItem.cs index 41c4c381..4631d721 100644 --- a/UI_oM/SearchItem.cs +++ b/UI_oM/SearchItem.cs @@ -24,9 +24,6 @@ using System; using System.Collections.Generic; using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace BH.oM.UI { @@ -46,7 +43,7 @@ public class SearchItem : BHoMObject public virtual double Weight { get; set; } = 1.0; - public virtual string Json { get; set; } = ""; + //public virtual string Json { get; set; } = ""; public virtual List InputKeys { get; set; } = new List();