public void Dpow2CobieLite2Ifc()
        {
            var pow = PlanOfWork.OpenJson("NewtownHighSchool.new.dpow");
            const string dir = "..\\..\\Export";
            if (!Directory.Exists(dir))
                Directory.CreateDirectory(dir);
            foreach (var stage in pow.ProjectStages)
            {
                var facility = new FacilityType();
                var d2C = new DPoWToCOBieLiteExchanger(pow, facility, stage);
                d2C.Convert();

                var outputIfc = Path.Combine(dir, stage.Name + ".DPoW.ifc");
                var outputCobieJson = Path.Combine(dir, stage.Name + ".DPoW.json");
                var outputCobieXml = Path.Combine(dir, stage.Name + ".DPoW.xml");
                facility.WriteJson(outputCobieJson);
                facility.WriteXml(outputCobieXml);

                using (var model = XbimModel.CreateTemporaryModel())
                {
                    model.Initialise("Xbim Tester", "XbimTeam", "Xbim.Exchanger", "Xbim Development Team", "3.0");
                    model.ReloadModelFactors();
                    using (var txn = model.BeginTransaction("Convert from COBieLite"))
                    {
                        var c2Ifc = new CoBieLiteToIfcExchanger(facility, model);
                        c2Ifc.Convert();
                        txn.Commit();
                    }
                    model.SaveAs(outputIfc, XbimStorageType.IFC);

                    if (facility.AssetTypes != null)
                        Assert.AreEqual(facility.AssetTypes.Count(), model.Instances.OfType<IfcTypeObject>().Count());
                }
            }
        }
        public void ConvertDPoWToCOBieLite()
        {
            var pow = PlanOfWork.OpenJson("NewtownHighSchool.new.dpow");
            const string dir = "Export";
            if (!Directory.Exists(dir))
                Directory.CreateDirectory(dir);
            var outputs = new List<string>();
            foreach (var stage in pow.ProjectStages)
            {
                var facility = new FacilityType();
                var exchanger = new DPoWToCOBieLiteExchanger(pow, facility, stage);
                exchanger.Convert();
                var output = Path.Combine(dir, stage.Name + ".json");
                outputs.Add(output);
                facility.WriteJson(output);
            }

            //check all result files exist
            foreach (var output in outputs)
            {
                Assert.IsTrue(File.Exists(output));
            }

            //try to reload to make sure serialization and deserilization works in both directions
            foreach (var output in outputs)
            {
                var facility = FacilityType.ReadJson(output);
            }
        }
        public static FacilityType ReadXml(string cobieModelFileName)
        {
            var x           = FacilityType.GetSerializer();
            var reader      = new XmlTextReader(cobieModelFileName);
            var reqFacility = (FacilityType)x.Deserialize(reader);

            reader.Close();
            return(reqFacility);
        }
 public static FacilityType ReadJson(string path)
 {
     using (var textReader = File.OpenText(path))
     {
         var serialiser = FacilityType.GetJsonSerializer();
         var facility   = (FacilityType)serialiser.Deserialize(textReader, typeof(FacilityType));
         textReader.Close();
         return(facility);
     }
 }
 public bool Convert(FacilityType facility, XbimModel model = null)
 {
     if (model == null)
     {
         _model = XbimModel.CreateTemporaryModel();
     }
     else
     {
         _model = model;
     }
     return(WriteFacility(facility));
 }
 public bool Convert(FacilityType facility, IfcStore model = null)
 {
     if (model == null)
     {
         var credentials = new XbimEditorCredentials();
         _model = IfcStore.Create(credentials, IfcSchemaVersion.Ifc4, XbimStoreType.EsentDatabase);
     }
     else
     {
         _model = model;
     }
     return(WriteFacility(facility));
 }
Beispiel #7
0
        static public void WriteJson(TextWriter textWriter, FacilityType theFacility)
        {
            var serializerSettings = new JsonSerializerSettings
            {
                NullValueHandling  = NullValueHandling.Ignore,
                Formatting         = Newtonsoft.Json.Formatting.Indented,
                DateFormatHandling = DateFormatHandling.IsoDateFormat
            };

            serializerSettings.Converters.Add(new StringEnumConverter());
            var serialiser = JsonSerializer.Create(serializerSettings);

            serialiser.Serialize(textWriter, theFacility);
        }
 public bool Convert(FacilityType facility, XbimModel model=null)
 {
     if (model == null)
     {
         _model = XbimModel.CreateTemporaryModel();
         
     }
     else
     {
         _model = model;
         
     }
     return  WriteFacility(facility);
    
 }
 private void ValidateAssets(FacilityType facility, AssetTypeInfoType required, string start)
 {
     //clear list of potentialy dummy assets
     required.Assets = new AssetCollectionType();
     var allValid = true;
     AssetTypeInfoType type;
     var assets = GetAssetsAndType(facility, start, out type);
     foreach (var asset in assets)
     {
         allValid = ValidateAttributes(required, type, asset) && allValid;
         if (asset != null)
             required.Assets.Add(asset);
     }
     required.AssetTypeName = (allValid ? "[T]" : "[F]") + required.AssetTypeName;
 }
Beispiel #10
0
        static public void WriteBson(BinaryWriter binaryWriter, FacilityType theFacility)
        {
            var serializerSettings = new JsonSerializerSettings
            {
                NullValueHandling  = NullValueHandling.Ignore,
                DateFormatHandling = DateFormatHandling.IsoDateFormat
            };

            serializerSettings.Converters.Add(new StringEnumConverter());
            var serialiser = JsonSerializer.Create(serializerSettings);
            // serialize product to BSON
            var writer = new BsonWriter(binaryWriter);

            serialiser.Serialize(writer, theFacility);
        }
 private IEnumerable<AssetInfoType> GetAssetsAndType(FacilityType facility, string start, out AssetTypeInfoType type)
 {
     var result = new List<AssetInfoType>();
     type = null;
     foreach (var assetType in facility.AssetTypes)
     {
         foreach (var instance in assetType.Assets)
         {
             if (instance.AssetName.StartsWith(start))
             {
                 type = assetType;
                 result.Add(instance);
             }
         }
     }
     return result;
 }
        public static void WriteXml(TextWriter textWriter, FacilityType theFacility)
        {
            var namespaces = new XmlSerializerNamespaces(new[]
            {
                new XmlQualifiedName("cobielite", "http://docs.buildingsmartalliance.org/nbims03/cobie/cobielite"),
                new XmlQualifiedName("core", "http://docs.buildingsmartalliance.org/nbims03/cobie/core"),
                new XmlQualifiedName("xsi", "http://www.w3.org/2001/XMLSchema-instance")
            });

            var x = FacilityType.GetSerializer();

            using (var xtw = new XbimCoBieLiteXmlWriter(textWriter))
            {
                xtw.Formatting = Formatting.Indented;
                // Now serialize our object.
                x.Serialize(xtw, theFacility, namespaces);
            }
        }
 private bool WriteFacility(FacilityType facility)
 {
     return(true);
 }
        public static FacilityType ReadJson(TextReader textReader)
        {
            var serialiser = FacilityType.GetJsonSerializer();

            return((FacilityType)serialiser.Deserialize(textReader, typeof(FacilityType)));
        }
        public static void WriteJson(TextWriter textWriter, FacilityType theFacility)
        {
            var serialiser = FacilityType.GetJsonSerializer();

            serialiser.Serialize(textWriter, theFacility);
        }
 public void WriteIIfc(TextWriter textWriter, FacilityType facilityType)
 {
 }
Beispiel #17
0
        public void ReadAndWriteCOBieLiteJSONWithValueConverter()
        {
            #region Facility definition
            var facility = new FacilityType()
            {
                FacilityAttributes = new AttributeCollectionType()
                {
                    Attribute = new List<AttributeType>(new []
                    {
                        new AttributeType()
                        {
                            AttributeName = "Null value",
                            AttributeValue = null
                        },
                        new AttributeType()
                        {
                            AttributeName = "Null boolean item value",
                            AttributeValue = new AttributeValueType()
                            {
                                Item = null,
                                ItemElementName = ItemChoiceType.AttributeBooleanValue
                            }
                        },
                        new AttributeType()
                        {
                            AttributeName = "Null datetime item value",
                            AttributeValue = new AttributeValueType()
                            {
                                Item = null,
                                ItemElementName = ItemChoiceType.AttributeDateTimeValue
                            }
                        },
                        new AttributeType()
                        {
                            AttributeName = "Null date item value",
                            AttributeValue = new AttributeValueType()
                            {
                                Item = null,
                                ItemElementName = ItemChoiceType.AttributeDateValue
                            }
                        },
                        new AttributeType()
                        {
                            AttributeName = "Null decimal item value",
                            AttributeValue = new AttributeValueType()
                            {
                                Item = null,
                                ItemElementName = ItemChoiceType.AttributeDecimalValue
                            }
                        },
                        new AttributeType()
                        {
                            AttributeName = "Null int item value",
                            AttributeValue = new AttributeValueType()
                            {
                                Item = null,
                                ItemElementName = ItemChoiceType.AttributeIntegerValue
                            }
                        },
                        new AttributeType()
                        {
                            AttributeName = "Null monetary item value",
                            AttributeValue = new AttributeValueType()
                            {
                                Item = null,
                                ItemElementName = ItemChoiceType.AttributeMonetaryValue
                            }
                        },
                        new AttributeType()
                        {
                            AttributeName = "Null string item value",
                            AttributeValue = new AttributeValueType()
                            {
                                Item = null,
                                ItemElementName = ItemChoiceType.AttributeStringValue
                            }
                        },
                        new AttributeType()
                        {
                            AttributeName = "Null time item value",
                            AttributeValue = new AttributeValueType()
                            {
                                Item = null,
                                ItemElementName = ItemChoiceType.AttributeTimeValue
                            }
                        },
                        new AttributeType()
                        {
                            AttributeName = "AttributeBooleanValue",
                            AttributeValue = new AttributeValueType()
                            {
                                Item = new BooleanValueType(){BooleanValue = true, BooleanValueSpecified = true},
                                ItemElementName = ItemChoiceType.AttributeBooleanValue
                            }
                        },
                        new AttributeType()
                        {
                            AttributeName = "AttributeDateTimeValue",
                            AttributeValue = new AttributeValueType()
                            {
                                Item = DateTime.Now,
                                ItemElementName = ItemChoiceType.AttributeDateTimeValue
                            }
                        },
                        new AttributeType()
                        {
                            AttributeName = "AttributeDateValue",
                            AttributeValue = new AttributeValueType()
                            {
                                Item = DateTime.Now,
                                ItemElementName = ItemChoiceType.AttributeDateValue
                            }
                        },
                        new AttributeType()
                        {
                            AttributeName = "AttributeTimeValue",
                            AttributeValue = new AttributeValueType()
                            {
                                Item = DateTime.Now,
                                ItemElementName = ItemChoiceType.AttributeTimeValue
                            }
                        },
                        new AttributeType()
                        {
                            AttributeName = "AttributeDecimalValue",
                            AttributeValue = new AttributeValueType()
                            {
                                Item = new AttributeDecimalValueType(){DecimalValue = 0.12},
                                ItemElementName = ItemChoiceType.AttributeDecimalValue
                            }
                        },
                        new AttributeType()
                        {
                            AttributeName = "AttributeIntegerValue",
                            AttributeValue = new AttributeValueType()
                            {
                                Item = new AttributeIntegerValueType(){IntegerValue = 75},
                                ItemElementName = ItemChoiceType.AttributeIntegerValue
                            }
                        },
                        new AttributeType()
                        {
                            AttributeName = "AttributeMonetaryValue",
                            AttributeValue = new AttributeValueType()
                            {
                                Item = new AttributeMonetaryValueType(){MonetaryValue = 45},
                                ItemElementName = ItemChoiceType.AttributeMonetaryValue
                            }
                        },
                        new AttributeType()
                        {
                            AttributeName = "String Attribute",
                            AttributeValue = new AttributeValueType()
                            {
                                Item = new AttributeStringValueType(){StringValue = "String value"},
                                ItemElementName = ItemChoiceType.AttributeStringValue
                }
            }
                    })
                }
            };
            #endregion;

            using (var file = File.CreateText("facility.json"))
            {
                facility.WriteJson(file);
                file.Close();
            }

            //read it back and check the values
            var facility2 = FacilityType.ReadJson("facility.json");
            var attrs = facility2.FacilityAttributes.Attribute;
            var bAttr = attrs.FirstOrDefault(a => a.AttributeValue != null && a.AttributeValue.ItemElementName == ItemChoiceType.AttributeBooleanValue && a.AttributeValue.Item != null);
            var dAttr = attrs.FirstOrDefault(a => a.AttributeValue != null && a.AttributeValue.ItemElementName == ItemChoiceType.AttributeDateValue && a.AttributeValue.Item != null);
            var dtAttr = attrs.FirstOrDefault(a => a.AttributeValue != null && a.AttributeValue.ItemElementName == ItemChoiceType.AttributeDateTimeValue && a.AttributeValue.Item != null);
            var decAttr = attrs.FirstOrDefault(a => a.AttributeValue != null && a.AttributeValue.ItemElementName == ItemChoiceType.AttributeDecimalValue && a.AttributeValue.Item != null);
            var iAttr = attrs.FirstOrDefault(a => a.AttributeValue != null && a.AttributeValue.ItemElementName == ItemChoiceType.AttributeIntegerValue && a.AttributeValue.Item != null);
            var mAttr = attrs.FirstOrDefault(a => a.AttributeValue != null && a.AttributeValue.ItemElementName == ItemChoiceType.AttributeMonetaryValue && a.AttributeValue.Item != null);
            var sAttr = attrs.FirstOrDefault(a => a.AttributeValue != null && a.AttributeValue.ItemElementName == ItemChoiceType.AttributeStringValue && a.AttributeValue.Item != null);
            var tAttr = attrs.FirstOrDefault(a => a.AttributeValue != null && a.AttributeValue.ItemElementName == ItemChoiceType.AttributeTimeValue && a.AttributeValue.Item != null);

            Assert.IsNotNull(bAttr);
            Assert.IsNotNull(dAttr);
            Assert.IsNotNull(dtAttr);
            Assert.IsNotNull(decAttr);
            Assert.IsNotNull(iAttr);
            Assert.IsNotNull(mAttr);
            Assert.IsNotNull(sAttr);
            Assert.IsNotNull(tAttr);

            //check values
            Assert.IsTrue((bAttr.AttributeValue.Item as BooleanValueType).BooleanValue == true);
            var date = (DateTime)dAttr.AttributeValue.Item;
            Assert.IsTrue(date != default(DateTime));
            date = (DateTime)tAttr.AttributeValue.Item;
            Assert.IsTrue(date != default(DateTime));
            date = (DateTime)dtAttr.AttributeValue.Item;
            Assert.IsTrue(date != default(DateTime));

            Assert.IsTrue(Math.Abs((decAttr.AttributeValue.Item as AttributeDecimalValueType).DecimalValue) - 1e-9 < 1e-5);
            Assert.IsTrue((iAttr.AttributeValue.Item as AttributeIntegerValueType).IntegerValue == 75);
            Assert.IsTrue((mAttr.AttributeValue.Item as AttributeMonetaryValueType).MonetaryValue == 45);
            Assert.IsTrue((sAttr.AttributeValue.Item as AttributeStringValueType).StringValue == "String value");

        }
 private bool WriteFacility(FacilityType facility)
 {
     return true;
 }