Exemplo n.º 1
0
        public int GetListIndex(IBindingMetadata metadata)
        {
            if (metadata.HasFlag(BindingMetadataFlags.Model))
            {
                return(ResultIndex);
            }
            else if (metadata.HasFlag(BindingMetadataFlags.Item) && metadata.Parent.HasFlag(BindingMetadataFlags.Model))
            {
                return(ResultIndex);
            }

            return(this.GetListIndex(new BufferCacheKey(metadata.Identity)));
        }
Exemplo n.º 2
0
        public AggregateNode Build()
        {
            IBindingMetadata metadata = this.Schema.GetMetadata <IBindingMetadata>();

            AggregateNode aggrNode = new AggregateNode()
            {
                Metadata = metadata,
                Index    = this.State.Indexer.GetListIndex(metadata.Item.Identity),
            };

            if (this.State.Aggregate.Targets.Count > 0)
            {
                aggrNode.Item = new MetadataNode(metadata.Item);
            }

            foreach (MetadataIdentity identity in this.State.Aggregate.Targets)
            {
                IBindingMetadata targetMetadata = identity.GetMetadata <IBindingMetadata>();
                IBindingMetadata valueMetadata  = targetMetadata.HasFlag(BindingMetadataFlags.Item) ? targetMetadata.Parent : targetMetadata;

                MetadataNode valueNode = new MetadataNode(valueMetadata)
                {
                    ListIndex = this.State.Indexer.GetListIndex(identity),
                };

                this.AddListNode(aggrNode, valueNode);
            }

            return(aggrNode);
        }
Exemplo n.º 3
0
        private static void AddDataNode(NodeTree tree, DataAttribute attribute)
        {
            MetadataIdentity identity = new MetadataIdentity(tree.Schema, attribute.Name);
            IBindingMetadata metadata = identity.Lookup <IBindingMetadata>() ?? FindDynamicMetadata(identity);

            if (metadata != null)
            {
                Node node;

                if (metadata.HasFlag(BindingMetadataFlags.Dynamic))
                {
                    node = AddDynamicNode(tree, identity, metadata);
                }
                else
                {
                    node = AddStaticNode(tree, metadata);
                }

                if (node != null)
                {
                    node.Data = attribute;

                    tree.Data.Add(node);
                }
            }
        }
Exemplo n.º 4
0
        private bool IsWriterList(IBindingMetadata metadata)
        {
            if (this.QueryType == QueryType.Aggregate)
            {
                if (metadata.HasFlag(BindingMetadataFlags.Model))
                {
                    return(false);
                }
                else if (metadata.HasFlag(BindingMetadataFlags.Item) && metadata.Parent.HasFlag(BindingMetadataFlags.Model))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 5
0
        private static Node AddStaticNode(NodeTree tree, IBindingMetadata metadata)
        {
            Node thisNode = tree.FindNode(metadata);

            if (thisNode != null)
            {
                return(thisNode);
            }
            else if (metadata.HasFlag(BindingMetadataFlags.Item) || HasValidReference(metadata))
            {
                thisNode = new Node(metadata)
                {
                    IsDynamic = metadata.HasFlag(BindingMetadataFlags.Dynamic),
                };

                tree.Nodes.Add(thisNode);
                tree.Items.Add(thisNode);
            }
            else if (metadata.HasFlag(BindingMetadataFlags.Model))
            {
                thisNode = new Node(metadata)
                {
                    IsDynamic = metadata.HasFlag(BindingMetadataFlags.Dynamic),
                };

                tree.Nodes.Add(thisNode);
                tree.Items.Add(thisNode);
            }
            else
            {
                Node parentNode = tree.FindNode(metadata.Parent) ?? AddStaticNode(tree, metadata.Parent);

                if (parentNode != null)
                {
                    thisNode = new Node(metadata)
                    {
                        IsDynamic = metadata.HasFlag(BindingMetadataFlags.Dynamic),
                    };

                    parentNode.Properties.Add(thisNode);
                    tree.Nodes.Add(thisNode);
                }
            }

            return(thisNode);
        }
Exemplo n.º 6
0
        private bool RequiresReference(IBindingMetadata metadata)
        {
            if (metadata.HasFlag(BindingMetadataFlags.Model))
            {
                return(false);
            }
            else if (metadata.HasFlag(BindingMetadataFlags.Item) && metadata.Parent.HasFlag(BindingMetadataFlags.Model))
            {
                return(false);
            }
            else if (this.IsAggregateList(metadata))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 7
0
        private MetadataNode AddStaticNode(List <MetadataNode> itemNodes, IBindingMetadata metadata, ColumnIdentity value)
        {
            MetadataNode thisNode = this.FindNode(itemNodes, metadata);

            if (thisNode != null)
            {
                thisNode.Column ??= value;
            }
            else if (metadata.HasFlag(BindingMetadataFlags.Item))
            {
                MetadataNode itemNode = new MetadataNode(metadata)
                {
                    Metadata = metadata,
                    Column   = value,
                    Flags    = metadata.HasFlag(BindingMetadataFlags.Dynamic) ? NodeFlags.Dynamic : NodeFlags.None,
                };

                if (metadata.Parent.HasFlag(BindingMetadataFlags.Model))
                {
                    itemNode.Flags |= NodeFlags.Result;
                }

                itemNodes.Add(itemNode);

                return(itemNode);
            }
            else
            {
                MetadataNode parentNode = this.FindNode(itemNodes, metadata.Parent) ?? this.AddStaticNode(itemNodes, metadata.Parent, null);

                if (parentNode != null)
                {
                    thisNode = new MetadataNode(metadata)
                    {
                        Metadata = metadata,
                        Column   = value,
                        Flags    = metadata.HasFlag(BindingMetadataFlags.Dynamic) ? NodeFlags.Dynamic : NodeFlags.None,
                    };

                    parentNode.Properties.Add(thisNode);
                }
            }

            return(thisNode);
        }
        private MethodInfo GetAddDynamicMethod(IBindingMetadata metadata)
        {
            if (metadata.HasFlag(BindingMetadataFlags.Dynamic))
            {
                Type dictionaryType = typeof(IDictionary <string, object>);

                return(dictionaryType.GetMethod("Add", new[] { typeof(string), typeof(object) }));
            }

            return(null);
        }
Exemplo n.º 9
0
 internal static BindingException NoReferenceFound(IBindingMetadata metadata)
 {
     if (metadata.HasFlag(BindingMetadataFlags.Item))
     {
         return(NoReferenceFound(metadata.Identity, metadata.Parent.Parent.Identity));
     }
     else
     {
         return(NoReferenceFound(metadata.Identity, metadata.Parent.Identity));
     }
 }
Exemplo n.º 10
0
        private IBindingMetadata FindDynamicMetadata(MetadataIdentity identity)
        {
            IBindingMetadata metadata = identity.GetMetadata <IBindingMetadata>();

            while (metadata == null && (identity = identity.Pop()) != null)
            {
                metadata = identity.GetMetadata <IBindingMetadata>();
            }

            if (metadata != null && metadata.HasFlag(BindingMetadataFlags.Dynamic))
            {
                return(metadata);
            }

            return(null);
        }
Exemplo n.º 11
0
        private void AddValueNode(List <MetadataNode> itemNodes, ColumnIdentity value)
        {
            MetadataIdentity identity = new MetadataIdentity(this.schema, value.Name);
            IBindingMetadata metadata = identity.GetMetadata <IBindingMetadata>() ?? this.FindDynamicMetadata(identity);

            if (metadata != null && !this.IsOutsideResultScope(metadata))
            {
                if (metadata.HasFlag(BindingMetadataFlags.Dynamic))
                {
                    this.AddDynamicNode(itemNodes, identity, metadata, value);
                }
                else
                {
                    this.AddStaticNode(itemNodes, metadata, value);
                }
            }
        }
Exemplo n.º 12
0
        private ParameterExpression GetListVariable(IBindingMetadata metadata, KeyReader joinKey)
        {
            if (joinKey != null)
            {
                Type dictType = typeof(Dictionary <,>).MakeGenericType(joinKey.KeyType, typeof(ElasticArray));

                return(this.GetNamedVariable(dictType, metadata.Identity));
            }
            else if (metadata.HasFlag(BindingMetadataFlags.Item))
            {
                Type listType = metadata.Parent.Composition?.Construct?.Type ?? throw BindingException.InvalidConstructor(metadata.Parent);

                return(this.GetNamedVariable(listType, metadata.Identity));
            }

            return(null);
        }
        private NewExpression GetDefaultConstructor(IBindingMetadata metadata)
        {
            if (metadata.HasFlag(BindingMetadataFlags.Dynamic))
            {
                return(Expression.New(typeof(ExpandoObject)));
            }

            if (metadata.Type.IsValueType)
            {
                return(Expression.New(metadata.Type));
            }

            ConstructorInfo constructorInfo = metadata.Type.GetConstructor(Type.EmptyTypes);

            if (constructorInfo != null)
            {
                return(Expression.New(constructorInfo));
            }

            return(null);
        }
Exemplo n.º 14
0
        private ListTarget GetListTarget(ListResult result, IBindingMetadata metadata, KeyReader joinKey)
        {
            int bufferIndex = this.Buffer.GetListIndex(metadata, joinKey?.Reference);

            metadata = joinKey?.Target ?? metadata;

            ListTarget target = result.Targets.FirstOrDefault(t => t.Index == bufferIndex);

            if (target != null)
            {
                return(target);
            }

            target = new ListTarget()
            {
                Index    = bufferIndex,
                Variable = this.GetListVariable(metadata, joinKey),
            };

            if (joinKey == null && metadata.HasFlag(BindingMetadataFlags.Item))
            {
                target.NewList   = target.NewTarget = metadata.Parent.Composition?.Construct ?? throw BindingException.InvalidConstructor(metadata.Parent);
                target.AddMethod = metadata.Parent.Composition.Add;
            }

            if (joinKey != null)
            {
                target.NewTarget = Expression.New(target.Variable.Type);
            }

            if (target.NewTarget != null)
            {
                result.Targets.Add(target);
            }

            return(target);
        }