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);
        }
        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);
        }
示例#3
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);
        }
示例#4
0
        public Product Flatten(JObject jObj)
        {
            var product = jObj.ToObject <Product>();
            List <IProductProperty> props = new List <IProductProperty>();

            foreach (var group in jObj.Properties().Where(p => p.Value.Type == JTokenType.Object || p.Value.Type == JTokenType.Array))
            {
                IPropertyFlattener flattener = PropertyFlattenerFactory.Flattener().For(group.Name);
                var properties = flattener.Flatten(group.Value, string.Empty, null);
                product.AddProperties(group.Name, properties);
            }

            return(product);
        }
        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);
        }
        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);
        }
示例#9
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);
        }
示例#10
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);
        }
 public void Add(string type, IPropertyFlattener flattener)
 {
     flatteners.Add(type, flattener);
 }