public override IContentType Parse(Stream stream, IReadonlyContentTypeStore templateStore)
        {
            TextReader reader = new StreamReader(stream, Encoding.UTF8);

            Internals.ContentType tmp = JsonConvert.DeserializeObject <Internals.ContentType>(reader.ReadToEnd());

            List <IField> fields = new List <IField>();

            foreach (Internals.Field field in tmp.Fields)
            {
                DataType dataType = DataType.Array;
                if (Enum.TryParse <DataType>(field.DataType, true, out dataType))
                {
                    IField newField = null;
                    if (dataType.IsSimpleDataType())
                    {
                        newField = this.CreateSimpleField(field.Name, (Int32)dataType);
                    }
                    else if (dataType == DataType.Array)
                    {
                        newField = this.CreateArrayField(field.Name, (Int32)dataType);
                    }
                    else if (dataType == DataType.Object)
                    {
                        newField = this.CreateObjectField(field.Name, (Int32)dataType);
                    }
                    fields.Add(newField);
                }
                else
                {
                    throw new Exception($"Unknown DataType {field.DataType}");
                }
            }

            IContentType template = new ContentType {
                Name        = tmp.Name,
                ParentTypes = tmp.ParentTypes,
                Fields      = fields
            };

            return(this.Merge(template, tmp.ParentTypes, templateStore));
        }
Esempio n. 2
0
 public abstract IContentType Parse(Stream stream, IReadonlyContentTypeStore contentTypeStore);
Esempio n. 3
0
        protected virtual IContentType Merge(IContentType primary, String[] parentTypes, IReadonlyContentTypeStore contentTypeStore)
        {
            // TODO: Stop circular reference, somehow!!!
            if (parentTypes != null && parentTypes.Any())
            {
                // Let's get the least important, least important is last in the array!
                IContentType mergedParents = contentTypeStore.Get(parentTypes.Reverse().First());
                // Iterate the parent types, least first, and merge them.
                foreach (String parentType in parentTypes.Reverse().Skip(1))
                {
                    mergedParents = this.Merge(contentTypeStore.Get(parentType), mergedParents);
                }

                primary = this.Merge(primary, mergedParents);
            }

            return(primary);
        }
 public CreateContentCommandHander(IReadonlyContentTypeStore contentTypes)
 {
     this.contentTypes = contentTypes;
 }