From 66007bde9a12116af8f57a6c571fd6e59b3f5d98 Mon Sep 17 00:00:00 2001 From: Rasmus Canfjorden Date: Mon, 13 Jan 2020 11:08:00 +0000 Subject: [PATCH 1/2] Desired changes made to the OpenStudio_Adapter --- OpenStudio_Adapter/AdapterActions/Push.cs | 31 +++++++++++++++++++ OpenStudio_Adapter/CRUD/Create.cs | 30 ++---------------- OpenStudio_Adapter/CRUD/Delete.cs | 13 -------- OpenStudio_Adapter/CRUD/Read.cs | 26 ---------------- OpenStudio_Adapter/CRUD/Update.cs | 13 -------- OpenStudio_Adapter/OpenStudioAdapter.cs | 32 ++------------------ OpenStudio_Adapter/OpenStudio_Adapter.csproj | 8 +++-- 7 files changed, 41 insertions(+), 112 deletions(-) create mode 100644 OpenStudio_Adapter/AdapterActions/Push.cs delete mode 100644 OpenStudio_Adapter/CRUD/Delete.cs delete mode 100644 OpenStudio_Adapter/CRUD/Read.cs delete mode 100644 OpenStudio_Adapter/CRUD/Update.cs diff --git a/OpenStudio_Adapter/AdapterActions/Push.cs b/OpenStudio_Adapter/AdapterActions/Push.cs new file mode 100644 index 0000000..f40ec06 --- /dev/null +++ b/OpenStudio_Adapter/AdapterActions/Push.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using BH.oM.Data.Requests; +using BH.oM.Adapter; +using BH.oM.Base; +using System.Reflection; + +namespace BH.Adapter.OpenStudio +{ + public partial class OpenStudioAdapter : BHoMAdapter + { + public override List Push(IEnumerable objects, String tag = "", PushType pushType = PushType.AdapterDefault, ActionConfig actionConfig = null) + { + // If unset, set the pushType to AdapterSettings' value (base AdapterSettings default is FullCRUD). + if (pushType == PushType.AdapterDefault) + pushType = m_AdapterSettings.DefaultPushType; + + IEnumerable objectsToPush = ProcessObjectsForPush(objects, actionConfig); // Note: default Push only supports IBHoMObjects. + + bool success = true; + + CreateModel(objectsToPush.ToList()); + + return success ? objects.ToList() : new List(); + } + } +} \ No newline at end of file diff --git a/OpenStudio_Adapter/CRUD/Create.cs b/OpenStudio_Adapter/CRUD/Create.cs index 2de4149..faee2b4 100644 --- a/OpenStudio_Adapter/CRUD/Create.cs +++ b/OpenStudio_Adapter/CRUD/Create.cs @@ -16,11 +16,13 @@ using BHC = BH.oM.Physical.Constructions; using BHEM = BH.oM.Environment.MaterialFragments; +using BH.oM.Adapter; + namespace BH.Adapter.OpenStudio { public partial class OpenStudioAdapter : BHoMAdapter { - protected override bool Create(IEnumerable objects) + protected override bool ICreate(IEnumerable objects, ActionConfig actionConfig = null) { bool success = true; @@ -29,32 +31,6 @@ protected override bool Create(IEnumerable objects) CreateModel(objects as List); } - /*OpenStudio.Model model = new Model(); - - if (typeof(IBHoMObject).IsAssignableFrom(typeof(T))) - { - List objs = objects.ToList() as List; - - List buildingElements = objs.BuildingElements(); - - List> elementsAsSpaces = buildingElements.BuildSpaces(buildingElements.UniqueSpaceNames()); - - model = CreateModel(elementsAsSpaces, model); - } - - EnergyPlusForwardTranslator translator = new EnergyPlusForwardTranslator(); - Workspace workspace = translator.translateModel(model); - IdfFile idf = workspace.toIdfFile(); - idf.save(OpenStudio.OpenStudioUtilitiesCore.toPath(IDFFilePath)); - /*OpenStudio.Model model = new Model(); - - EnergyPlusForwardTranslator t2 = new EnergyPlusForwardTranslator(); - Workspace w2 = t2.translateModel(model); - IdfFile i2 = w2.toIdfFile(); - - - i2.save(new OpenStudio.Path(OpenStudio.OpenStudioUtilitiesCore.toPath(@"C:\Users\fgreenro\Documents\Repo Code\Test Files & Scripts\BHoM Testing\EnergyPlus_Toolkit\firstTest.idf")), true); - */ return success; } diff --git a/OpenStudio_Adapter/CRUD/Delete.cs b/OpenStudio_Adapter/CRUD/Delete.cs deleted file mode 100644 index 95f8627..0000000 --- a/OpenStudio_Adapter/CRUD/Delete.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Adapter.OpenStudio -{ - public partial class OpenStudioAdapter : BHoMAdapter - { - - } -} diff --git a/OpenStudio_Adapter/CRUD/Read.cs b/OpenStudio_Adapter/CRUD/Read.cs deleted file mode 100644 index eb3fd9c..0000000 --- a/OpenStudio_Adapter/CRUD/Read.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -using System.Collections; -using BH.oM.Base; - -namespace BH.Adapter.OpenStudio -{ - public partial class OpenStudioAdapter : BHoMAdapter - { - protected override IEnumerable Read(Type type, IList indices = null) - { - return null; - } - - public List Read() - { - List bhomObjects = new List(); - - return bhomObjects; - } - } -} diff --git a/OpenStudio_Adapter/CRUD/Update.cs b/OpenStudio_Adapter/CRUD/Update.cs deleted file mode 100644 index 95f8627..0000000 --- a/OpenStudio_Adapter/CRUD/Update.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BH.Adapter.OpenStudio -{ - public partial class OpenStudioAdapter : BHoMAdapter - { - - } -} diff --git a/OpenStudio_Adapter/OpenStudioAdapter.cs b/OpenStudio_Adapter/OpenStudioAdapter.cs index 5529c5b..acaa347 100644 --- a/OpenStudio_Adapter/OpenStudioAdapter.cs +++ b/OpenStudio_Adapter/OpenStudioAdapter.cs @@ -5,7 +5,6 @@ using System.Threading.Tasks; using BH.oM.Base; -//using System.Reflection; using BH.oM.Data.Requests; using BH.oM.Reflection.Attributes; using System.ComponentModel; @@ -22,36 +21,9 @@ public OpenStudioAdapter(string idfFilePath) BH.Engine.Reflection.Compute.RecordWarning("This adapter is under development. Its use is not yet sanctioned for project work. You use this at your own risk. Check the GitHub repo for the latest version and updates on development status"); IDFFilePath = idfFilePath; - AdapterId = "OpenStudio_Adapter"; - Config.UseAdapterId = false; //Set to true when NextId method and id tagging has been implemented + AdapterIdName = "OpenStudio_Adapter"; } - public override List Push(IEnumerable objects, String tag = "", Dictionary config = null) - { - bool success = true; - - //MethodInfo methodInfos = typeof(Enumerable).GetMethod("Cast"); - /*foreach (var typeGroup in objects.GroupBy(x => x.GetType())) - { - MethodInfo mInfo = methodInfos.MakeGenericMethod(new[] { typeGroup.Key }); - var list = mInfo.Invoke(typeGroup, new object[] { typeGroup }); - success &= Create(list as dynamic, false); - }*/ - - CreateModel(objects.ToList().ConvertAll(x => (IBHoMObject)x).ToList()); - - return success ? objects.ToList() : new List(); - } - - public override IEnumerable Pull(IRequest request, Dictionary config = null) - { - if (request is IRequest) - return Read(); - - return new List(); - } - - private string IDFFilePath { get; set; } } -} +} \ No newline at end of file diff --git a/OpenStudio_Adapter/OpenStudio_Adapter.csproj b/OpenStudio_Adapter/OpenStudio_Adapter.csproj index 0628745..02df7dd 100644 --- a/OpenStudio_Adapter/OpenStudio_Adapter.csproj +++ b/OpenStudio_Adapter/OpenStudio_Adapter.csproj @@ -32,6 +32,9 @@ 4 + + ..\..\BHoM_Adapter\Build\Adapter_oM.dll + False ..\..\BHoM\Build\Analytical_oM.dll @@ -97,10 +100,8 @@ + - - - @@ -114,6 +115,7 @@ OpenStudio_oM + Copy /Y "$(ProjectDir)..\libs\msvcp120.dll" "$(ProjectDir)..\Build\msvcp120.dll" From db00835596de5f01d4adb0e96a434b978d981b6a Mon Sep 17 00:00:00 2001 From: Alessio Lombardi Date: Wed, 22 Jan 2020 15:10:38 +0000 Subject: [PATCH 2/2] Required changes. Needs testing. --- OpenStudio_Adapter/AdapterActions/Push.cs | 31 -------------------- OpenStudio_Adapter/CRUD/Create.cs | 2 +- OpenStudio_Adapter/OpenStudioAdapter.cs | 6 ++-- OpenStudio_Adapter/OpenStudio_Adapter.csproj | 1 - 4 files changed, 5 insertions(+), 35 deletions(-) delete mode 100644 OpenStudio_Adapter/AdapterActions/Push.cs diff --git a/OpenStudio_Adapter/AdapterActions/Push.cs b/OpenStudio_Adapter/AdapterActions/Push.cs deleted file mode 100644 index f40ec06..0000000 --- a/OpenStudio_Adapter/AdapterActions/Push.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -using BH.oM.Data.Requests; -using BH.oM.Adapter; -using BH.oM.Base; -using System.Reflection; - -namespace BH.Adapter.OpenStudio -{ - public partial class OpenStudioAdapter : BHoMAdapter - { - public override List Push(IEnumerable objects, String tag = "", PushType pushType = PushType.AdapterDefault, ActionConfig actionConfig = null) - { - // If unset, set the pushType to AdapterSettings' value (base AdapterSettings default is FullCRUD). - if (pushType == PushType.AdapterDefault) - pushType = m_AdapterSettings.DefaultPushType; - - IEnumerable objectsToPush = ProcessObjectsForPush(objects, actionConfig); // Note: default Push only supports IBHoMObjects. - - bool success = true; - - CreateModel(objectsToPush.ToList()); - - return success ? objects.ToList() : new List(); - } - } -} \ No newline at end of file diff --git a/OpenStudio_Adapter/CRUD/Create.cs b/OpenStudio_Adapter/CRUD/Create.cs index faee2b4..9a2a6bb 100644 --- a/OpenStudio_Adapter/CRUD/Create.cs +++ b/OpenStudio_Adapter/CRUD/Create.cs @@ -51,7 +51,7 @@ public bool CreateModel(List objects) EnergyPlusForwardTranslator translator = new EnergyPlusForwardTranslator(); Workspace workspace = translator.translateModel(model); IdfFile idf = workspace.toIdfFile(); - idf.save(global::OpenStudio.OpenStudioUtilitiesCore.toPath(IDFFilePath), true); //setting overwrite file true to avoid appending the surfaces to the exisiting idf file + idf.save(global::OpenStudio.OpenStudioUtilitiesCore.toPath(m_IDFFilePath), true); //setting overwrite file true to avoid appending the surfaces to the exisiting idf file return success; } diff --git a/OpenStudio_Adapter/OpenStudioAdapter.cs b/OpenStudio_Adapter/OpenStudioAdapter.cs index acaa347..7f9735f 100644 --- a/OpenStudio_Adapter/OpenStudioAdapter.cs +++ b/OpenStudio_Adapter/OpenStudioAdapter.cs @@ -19,11 +19,13 @@ public partial class OpenStudioAdapter : BHoMAdapter public OpenStudioAdapter(string idfFilePath) { BH.Engine.Reflection.Compute.RecordWarning("This adapter is under development. Its use is not yet sanctioned for project work. You use this at your own risk. Check the GitHub repo for the latest version and updates on development status"); - IDFFilePath = idfFilePath; + m_IDFFilePath = idfFilePath; AdapterIdName = "OpenStudio_Adapter"; + + m_AdapterSettings.DefaultPushType = oM.Adapter.PushType.CreateOnly; } - private string IDFFilePath { get; set; } + private string m_IDFFilePath; } } \ No newline at end of file diff --git a/OpenStudio_Adapter/OpenStudio_Adapter.csproj b/OpenStudio_Adapter/OpenStudio_Adapter.csproj index 02df7dd..8acf30a 100644 --- a/OpenStudio_Adapter/OpenStudio_Adapter.csproj +++ b/OpenStudio_Adapter/OpenStudio_Adapter.csproj @@ -100,7 +100,6 @@ -