From 2242a76d2036c1709dcdcfa073b0cf65b9d7d835 Mon Sep 17 00:00:00 2001 From: adecler Date: Thu, 23 Apr 2020 15:53:05 +0800 Subject: [PATCH 1/4] method to easily generate method keys for versioning --- Versioning_Engine/Compute/VersionKey.cs | 66 +++++++++++++++++++ Versioning_Engine/Query/VersionKey.cs | 75 ++++++++++++++++++++++ Versioning_Engine/Versioning_Engine.csproj | 4 +- 3 files changed, 143 insertions(+), 2 deletions(-) create mode 100644 Versioning_Engine/Compute/VersionKey.cs create mode 100644 Versioning_Engine/Query/VersionKey.cs diff --git a/Versioning_Engine/Compute/VersionKey.cs b/Versioning_Engine/Compute/VersionKey.cs new file mode 100644 index 000000000..4a220d9e4 --- /dev/null +++ b/Versioning_Engine/Compute/VersionKey.cs @@ -0,0 +1,66 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2020, 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; +using MongoDB.Bson; +using MongoDB.Bson.IO; +using MongoDB.Bson.Serialization; +using MongoDB.Bson.Serialization.Serializers; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.IO; +using System.IO.Pipes; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using BH.oM.Reflection.Attributes; + +namespace BH.Engine.Versioning +{ + public static partial class Compute + { + /***************************************************/ + /**** Public Methods ****/ + /***************************************************/ + + [Description("Provide a string representation of a method as it used for versioning by the PreviousVersion attribute.")] + [Input("declaringType", "Type in which the method is declared. You can use just the name of the type or include a (part of the) namespace in front of it.")] + [Input("methodName", "Name of the method. It has to be the exact string")] + [Output("Keys", "String representation for each method that matches the input filters.")] + public static List VersioningKey(string declaringType, string methodName = "") + { + if (methodName == "") + methodName = ".ctor"; + + return Engine.Reflection.Query.AllMethodList() + .Where(x => x.Name == methodName && x.DeclaringType.FullName.EndsWith(declaringType)) + .Select(x => x.VersioningKey()) + .ToList(); + } + + /***************************************************/ + } +} diff --git a/Versioning_Engine/Query/VersionKey.cs b/Versioning_Engine/Query/VersionKey.cs new file mode 100644 index 000000000..e00bad14f --- /dev/null +++ b/Versioning_Engine/Query/VersionKey.cs @@ -0,0 +1,75 @@ +/* + * This file is part of the Buildings and Habitats object Model (BHoM) + * Copyright (c) 2015 - 2020, 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; +using BH.oM.Reflection.Attributes; +using MongoDB.Bson; +using MongoDB.Bson.IO; +using MongoDB.Bson.Serialization; +using MongoDB.Bson.Serialization.Serializers; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.IO; +using System.IO.Pipes; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace BH.Engine.Versioning +{ + public static partial class Query + { + /***************************************************/ + /**** Public Methods ****/ + /***************************************************/ + + [Description("Provide a string representation of a method as it used for versioning by the PreviousVersion attribute.")] + [Input("methodName", "Method to ge tthe key from")] + [Output("Key", "String representation of the method as it will be used by the PreviousVersion attribute.")] + public static string VersioningKey(this MethodBase method) + { + if (method == null) + return ""; + + string name = method.Name; + if (name == ".ctor") + name = ""; + else + name = "." + name; + + string declaringType = method.DeclaringType.FullName; + + string parametersString = ""; + List parameterTypes = method.GetParameters().Select(x => x.ParameterType.ToText(true)).ToList(); + if (parameterTypes.Count > 0) + parametersString = parameterTypes.Aggregate((a, b) => a + ", " + b); + + return declaringType + name + "(" + parametersString + ")"; + } + + /***************************************************/ + } +} diff --git a/Versioning_Engine/Versioning_Engine.csproj b/Versioning_Engine/Versioning_Engine.csproj index e91f84df5..83c2cce62 100644 --- a/Versioning_Engine/Versioning_Engine.csproj +++ b/Versioning_Engine/Versioning_Engine.csproj @@ -47,14 +47,14 @@ + + - - From 2a2570a5570c19df93741fdb858bc0730226dc6c Mon Sep 17 00:00:00 2001 From: adecler Date: Thu, 23 Apr 2020 16:00:03 +0800 Subject: [PATCH 2/4] pushing project file --- Versioning_Engine/Versioning_Engine.csproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Versioning_Engine/Versioning_Engine.csproj b/Versioning_Engine/Versioning_Engine.csproj index 83c2cce62..1ed820f2c 100644 --- a/Versioning_Engine/Versioning_Engine.csproj +++ b/Versioning_Engine/Versioning_Engine.csproj @@ -37,6 +37,10 @@ ..\packages\MongoDB.Bson.2.4.4\lib\net45\MongoDB.Bson.dll + + False + ..\..\BHoM\Build\Reflection_oM.dll + From 80e4efc6f51da6c256618d55bc40aefb1f0bc97a Mon Sep 17 00:00:00 2001 From: adecler Date: Thu, 23 Apr 2020 17:46:46 +0800 Subject: [PATCH 3/4] Fixing dlls references --- Versioning_Engine/Versioning_Engine.csproj | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Versioning_Engine/Versioning_Engine.csproj b/Versioning_Engine/Versioning_Engine.csproj index 1ed820f2c..e6ecef31f 100644 --- a/Versioning_Engine/Versioning_Engine.csproj +++ b/Versioning_Engine/Versioning_Engine.csproj @@ -37,9 +37,10 @@ ..\packages\MongoDB.Bson.2.4.4\lib\net45\MongoDB.Bson.dll - + False ..\..\BHoM\Build\Reflection_oM.dll + False @@ -67,6 +68,7 @@ {b0154405-9390-472d-9b5c-a2280823b18d} Reflection_Engine + False From ac85fd69856fd46be5f18a7d7680ac6a2804b0f7 Mon Sep 17 00:00:00 2001 From: adecler Date: Thu, 23 Apr 2020 17:50:07 +0800 Subject: [PATCH 4/4] fixing attributes of VersionKey methods --- Versioning_Engine/Compute/VersionKey.cs | 4 ++-- Versioning_Engine/Query/VersionKey.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Versioning_Engine/Compute/VersionKey.cs b/Versioning_Engine/Compute/VersionKey.cs index 4a220d9e4..33968d79f 100644 --- a/Versioning_Engine/Compute/VersionKey.cs +++ b/Versioning_Engine/Compute/VersionKey.cs @@ -48,8 +48,8 @@ public static partial class Compute [Description("Provide a string representation of a method as it used for versioning by the PreviousVersion attribute.")] [Input("declaringType", "Type in which the method is declared. You can use just the name of the type or include a (part of the) namespace in front of it.")] - [Input("methodName", "Name of the method. It has to be the exact string")] - [Output("Keys", "String representation for each method that matches the input filters.")] + [Input("methodName", "Name of the method. It has to be the exact string. If the method is a constructor, you can leave this input blank.")] + [Output("keys", "String representation for each method that matches the input filters.")] public static List VersioningKey(string declaringType, string methodName = "") { if (methodName == "") diff --git a/Versioning_Engine/Query/VersionKey.cs b/Versioning_Engine/Query/VersionKey.cs index e00bad14f..0e6cdfb63 100644 --- a/Versioning_Engine/Query/VersionKey.cs +++ b/Versioning_Engine/Query/VersionKey.cs @@ -47,8 +47,8 @@ public static partial class Query /***************************************************/ [Description("Provide a string representation of a method as it used for versioning by the PreviousVersion attribute.")] - [Input("methodName", "Method to ge tthe key from")] - [Output("Key", "String representation of the method as it will be used by the PreviousVersion attribute.")] + [Input("method", "Method to generate the key for")] + [Output("key", "String representation of the method as it will be used by the PreviousVersion attribute.")] public static string VersioningKey(this MethodBase method) { if (method == null)