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 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); var credentials = new XbimEditorCredentials() { ApplicationDevelopersName = "XbimTeam", ApplicationFullName = "Xbim.Exchanger", EditorsOrganisationName = "Xbim Development Team", EditorsFamilyName = "Xbim Tester", ApplicationVersion = "3.0" }; using (var model = IfcStore.Create(credentials, IfcSchemaVersion.Ifc2X3, XbimStoreType.InMemoryModel)) { using (var txn = model.BeginTransaction("Convert from COBieLite")) { var c2Ifc = new CoBieLiteToIfcExchanger(facility, model); c2Ifc.Convert(); txn.Commit(); } model.SaveAs(outputIfc, IfcStorageType.Ifc); if (facility.AssetTypes != null) { Assert.AreEqual(facility.AssetTypes.Count(), model.Instances.OfType <IfcTypeObject>().Count()); } } } }
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 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"); }