Skip to content

Commit

Permalink
6.3 Deployment (#589)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fraser Greenroyd authored Sep 21, 2023
2 parents d50e2ac + 699a2e0 commit fd99b57
Show file tree
Hide file tree
Showing 17 changed files with 190 additions and 901 deletions.
2 changes: 1 addition & 1 deletion XML_Adapter/AdapterActions/Pull.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public override IEnumerable<object> Pull(IRequest request, PullType pullType = P
{
if (!System.IO.File.Exists(_fileSettings.GetFullFileName()))
{
BH.Engine.Base.Compute.RecordError("File does not exist to pull from");
BH.Engine.Base.Compute.RecordError($"The file at {_fileSettings.GetFullFileName()} does not exist to pull from.");
return new List<IBHoMObject>();
}

Expand Down
62 changes: 52 additions & 10 deletions XML_Adapter/AdapterActions/Push.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
using BH.oM.Adapter;
using BH.oM.Base;
using System.Reflection;
using BH.oM.Adapters.XML;
using BH.oM.Adapters.XML.Enums;
using System.IO;

namespace BH.Adapter.XML
{
Expand All @@ -41,26 +44,65 @@ public override List<object> Push(IEnumerable<object> objects, String tag = "",
if (pushType == PushType.AdapterDefault)
pushType = m_AdapterSettings.DefaultPushType;

/*if (_xmlSettings == null)
if (actionConfig == null)
{
BH.Engine.Base.Compute.RecordError("Please set some XML Settings on the XML Adapter before pushing to an XML File");
BH.Engine.Base.Compute.RecordError("Please provide configuration settings to push to an XML file");
return new List<object>();
}*/
}

IEnumerable<IBHoMObject> objectsToPush = ProcessObjectsForPush(objects, actionConfig); // Note: default Push only supports IBHoMObjects.
XMLConfig config = actionConfig as XMLConfig;
if (config == null)
{
BH.Engine.Base.Compute.RecordError("Please provide valid a XMLConfig object for pushing to an XML file");
return new List<object>();
}

bool success = true;
IEnumerable<IBHoMObject> objectsToPush = ProcessObjectsForPush(objects, actionConfig); // Note: default Push only supports IBHoMObjects.

MethodInfo methodInfos = typeof(Enumerable).GetMethod("Cast");
foreach (var typeGroup in objectsToPush.GroupBy(x => x.GetType()))
bool success = false;
switch (config.Schema)
{
MethodInfo mInfo = methodInfos.MakeGenericMethod(new[] { typeGroup.Key });
var list = mInfo.Invoke(typeGroup, new object[] { typeGroup });
success &= ICreate(list as dynamic, actionConfig);
case Schema.CSProject:
success = CreateCSProject(objectsToPush, config);
break;
case Schema.GBXML:
success = CreateGBXML(objectsToPush, config);
break;
case Schema.KML:
success = CreateKML(objectsToPush, config);
break;
case Schema.EnergyPlusLoads:
BH.Engine.Base.Compute.RecordError("The EnergyPlusLoads Schema is not supported for push operations at this time");
success = false;
break;
case Schema.Bluebeam:
BH.Engine.Base.Compute.RecordError("The Bluebeam markup schema is not supported for push operations at this time.");
success = false;
break;
default:
success = CreateDefault(objectsToPush, config);
break;
}

if (success && config.RemoveNils)
RemoveNil(_fileSettings);

return success ? objects.ToList() : new List<object>();
}

private static bool RemoveNil(FileSettings file)
{
var path = Path.Combine(file.Directory, file.FileName);
var xmlFile = File.ReadAllLines(path);

xmlFile = xmlFile.Where(x => !x.Trim().Contains("xsi:nil")).ToArray();
xmlFile = xmlFile.Where(x => x != null).ToArray();

File.Delete(path);
File.WriteAllLines(path, xmlFile);

return true;
}
}
}

Expand Down
102 changes: 0 additions & 102 deletions XML_Adapter/CRUD/Create.cs

This file was deleted.

6 changes: 5 additions & 1 deletion XML_Adapter/CRUD/Default/CreateDefault.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ private bool CreateDefault<T>(IEnumerable<T> objects, XMLConfig config)
foreach (System.Reflection.PropertyInfo pi in bhomProperties)
overrides.Add(typeof(BHoMObject), pi.Name, new XmlAttributes { XmlIgnore = true });

var exportType = typeof(T);
if (exportType == typeof(IBHoMObject))
exportType = objects.First().GetType();

XmlSerializerNamespaces xns = new XmlSerializerNamespaces();
XmlSerializer szer = new XmlSerializer(typeof(T), overrides);
XmlSerializer szer = new XmlSerializer(exportType, overrides);
TextWriter ms = new StreamWriter(_fileSettings.GetFullFileName());
foreach (var obj in objects)
{
Expand Down
8 changes: 7 additions & 1 deletion XML_Adapter/CRUD/Default/ReadDefault.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,14 @@ private IEnumerable<IBHoMObject> ReadDefault(Type type = null, XMLConfig config
object obj = null;
try
{
System.Reflection.PropertyInfo[] bhomProperties = typeof(BHoMObject).GetProperties();
XmlAttributeOverrides overrides = new XmlAttributeOverrides();

foreach (System.Reflection.PropertyInfo pi in bhomProperties)
overrides.Add(typeof(BHoMObject), pi.Name, new XmlAttributes { XmlIgnore = true });

TextReader reader = new StreamReader(_fileSettings.GetFullFileName());
XmlSerializer szer = new XmlSerializer(type);
XmlSerializer szer = new XmlSerializer(type, overrides);
obj = System.Convert.ChangeType(szer.Deserialize(reader), type);
reader.Close();
}
Expand Down
26 changes: 8 additions & 18 deletions XML_Adapter/CRUD/GBXML/CreateGBXML.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
using BH.Engine.Adapter;
using BH.Engine.Adapters.XML;

using BH.oM.Spatial.SettingOut;
using BH.Engine.Environment;

namespace BH.Adapter.XML
{
public partial class XMLAdapter : BHoMAdapter
Expand All @@ -58,29 +61,16 @@ private bool CreateGBXML<T>(IEnumerable<T> objects, XMLConfig config)
return false;
}

GBXMLDocumentBuilder doc = objects.ToList()[0] as GBXMLDocumentBuilder;

if(doc == null)
{
BH.Engine.Base.Compute.RecordError("The GBXML schema requires a full model to be provided as a single push operation. For pushing to the GBXML version, you need to plug your objects into a GBXMLDocumentBuilder which collates the objects for pushing and push that to GBXML via this adapter.");
return false;
}
List<Panel> panels = objects.Where(x => x.GetType() == typeof(Panel)).Cast<Panel>().ToList();

List<IBHoMObject> bhomObjects = new List<IBHoMObject>();
bhomObjects.AddRange(doc.Buildings);
bhomObjects.AddRange(doc.Levels);
bhomObjects.AddRange(doc.ShadingElements);
bhomObjects.AddRange(doc.UnassignedPanels);
bhomObjects.AddRange(objects.Where(x => x.GetType() == typeof(oM.Environment.Elements.Building)).Cast<oM.Environment.Elements.Building>());
bhomObjects.AddRange(objects.Where(x => x.GetType() == typeof(Level)).Cast<Level>());

if (settings.ExportDetail == oM.Adapters.XML.Enums.ExportDetail.Full)
{
foreach (List<Panel> p in doc.ElementsAsSpaces)
bhomObjects.AddRange(p);
}
bhomObjects.AddRange(panels);
else if(settings.ExportDetail == oM.Adapters.XML.Enums.ExportDetail.BuildingShell)
{
bhomObjects.AddRange(doc.ElementsAsSpaces.ExternalElements());
}
bhomObjects.AddRange(panels.ToSpaces().ExternalElements());
else
{
BH.Engine.Base.Compute.RecordError("The ExportDetail has not been appropriately set. Please set the ExportDetail to continue");
Expand Down
62 changes: 0 additions & 62 deletions XML_Adapter/Properties/AssemblyInfo.cs

This file was deleted.

Loading

0 comments on commit fd99b57

Please sign in to comment.