Exemple #1
0
        protected override bool Create <T>(IEnumerable <T> objects, bool replaceAll = false)
        {
            string fileName = _fileSettings.FullFileName();

            GBXML gbx = new GBXML();

            if (!_xmlSettings.NewFile)
            {
                gbx = XMLReader.Load(_fileSettings.FullFileName()); //Load up the previous file to append to
            }
            if (_xmlSettings.UnitType == UnitType.Imperial)
            {
                gbx.TemperatureUnit      = "F";
                gbx.LengthUnit           = "Feet";
                gbx.AreaUnit             = "SquareFeet";
                gbx.VolumeUnit           = "CubicFeet";
                gbx.UseSIUnitsForResults = "false";
            }

            if (typeof(IBHoMObject).IsAssignableFrom(typeof(T)))
            {
                XML.GBXMLSerializer.Serialize(objects, gbx, fileName, _xmlSettings);
                XMLWriter.Save(fileName, gbx);
            }

            return(true);
        }
Exemple #2
0
        private static void SerializeBuildingSpaces(IEnumerable <BH.oM.XML.Environment.DocumentBuilder> documents, string fileName, XMLSettings settings)
        {
            if (!System.IO.Directory.Exists(fileName))
            {
                System.IO.Directory.CreateDirectory(fileName);
            }

            foreach (BH.oM.XML.Environment.DocumentBuilder db in documents)
            {
                foreach (List <Panel> space in db.ElementsAsSpaces)
                {
                    if (space.IsExternal(db.ElementsAsSpaces))
                    {
                        Dictionary <String, object> spaceData = (space.Where(x => x.CustomData.ContainsKey("Space_Custom_Data")).FirstOrDefault() != null ? space.Where(x => x.CustomData.ContainsKey("Space_Custom_Data")).FirstOrDefault().CustomData["Space_Custom_Data"] as Dictionary <String, object> : new Dictionary <string, object>());
                        string spaceName = "";
                        if (spaceData.ContainsKey("SAM_SpaceName") && spaceData["SAM_SpaceName"] != null)
                        {
                            spaceName = spaceData["SAM_SpaceName"].ToString();
                        }
                        else
                        {
                            spaceName = "Space-" + Guid.NewGuid().ToString().Replace("-", "");
                        }

                        GBXML gbx = new GBXML();
                        SerializeCollection(space, db.Levels, db.UnassignedPanels, gbx, settings);

                        //Document History
                        DocumentHistory DocumentHistory = new DocumentHistory();
                        DocumentHistory.CreatedBy.Date = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss");
                        gbx.DocumentHistory            = DocumentHistory;

                        XMLWriter.Save(fileName + spaceName + ".xml", gbx);
                    }
                }
            }
        }
Exemple #3
0
 private static void SerializeBuildingShell(IEnumerable <BH.oM.XML.Environment.DocumentBuilder> documents, GBXML gbx, XMLSettings settings)
 {
     foreach (BH.oM.XML.Environment.DocumentBuilder db in documents)
     {
         SerializeLevels(db.Levels, db.ElementsAsSpaces, gbx, settings);
         SerializeCollection(db.ElementsAsSpaces.ExternalElements(), db.Levels, db.UnassignedPanels, gbx, settings);
         SerializeCollection(db.ShadingElements, gbx, settings);
     }
 }
Exemple #4
0
        private static void SerializeCollectionFull(IEnumerable <BH.oM.XML.Environment.DocumentBuilder> documents, GBXML gbx, XMLSettings settings)
        {
            foreach (BH.oM.XML.Environment.DocumentBuilder db in documents)
            {
                MongoDB.Bson.BsonDocument bd = BH.Engine.Serialiser.Convert.ToBson(db); //Break the reference clone issue

                BH.oM.XML.Environment.DocumentBuilder dbBroken = (BH.oM.XML.Environment.DocumentBuilder)BH.Engine.Serialiser.Convert.FromBson(bd);
                SerializeLevels(dbBroken.Levels, dbBroken.ElementsAsSpaces, gbx, settings);
                SerializeCollection(dbBroken.ElementsAsSpaces, dbBroken.Levels, dbBroken.UnassignedPanels, gbx, settings);
                SerializeCollection(dbBroken.ShadingElements, gbx, settings);
                SerializeCollection(dbBroken.UnassignedPanels, gbx, settings); //Serialise unassigned panels as shading as an interim measure
            }
        }
Exemple #5
0
        private bool CreateGBXML <T>(IEnumerable <T> objects, XMLConfig config)
        {
            bool success = true;

            if (config.Settings == null)
            {
                BH.Engine.Reflection.Compute.RecordError("Please provide a suitable set of GBXMLSettings with the XMLConfig to determine how the GBXML file should be created");
                return(false);
            }

            GBXMLSettings settings = config.Settings as GBXMLSettings;

            if (settings == null)
            {
                BH.Engine.Reflection.Compute.RecordError("Please provide a suitable set of GBXMLSettings with the XMLConfig to determine how the GBXML file should be created");
                return(false);
            }

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

            if (doc == null)
            {
                BH.Engine.Reflection.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 <IBHoMObject> bhomObjects = new List <IBHoMObject>();

            bhomObjects.AddRange(doc.Buildings);
            bhomObjects.AddRange(doc.Levels);
            bhomObjects.AddRange(doc.ShadingElements);
            bhomObjects.AddRange(doc.UnassignedPanels);

            if (settings.ExportDetail == oM.Adapters.XML.Enums.ExportDetail.Full)
            {
                foreach (List <Panel> p in doc.ElementsAsSpaces)
                {
                    bhomObjects.AddRange(p);
                }
            }
            else if (settings.ExportDetail == oM.Adapters.XML.Enums.ExportDetail.BuildingShell)
            {
                bhomObjects.AddRange(doc.ElementsAsSpaces.ExternalElements());
            }
            else
            {
                BH.Engine.Reflection.Compute.RecordError("The ExportDetail has not been appropriately set. Please set the ExportDetail to continue");
                return(false);
            }

            GBXML gbx = bhomObjects.ToGBXML(settings);

            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
                    });
                }

                XmlSerializerNamespaces xns  = new XmlSerializerNamespaces();
                XmlSerializer           szer = new XmlSerializer(typeof(BH.Adapter.XML.GBXMLSchema.GBXML), overrides);
                TextWriter ms = new StreamWriter(_fileSettings.GetFullFileName());
                szer.Serialize(ms, gbx, xns);
                ms.Close();
            }
            catch (Exception e)
            {
                BH.Engine.Reflection.Compute.RecordError(e.ToString());
                success = false;
            }

            return(success);
        }