Ejemplo n.º 1
0
        private void ProcessItem(BucketImpl item)
        {
            if (!item.Processed)
            {
                try
                {
                    ExecuteQuery(item, context.Collection);
                }
                catch (Exception ex)
                {
                    throw new ProviderException(Messages.ErrorWhileExecutingTheQuery, ex);
                }

                item.Processed = true;
            }
        }
Ejemplo n.º 2
0
        private void ExtractDataFromExpression(BucketImpl bucket, Expression left, Expression right)
        {
            object value = Expression.Lambda(right).Compile().DynamicInvoke();

            MemberExpression memberExpression   = (MemberExpression)left;
            string           originalMembername = memberExpression.Member.Name;

            PropertyInfo targetProperty = null;

            // for nested types.
            if (memberExpression.Member.DeclaringType != typeof(T) &&
                memberExpression.Member.DeclaringType != typeof(T).BaseType &&
                !memberExpression.Member.DeclaringType.IsInterface &&
                !memberExpression.Member.DeclaringType.IsAbstract)
            {
                Type targetType = memberExpression.Member.DeclaringType;

                while (true)
                {
                    if (targetType.DeclaringType == null || targetType.DeclaringType == typeof(T))
                    {
                        break;
                    }
                    targetType = targetType.DeclaringType;
                }

                PropertyInfo[] infos = typeof(T).GetProperties();

                targetProperty = FindTargetPropertyWhereUsed(infos, targetType);

                object nestedObj = Activator.CreateInstance(targetType);

                if (targetProperty.CanWrite)
                {
                    var property = nestedObj.GetType().GetProperty(memberExpression.Member.Name);

                    if (property == null)
                    {
                        // go deep find n.
                        object nestedChildObject = FindDeepObject(nestedObj, targetType, memberExpression.Member.Name);

                        nestedChildObject.GetType()
                        .GetProperty(memberExpression.Member.Name)
                        .SetValue(nestedChildObject, value, null);
                    }
                    else
                    {
                        property.SetValue(nestedObj, value, null);
                    }

                    // reset the value.
                    value = nestedObj;
                }
            }
            else
            {
                targetProperty = typeof(T).GetProperty(originalMembername);
            }

            object[] attr = targetProperty.GetCustomAttributes(typeof(IgnoreAttribute), true);

            if (attr.Length == 0)
            {
                if (targetProperty.CanRead)
                {
                    bucket.IsDirty = true;
                    FillBucket(bucket, targetProperty, value, memberExpression);
                }
            }
        }
Ejemplo n.º 3
0
        private void FillBucket(BucketImpl bucket, PropertyInfo info, object value, MemberExpression memberExpression)
        {
            bucket.ClauseItemCount = bucket.ClauseItemCount + 1;

            var expression = memberExpression.Expression;

            Buckets.Current.SyntaxStack.Pop();

            string[] parts = expression.ToString().Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);

            Bucket current = bucket;
            bool   nested  = false;

            for (int index = 1; index < parts.Length; index++)
            {
                Type propertyType = current.Items[parts[index]].PropertyType;

                if (!propertyType.IsPrimitive &&
                    propertyType.FullName.IndexOf("System") == -1 &&
                    !propertyType.IsEnum)
                {
                    if (current.Items[parts[index]].Child == null)
                    {
                        current.Items[parts[index]].Child           = BucketImpl.NewInstance(propertyType).Init();
                        current.Items[parts[index]].Child.Container = current.Items[parts[index]];
                    }
                    // move on.
                    current = current.Items[parts[index]].Child;
                    nested  = true;
                }
            }

            BucketItem item = null;

            if (current != null && nested)
            {
                foreach (PropertyInfo property in info.PropertyType.GetProperties())
                {
                    object targetValue = property.GetValue(value, null);

                    if (targetValue != null && !targetValue.EqualsDefault(property.Name, value))
                    {
                        current.Items[property.Name].Values.Add(new BucketItem.QueryCondition(targetValue, bucket.Relation));
                    }
                }
            }

            item = parts.Length > 1 ? bucket.Items[parts[1]] : bucket.Items[info.Name];

            BucketItem leafItem;

            if (item.Child != null)
            {
                BucketItem i = item.GetActiveItem();

                leafItem = new BucketItem
                {
                    DeclaringType = i.DeclaringType,
                    Name          = i.Name,
                    ProperyName   = i.ProperyName,
                    PropertyType  = info.PropertyType,
                    Unique        = i.Unique,
                    Child         = i.Child,
                    Container     = i.Container
                };

                leafItem.Values.Add(new BucketItem.QueryCondition(i.Value, bucket.Relation));
            }
            else
            {
                // for getting the values directly.
                // add it to the bucket condition list.
                item.Values.Add(new BucketItem.QueryCondition(value, bucket.Relation));

                leafItem = new BucketItem
                {
                    DeclaringType = item.DeclaringType,
                    Name          = item.Name,
                    ProperyName   = item.ProperyName,
                    PropertyType  = info.PropertyType,
                    MemberInfo    = memberExpression.Member,
                    Unique        = item.Unique,
                    Container     = item.Container
                };

                leafItem.Values.Add(new BucketItem.QueryCondition(value, bucket.Relation));
            }
            bucket.CurrentTreeNode.Nodes.Add(new TreeNode.Node()
            {
                Value = leafItem
            });
        }