Пример #1
0
        private IJsonMetadata GetMetadata(IMetadataBuilderContext context, MetadataIdentity identity)
        {
            MetadataIdentity  parentIdentity = identity.Parent();
            IJsonMetadata     parent         = context.GetMetadata <IJsonMetadata>(parentIdentity.Name) ?? this.GetMetadata(context, parentIdentity);
            IRelationMetadata relation       = identity.GetMetadata <IRelationMetadata>();

            if (parent == null || relation == null)
            {
                return(null);
            }

            JsonMetadata metadata = new JsonMetadata(relation);

            if (this.HasJsonAttribute(relation) || relation.HasFlag(RelationMetadataFlags.Item))
            {
                metadata.MemberOf = metadata;
                metadata.IsRoot   = true;
                metadata.Path     = "$";
            }
            else
            {
                metadata.MemberOf = parent.MemberOf;
                metadata.IsRoot   = false;
                metadata.Path     = $"{parent.Path}.{this.GetPropertyNameFromContract(metadata)}";
            }

            context.AddMetadata <IJsonMetadata>(metadata);

            return(metadata);
        }
        private ProjectionMetadata CreateAndAddMetadata(IMetadataBuilderContext context, IRelationMetadata relation)
        {
            ProjectionMetadata metadata = this.CreateBaseMetadata(context, relation);

            context.AddMetadata <IProjectionMetadata>(metadata);

            return(metadata);
        }
Пример #3
0
        public void Initialize(IMetadataBuilderContext context)
        {
            JsonMetadata metadata = new JsonMetadata(context.Relation);

            metadata.MemberOf = metadata;
            metadata.Path     = "$";
            metadata.IsRoot   = true;

            context.AddMetadata <IJsonMetadata>(metadata);
        }
Пример #4
0
        private IEnumerable <ReferenceMetadata> CreateProperties(IMetadataBuilderContext context, ReferenceMetadata parent)
        {
            foreach (IRelationMetadata attribute in parent.Relation.Properties)
            {
                ReferenceMetadata metadata = this.CreateBaseMetadata(context, attribute, parent);

                context.AddMetadata <IReferenceMetadata>(metadata);

                yield return(metadata);
            }
        }
        public void Initialize(IMetadataBuilderContext context)
        {
            IRelationMetadata relation = context.Schema.GetMetadata <IRelationMetadata>(context.Identity.Name);

            if (relation == null)
            {
                throw MetadataNotFoundException.FromMetadata <IRelationMetadata>(context.Identity);
            }

            context.AddMetadata <IReferenceMetadata>(this.CreateBaseMetadata(context, relation, null));
        }
Пример #6
0
        private ReferenceMetadata CreateItem(IMetadataBuilderContext context, ReferenceMetadata parent)
        {
            if (parent.Relation.Item != null)
            {
                ReferenceMetadata metadata = this.CreateBaseMetadata(context, parent.Relation.Item, parent);

                context.AddMetadata <IReferenceMetadata>(metadata);

                return(metadata);
            }

            return(null);
        }
        private TableMetadata CreateMetadata(IMetadataBuilderContext context, IRelationMetadata relation, TableMetadata parent)
        {
            TableMetadata metadata = new TableMetadata(relation);

            metadata.Item = this.CreateItem(context, metadata);

            this.ApplyContracts(metadata, parent);

            metadata.Properties = new Lazy <IReadOnlyList <TableMetadata> >(() => this.CreateProperties(context, metadata).ToList());

            context.AddMetadata <ITableMetadata>(metadata);

            return(metadata);
        }
Пример #8
0
        private TableMetadata CreateBaseMetadata(IMetadataBuilderContext context, IRelationMetadata attribute, TableMetadata parent)
        {
            TableMetadata metadata = new TableMetadata(attribute);

            metadata.Item       = this.CreateItem(context, metadata);
            metadata.Properties = new Lazy <IReadOnlyList <TableMetadata> >(() => this.CreateProperties(context, metadata).ToList());

            this.AddTableMetadata(metadata);
            this.AddColumnMetadata(metadata, parent);

            context.AddMetadata <ITableMetadata>(metadata);

            return(metadata);
        }
        private RelationMetadata CreateItem(IMetadataBuilderContext context, RelationMetadata parent)
        {
            IRelationListContract contract = this.GetListContract(parent);

            if (contract == null)
            {
                return(null);
            }

            MetadataIdentity itemId = parent.Identity.Child(contract.ItemName ?? "Item");

            RelationMetadata metadata = new RelationMetadata(itemId)
            {
                Parent     = parent,
                Type       = contract.ItemType,
                Flags      = RelationMetadataFlags.Item | RelationMetadataFlags.Property,
                ReadIndex  = contract.ReadIndex,
                WriteIndex = contract.WriteIndex,
            };

            metadata.MemberOf    = metadata;
            metadata.Item        = this.CreateItem(context, metadata);
            metadata.Properties  = this.CreateLazy(() => this.CreateProperties(context, metadata));
            metadata.Annotations = this.CreateAnnotations(metadata).ToList();

            if (this.IsMetadataRecursive(metadata))
            {
                metadata.Flags |= RelationMetadataFlags.Recursive;
            }

            if (contract.ReadIndex != null)
            {
                metadata.Flags |= RelationMetadataFlags.Readable;
            }

            if (contract.WriteIndex != null)
            {
                metadata.Flags |= RelationMetadataFlags.Writable;
            }

            if (metadata.Item != null)
            {
                metadata.Flags |= RelationMetadataFlags.List;
            }

            context.AddMetadata <IRelationMetadata>(metadata);

            return(metadata);
        }
        private ProjectionMetadata CreateItem(IMetadataBuilderContext context, ProjectionMetadata parent)
        {
            if (parent.Relation.Item != null)
            {
                ProjectionMetadata metadata = this.CreateBaseMetadata(context, parent.Relation.Item);

                metadata.List = parent;

                context.AddMetadata <IProjectionMetadata>(metadata);

                return(metadata);
            }

            return(null);
        }
Пример #11
0
        private ProjectionMetadata GetMetadata(IMetadataBuilderContext context, IRelationMetadata relation, IProjectionMetadata parent)
        {
            ProjectionMetadata metadata = new ProjectionMetadata(relation);

            context.AddMetadata <IProjectionMetadata>(metadata);

            metadata.Properties = this.CreateLazy(() => this.CreateProperties(context, metadata));
            metadata.Item       = this.CreateItem(context, metadata);
            metadata.Flags      = this.GetFlags(metadata);

            this.CreateTableMetadata(metadata);
            this.CreateInputMetadata(context, metadata, parent);

            return(metadata);
        }
Пример #12
0
        private RelationMetadata CreateProperty(IMetadataBuilderContext context, RelationMetadata parent, MemberInfo memberInfo)
        {
            MetadataIdentity attributeId = parent.Identity.Child(memberInfo.Name);

            RelationMetadata metadata = new RelationMetadata(attributeId)
            {
                Type     = this.GetMemberType(memberInfo),
                Parent   = parent,
                Member   = memberInfo,
                MemberOf = parent.MemberOf,
                Flags    = RelationMetadataFlags.Property,
            };

            metadata.Item        = this.CreateItem(context, metadata);
            metadata.Properties  = this.CreateLazy(() => this.CreateProperties(context, metadata));
            metadata.Annotations = this.CreateAnnotations(metadata).ToList();

            if (metadata.Item != null)
            {
                metadata.Flags |= RelationMetadataFlags.List;
            }

            if (this.IsMetadataRecursive(metadata))
            {
                metadata.Flags |= RelationMetadataFlags.Recursive;
            }

            if (memberInfo is PropertyInfo pi)
            {
                if (pi.CanRead)
                {
                    metadata.Flags |= RelationMetadataFlags.Readable;
                }

                if (pi.CanWrite)
                {
                    metadata.Flags |= RelationMetadataFlags.Writable;
                }
            }
            else if (memberInfo is FieldInfo)
            {
                metadata.Flags |= RelationMetadataFlags.Readable | RelationMetadataFlags.Writable;
            }

            context.AddMetadata <IRelationMetadata>(metadata);

            return(metadata);
        }
Пример #13
0
        public void Initialize(IMetadataBuilderContext context)
        {
            IRelationMetadata relation = context.Identity.GetMetadata <IRelationMetadata>();

            if (relation == null)
            {
                throw MetadataNotFoundException.FromMetadata <IRelationMetadata>(context.Identity);
            }

            JsonMetadata metadata = new JsonMetadata(relation);

            metadata.MemberOf = metadata;
            metadata.Path     = "$";
            metadata.IsRoot   = true;

            context.AddMetadata <IJsonMetadata>(metadata);
        }
Пример #14
0
        public void Initialize(IMetadataBuilderContext context)
        {
            RelationMetadata model = new RelationMetadata(context.Identity)
            {
                Flags = RelationMetadataFlags.Model | RelationMetadataFlags.Readable,
                Type  = context.Schema.Model,
            };

            model.MemberOf   = model;
            model.Properties = this.CreateLazy(() => this.CreateProperties(context, model));

            model.Annotations = this.CreateAnnotations(model).ToList();
            model.Item        = this.CreateItem(context, model);

            if (model.Item != null)
            {
                model.Flags |= RelationMetadataFlags.List;
            }

            context.AddMetadata <IRelationMetadata>(model);
        }
Пример #15
0
        private BindingMetadata CreateBaseMetadata(IMetadataBuilderContext context, IRelationMetadata attribute, BindingMetadata parent)
        {
            BindingMetadata metadata = new BindingMetadata(attribute)
            {
                Parent   = parent,
                MemberOf = parent?.MemberOf
            };

            if (metadata.MemberOf == null || metadata.HasFlag(RelationMetadataFlags.Item))
            {
                metadata.MemberOf = metadata;
            }

            metadata.Properties = this.CreateLazyProperties(context, metadata);
            metadata.Item       = this.CreateItem(context, metadata);
            metadata.Flags      = this.GetFlags(metadata);

            context.AddMetadata <IBindingMetadata>(metadata);

            this.ApplyContracts(metadata);

            return(metadata);
        }
Пример #16
0
        public void Initialize(IMetadataBuilderContext context)
        {
            IReferenceMetadata metadata = this.CreateBaseMetadata(context, context.Relation, null);

            context.AddMetadata(metadata);
        }