Esempio n. 1
0
        public void FlattenWallProductTest()
        {
            BuildFactory();
            //materials


            var expected = new Product()
            {
                GlobalId = "1xR1Dku9TCdxjX7pW7MV0W",
                Id       = 1198587222,
                Type     = "IfcWallStandardCase"
            };
            var testdata  = Helpers.TestFiles.GetFile("wall.json");
            var jObj      = JObject.Parse(testdata);
            var flattener = new ProductFlattener();
            var product   = flattener.Flatten(jObj);

            Assert.AreEqual(expected.Id, product.Id);
            Assert.AreEqual(expected.GlobalId, product.GlobalId);
            Assert.AreEqual(expected.Type, product.Type);
            Assert.IsNull(product.Name);
            string json = JsonConvert.SerializeObject(product, Formatting.Indented, new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            });

            File.WriteAllText(@"C:\Temp\wall.json", json);
            PropertyFlattenerFactory.Flattener().Clear();
        }
        public IEnumerable <IProductProperty> Flatten(JToken jToken, string desc, string group = null, List <string> parents = null)
        {
            var properties = new List <IProductProperty>();

            if (jToken.Type == JTokenType.Array)
            {
                JArray jArray = (JArray)jToken;
                foreach (var item in jArray.Where(j => j.Type == JTokenType.Object))
                {
                    JObject jObj = (JObject)item;
                    if (jObj.Property("attributes") != null)
                    {
                        IPropertyFlattener flattener = PropertyFlattenerFactory.Flattener().For("attributes");
                        properties.AddRange(flattener.Flatten(jObj.Property("attributes").Value, null, null, null));
                    }
                    if (jObj.Property("properties") != null)
                    {
                        JObject propertiesObj = (JObject)jObj.Property("properties").Value;
                        foreach (var prop in propertiesObj.Properties().Where(p => p.Value.Type == JTokenType.Object))
                        {
                            var childValue = (JObject)prop.Value;
                            if (childValue.Property("ifcType") != null)
                            {
                                IPropertyFlattener flattener = PropertyFlattenerFactory.Flattener().For(childValue.Property("ifcType").Value.ToObject <string>());
                                properties.AddRange(flattener.Flatten(childValue, prop.Name, jObj.Property("name").ToObject <String>(), null));
                            }
                        }
                    }
                }
            }
            return(properties);
        }
Esempio n. 3
0
        public void FlattenBeamProductTest()
        {
            BuildFactory();

            var expected = new Product()
            {
                GlobalId = "1ldHk5baXAWBB4kMiZXzAO",
                Id       = 912184375,
                Name     = "Balk-004",
                Type     = "IfcBeam"
            };
            var testdata  = Helpers.TestFiles.GetFile("beam.json");
            var jObj      = JObject.Parse(testdata);
            var flattener = new ProductFlattener();
            var product   = flattener.Flatten(jObj);

            Assert.AreEqual(expected.Id, product.Id);
            Assert.AreEqual(expected.GlobalId, product.GlobalId);
            Assert.AreEqual(expected.Type, product.Type);
            Assert.AreEqual(expected.Name, product.Name);
            string json = JsonConvert.SerializeObject(product, Formatting.Indented, new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            });

            File.WriteAllText(@"C:\Temp\beam.json", json);
            PropertyFlattenerFactory.Flattener().Clear();
        }
        public IEnumerable <IProductProperty> Flatten(JToken jToken, string desc, string group = null, List <string> parents = null)
        {
            var properties = new List <IProductProperty>();

            if (jToken.Type == JTokenType.Array)
            {
                JArray jArray = (JArray)jToken;
                foreach (var item in jArray.Where(j => j.Type == JTokenType.Object))
                {
                    JObject jObj = (JObject)item;
                    if (jObj.Property("attributes") != null)
                    {
                        IPropertyFlattener flattener = PropertyFlattenerFactory.Flattener().For("attributes");
                        properties.AddRange(flattener.Flatten(jObj.Property("attributes").Value, null, group: group));
                    }
                    if (jObj.Property("quantities") != null)
                    {
                        JObject quantatiesObj = (JObject)jObj.Property("quantities").Value;
                        foreach (var prop in quantatiesObj.Properties())
                        {
                            var converter = new ExpandoObjectConverter();

                            dynamic            propValue = JsonConvert.DeserializeObject <ExpandoObject>(prop.Value.ToString(), converter);
                            IPropertyFlattener flattener = PropertyFlattenerFactory.Flattener().For(propValue.value.type);
                            parents = new List <string>(new string[] { jObj.Property("name").Value.ToObject <string>() });
                            properties.AddRange(flattener.Flatten(((JObject)prop.Value).Property("value").Value, prop.Name, group, parents));
                        }
                    }
                }
            }
            return(properties);
        }
Esempio n. 5
0
        public IEnumerable <IProductProperty> Flatten(JToken jToken, string desc, string group = null, List <string> parents = null
                                                      )
        {
            var properties = new List <IProductProperty>();

            if (jToken.Type == JTokenType.Object)
            {
                JObject jObj  = (JObject)jToken;
                var     value = jObj.Property("value");
                if (value != null && value.Value.Type == JTokenType.Object && ((JObject)value.Value).Property("attributes") != null)
                {
                    var att = ((JObject)value.Value).Property("attributes");
                    IPropertyFlattener flattener = PropertyFlattenerFactory.Flattener().For("attributes");
                    if (desc != null)
                    {
                        if (parents == null)
                        {
                            parents = new List <string>(new string[] { desc });
                        }
                        else
                        {
                            parents.Add(desc);
                        }
                    }
                    var newList = parents != null ? new List <string>(parents) : null;
                    properties.AddRange(flattener.Flatten(att.Value, null, group, newList));
                }
            }
            return(properties);
        }
        public IEnumerable <IProductProperty> Flatten(JToken jToken, string desc, string group = null, List <string> parents = null)
        {
            var properties = new List <IProductProperty>();

            if (jToken.Type == JTokenType.Object)
            {
                JObject jObj = (JObject)jToken;
                foreach (var childProp in jObj.Properties().Where(p => p.Value.Type == JTokenType.Object))
                {
                    IPropertyFlattener flattener = PropertyFlattenerFactory.Flattener().For(childProp.Name);
                    properties.AddRange(flattener.Flatten(childProp.Value, desc, group, parents));
                }
            }
            return(properties);
        }
        public IEnumerable <IProductProperty> Flatten(JToken jToken, string desc, string group = null, List <string> parents = null)
        {
            var properties = new List <IProductProperty>();

            if (jToken.Type == JTokenType.Object)
            {
                JObject jObj = (JObject)jToken;
                if (jObj.Property("type") != null)
                {
                    IPropertyFlattener flattener = PropertyFlattenerFactory.Flattener().For(jObj.Property("type").Value.ToObject <string>());
                    properties.AddRange(flattener.Flatten(jObj, desc, group, parents));
                }
            }
            return(properties);
        }
Esempio n. 8
0
 private void BuildFactory()
 {
     PropertyFlattenerFactory.Flattener().Add("string", new BasicPropertyFlattener());
     PropertyFlattenerFactory.Flattener().Add("enum", new BasicPropertyFlattener());
     PropertyFlattenerFactory.Flattener().Add("number", new NumberPropertyFlattener());
     PropertyFlattenerFactory.Flattener().Add("boolean", new NumberPropertyFlattener());
     PropertyFlattenerFactory.Flattener().Add("attributes", new AttributesPropertyFlattener());
     PropertyFlattenerFactory.Flattener().Add("quantitySets", new QuantitiesPropertyFlattener());
     PropertyFlattenerFactory.Flattener().Add("propertySets", new PropertySetsPropertyFlattener());
     PropertyFlattenerFactory.Flattener().Add("nominalValue", new NominalValueFlattener());
     PropertyFlattenerFactory.Flattener().Add("types", new TypesPropertyFlattener());
     PropertyFlattenerFactory.Flattener().Add("materials", new MaterialsPropertyFlattener());
     PropertyFlattenerFactory.Flattener().Add("presentationLayers", new MaterialsPropertyFlattener());
     PropertyFlattenerFactory.Flattener().Add("IfcPropertySingleValue", new PropertySingleValueFlattener());
     PropertyFlattenerFactory.Flattener().Add("IfcComplexProperty", new ComplexPropertyFlattener());
     PropertyFlattenerFactory.Flattener().Add("integer", new IntegerPropertyFlattener());
     PropertyFlattenerFactory.Flattener().Add("array", new ArrayPropertyFlattener());
     PropertyFlattenerFactory.Flattener().Add("object", new ObjectPropertyFlattener());
 }
        public IEnumerable <IProductProperty> Flatten(JToken jToken, string desc, string group = null, List <string> parents = null)
        {
            var properties = new List <IProductProperty>();

            if (jToken.Type == JTokenType.Array)
            {
                JArray jArray = (JArray)jToken;
                foreach (var item in jArray.Where(j => j.Type == JTokenType.Object))
                {
                    JObject jObj = (JObject)item;
                    if (jObj.Property("attributes") != null)
                    {
                        IPropertyFlattener flattener = PropertyFlattenerFactory.Flattener().For("attributes");
                        properties.AddRange(flattener.Flatten(jObj.Property("attributes").Value, null, group, parents));
                    }
                }
            }
            return(properties);
        }
        public IEnumerable <IProductProperty> Flatten(JToken jToken, string desc, string group = null, List <string> parents = null)
        {
            var properties = new List <IProductProperty>();

            if (jToken.Type == JTokenType.Object)
            {
                JObject jObj = (JObject)jToken;
                foreach (var property in jObj.Properties().Where(p => p.Value.Type == JTokenType.Object))
                {
                    var valueObj      = (JObject)property.Value;
                    var valueProperty = valueObj.Property("type");
                    if (valueProperty != null)
                    {
                        IPropertyFlattener flattener = PropertyFlattenerFactory.Flattener().For(valueProperty.Value.ToObject <string>());
                        properties.AddRange(flattener.Flatten(valueObj, property.Name, group, parents));
                    }
                }
            }
            return(properties);
        }
Esempio n. 11
0
        public IEnumerable <IProductProperty> Flatten(JToken jToken, string desc, string group = null, List <string> parents = null)
        {
            var properties = new List <IProductProperty>();

            if (jToken.Type == JTokenType.Object)
            {
                JObject jObj = (JObject)jToken;
                if (jObj.Property("properties") != null && jObj.Property("properties").Value.Type == JTokenType.Object)
                {
                    var propertiesObj = (JObject)jObj.Property("properties").Value;
                    if (desc != null)
                    {
                        if (parents == null)
                        {
                            parents = new List <string>(new string[] { desc });
                        }
                        else
                        {
                            parents.Add(desc);
                        }
                    }
                    var newList = parents != null ? new List <string>(parents) : null;
                    foreach (var prop in propertiesObj.Properties().Where(p => p.Value.Type == JTokenType.Object))
                    {
                        var childValue = (JObject)prop.Value;
                        if (childValue.Property("ifcType") != null)
                        {
                            IPropertyFlattener flattener = PropertyFlattenerFactory.Flattener().For(childValue.Property("ifcType").Value.ToObject <string>());

                            properties.AddRange(flattener.Flatten(childValue, prop.Name, group, newList));
                        }
                    }
                }
            }
            return(properties);
        }
Esempio n. 12
0
        public IEnumerable <IProductProperty> Flatten(JToken jToken, string desc, string group = null, List <string> parents = null)
        {
            var properties = new List <IProductProperty>();

            if (jToken.Type == JTokenType.Object)
            {
                JObject jObj  = (JObject)jToken;
                var     value = jObj.Property("value");
                if (value != null && value.Value.Type == JTokenType.Array)
                {
                    JArray jArray = (JArray)value.Value;
                    if (desc != null)
                    {
                        if (parents == null)
                        {
                            parents = new List <string>(new string[] { desc });
                        }
                        else
                        {
                            parents.Add(desc);
                        }
                    }
                    var newList = parents != null ? new List <string>(parents) : null;
                    foreach (var item in jArray.Where(j => j.Type == JTokenType.Object))
                    {
                        JObject childjObj = (JObject)item;
                        if (childjObj.Property("type") != null)
                        {
                            IPropertyFlattener flattener = PropertyFlattenerFactory.Flattener().For(childjObj.Property("type").Value.ToObject <string>());
                            properties.AddRange(flattener.Flatten(childjObj, null, group, newList));
                        }
                    }
                }
            }
            return(properties);
        }