Ejemplo n.º 1
0
        private DataSchema CreateItems(SchemaObject schemaObject)
        {
            var result = new DataSchema {
                Type = SchemaDataTypeExtensions.ConvertFromString(schemaObject.ArrayItemType)
            };

            if (schemaObject.IsDocumentArray)
            {
                result.Properties = CreateProperties(schemaObject);
            }
            return(result);
        }
Ejemplo n.º 2
0
        private DataSchema FindProperty(DataSchema partialObject, SchemaObject findObject)
        {
            var path = findObject.ParentPath.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries).ToList();

            path.AddRange(findObject.Name.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries));

            var schemaToFind = partialObject;

            var isCollectionItemPath = false;

            foreach (var s in path)
            {
                if (schemaToFind == null)
                {
                    return(null);
                }


                if (s != "$")
                {
                    if (isCollectionItemPath)
                    {
                        schemaToFind.Items.Properties.TryGetValue(s, out schemaToFind);
                    }
                    else
                    {
                        schemaToFind.Properties.TryGetValue(s, out schemaToFind);
                    }
                }

                isCollectionItemPath = s == "$";

                //else
                //{
                //	schemaToFind = schemaToFind.Items;
                //}

                if (s == path.LastOrDefault())
                {
                    return(schemaToFind);
                }
            }
            return(partialObject);
        }
Ejemplo n.º 3
0
        private IDictionary <string, DataSchema> CreateProperties(SchemaObject schemaObject)
        {
            var properties = new Dictionary <string, DataSchema>();

            foreach (KeyValuePair <string, dynamic> property in schemaObject.ObjectSchema.Properties)
            {
                var propertyDataSchema = new DataSchema
                {
                    Type = SchemaDataTypeExtensions.ConvertFromString(property.Value.Type)
                };

                properties.Add(property.Key, propertyDataSchema);
            }
            properties.Add("Id", new DataSchema
            {
                Type = SchemaDataType.String
            });
            properties.Add("DisplayName", new DataSchema
            {
                Type = SchemaDataType.String
            });
            return(properties);
        }
Ejemplo n.º 4
0
        private void ProcessSchema(SchemaObject parentInfo, dynamic schema)
        {
            if (schema == null)
            {
                return;
            }

            foreach (var startInfo in schema.Properties)
            {
                //пока не сделано предзаполнение свойств-массивов
                var propertyValue = startInfo.Value;
                if (propertyValue.Type == "Object")
                {
                    if (propertyValue.TypeInfo != null && propertyValue.TypeInfo.DocumentLink != null)
                    {
                        dynamic schemaInner = GetDocumentSchema(propertyValue.TypeInfo.DocumentLink.DocumentId);

                        var linkSchemaObject = new SchemaObject(parentInfo, startInfo.Key, propertyValue.Caption,
                                                                startInfo.Value, schemaInner);

                        if (_typeInfoChain.Any(t => t.DocumentId == propertyValue.TypeInfo.DocumentLink.DocumentId))
                        {
                            continue;
                        }

                        _typeInfoChain.Add(propertyValue.TypeInfo.DocumentLink);

                        if (OnObjectProperty != null)
                        {
                            OnObjectProperty(linkSchemaObject);
                        }

                        //добавляем свойство с идентификатором объекта (которое отсутствует в описаниях моделей)
                        var schemaId = new SchemaObject(linkSchemaObject, "Id", "Id", null, schemaInner);
                        if (OnPrimitiveProperty != null)
                        {
                            OnPrimitiveProperty(schemaId);
                        }


                        if (propertyValue.TypeInfo.DocumentLink.Inline == null ||
                            propertyValue.TypeInfo.DocumentLink.Inline == false)
                        {
                            var schemaDisplayProperty = new SchemaObject(linkSchemaObject, "DisplayName", "DisplayName",
                                                                         null, schemaInner);
                            if (OnPrimitiveProperty != null)
                            {
                                OnPrimitiveProperty(schemaDisplayProperty);
                            }
                        }

                        //---
                        var linkEntry = new LinkEntry
                        {
                            DocumentId = propertyValue.TypeInfo.DocumentLink.DocumentId,
                            Schema     = schemaInner
                        };

                        if (!_entries.HasEntry(linkEntry))
                        {
                            _entries.Add(linkEntry);

                            if (linkSchemaObject.Inline)
                            {
                                ProcessSchema(linkSchemaObject, schemaInner);
                            }
                        }
                        //---
                    }
                }
                else if (propertyValue.Type == "Array")
                {
                    if (OnArrayProperty != null)
                    {
                        //если массив содержит элементы типа "объект" то получаем метаданные объекта данного типа
                        dynamic schemaObject = null;
                        if (propertyValue.Items.Type == "Object" && propertyValue.Items.TypeInfo != null &&
                            propertyValue.Items.TypeInfo.DocumentLink != null)
                        {
                            schemaObject = GetDocumentSchema(propertyValue.Items.TypeInfo.DocumentLink.DocumentId);
                        }

                        //обрабатываем сам массив
                        var arraySchemaObject = new SchemaObject(parentInfo, startInfo.Key, propertyValue.Caption,
                                                                 startInfo.Value,
                                                                 schemaObject);

                        OnArrayProperty(arraySchemaObject);

                        //если массив содержит ссылочные типы, то выполняем анализ типа элемента массива
                        if (schemaObject != null)
                        {
                            var linkEntry = new LinkEntry
                            {
                                DocumentId = propertyValue.Items.TypeInfo.DocumentLink.DocumentId,
                                Schema     = schemaObject
                            };

                            var linkToObjectIsCycleReference = _entries.HasEntry(linkEntry);
                            if (!linkToObjectIsCycleReference)
                            {
                                _entries.Add(linkEntry);
                                ProcessSchema(arraySchemaObject, schemaObject);
                            }
                        }
                    }
                }
                else
                {
                    if (OnPrimitiveProperty != null)
                    {
                        OnPrimitiveProperty(new SchemaObject(parentInfo, startInfo.Key, propertyValue.Caption,
                                                             startInfo.Value, null));
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void FillDataSchema(DataSchema partialObject, SchemaObject schemaObject)
        {
            var root    = schemaObject;
            var members = new List <SchemaObject>();

            while (root != null)
            {
                members.Add(root);
                root = root.Parent;
            }

            members.Reverse();

            partialObject.Properties = partialObject.Properties ?? new Dictionary <string, DataSchema>();

            for (var i = 0; i < members.Count; i++)
            {
                if (partialObject.Properties.ContainsKey(members[i].Name))
                {
                    continue;
                }


                if (members[i].Parent == null)
                {
                    if (members[i].IsArray)
                    {
                        partialObject.Properties.Add(members[i].Name, new DataSchema
                        {
                            Type  = SchemaDataTypeExtensions.ConvertFromString(members[i].Type),
                            Items = CreateItems(members[i])
                        });
                    }
                    else if (members[i].IsDocumentLink)
                    {
                        partialObject.Properties.Add(members[i].Name, new DataSchema
                        {
                            Type       = SchemaDataTypeExtensions.ConvertFromString(members[i].Type),
                            Properties = CreateProperties(members[i])
                        });
                    }
                    else
                    {
                        partialObject.Properties.Add(members[i].Name, new DataSchema
                        {
                            Type = SchemaDataTypeExtensions.ConvertFromString(members[i].Type)
                        });
                    }
                }
                else
                {
                    var dataSchema = FindProperty(partialObject, members[i]);

                    if (members[i].IsArray)
                    {
                        dataSchema.Type  = SchemaDataTypeExtensions.ConvertFromString(members[i].Type);
                        dataSchema.Items = CreateItems(members[i]);
                    }
                    else if (members[i].IsDocumentLink)
                    {
                        dataSchema.Type       = SchemaDataTypeExtensions.ConvertFromString(members[i].Type);
                        dataSchema.Properties = CreateProperties(members[i]);
                    }
                    else
                    {
                        dataSchema.Type = SchemaDataTypeExtensions.ConvertFromString(members[i].Type);
                    }
                }
            }
        }