Ejemplo n.º 1
0
 internal FluentCommand(FluentCommand ancestor)
 {
     _schema = ancestor._schema;
     _parent = ancestor._parent;
     _collectionName = ancestor._collectionName;
     _collectionExpression = ancestor._collectionExpression;
     _derivedCollectionName = ancestor._derivedCollectionName;
     _derivedCollectionExpression = ancestor._derivedCollectionExpression;
     _functionName = ancestor._functionName;
     _keyValues = ancestor._keyValues;
     _namedKeyValues = ancestor._namedKeyValues;
     _entryData = ancestor._entryData;
     _parameters = ancestor._parameters;
     _filter = ancestor._filter;
     _filterExpression = ancestor._filterExpression;
     _filterExpression = ancestor._filterExpression;
     _skipCount = ancestor._skipCount;
     _topCount = ancestor._topCount;
     _expandAssociations = ancestor._expandAssociations;
     _selectColumns = ancestor._selectColumns;
     _orderbyColumns = ancestor._orderbyColumns;
     _computeCount = ancestor._computeCount;
     _inlineCount = ancestor._inlineCount;
     _linkName = ancestor._linkName;
     _linkExpression = ancestor._linkExpression;
 }
Ejemplo n.º 2
0
 private static List<ODataExpression> MergeArguments(IEnumerable<object> arguments, ODataExpression argument)
 {
     var collection = new List<ODataExpression>();
     collection.AddRange(arguments.Select(ODataExpression.FromValue));
     collection.Add(argument);
     return collection;
 }
 private static string FormatExpression(ODataExpression expr, ExpressionContext context)
 {
     if (ReferenceEquals(expr, null))
     {
         return "null";
     }
     else
     {
         return expr.Format(context);
     }
 }
        protected internal ODataExpression(ODataExpression expression)
        {
            _functionCaller = expression._functionCaller;
            _left = expression._left;
            _right = expression._right;
            _operator = expression._operator;
            _conversionType = expression._conversionType;

            this.Reference = expression.Reference;
            this.Value = expression.Value;
            this.Function = expression.Function;
        }
 internal string Format(ExpressionContext context)
 {
     if (_operator == ExpressionOperator.None && _conversionType == null)
     {
         return this.Reference != null ?
             FormatReference(context) : this.Function != null ?
             FormatFunction(context) :
             FormatValue(context);
     }
     else if (_conversionType != null)
     {
         var expr = _left;
         if (expr.Reference == null && expr.Function == null)
         {
             object result;
             if (Utils.TryConvert(expr.Value, _conversionType, out result))
             {
                 expr = new ODataExpression(result);
             }
         }
         return FormatExpression(expr, context);
     }
     else if (_operator == ExpressionOperator.NOT || _operator == ExpressionOperator.NEG)
     {
         var left = FormatExpression(_left, context);
         var op = FormatOperator(context);
         if (NeedsGrouping(_left))
             return string.Format("{0}({1})", op, left);
         else
             return string.Format("{0} {1}", op, left);
     }
     else
     {
         var left = FormatExpression(_left, context);
         var right = FormatExpression(_right, context);
         var op = FormatOperator(context);
         if (NeedsGrouping(_left))
             return string.Format("({0}) {1} {2}", left, op, right);
         else if (NeedsGrouping(_right))
             return string.Format("{0} {1} ({2})", left, op, right);
         else
             return string.Format("{0} {1} {2}", left, op, right);
     }
 }
Ejemplo n.º 6
0
 public void As(ODataExpression expression)
 {
     As(expression.ToString());
 }
Ejemplo n.º 7
0
 public void As(ODataExpression expression)
 {
     _derivedCollectionExpression = expression;
 }
        public FluentCommand Filter(ODataExpression expression)
        {
            if (IsBatchResponse) return this;

            if (ReferenceEquals(_details.FilterExpression, null))
                _details.FilterExpression = expression;
            else
                _details.FilterExpression = _details.FilterExpression && expression;
            return this;
        }
        public FluentCommand As(ODataExpression expression)
        {
            if (IsBatchResponse) return this;

            _details.DerivedCollectionExpression = expression;
            return this;
        }
 protected internal ODataExpression(ODataExpression caller, ExpressionFunction function)
 {
     _functionCaller = caller;
     this.Function = function;
 }
 protected internal ODataExpression(ODataExpression left, ODataExpression right, ExpressionOperator expressionOperator)
 {
     _left = left;
     _right = right;
     _operator = expressionOperator;
 }
 public FluentCommand Media(ODataExpression expression)
 {
     return Media(expression.Reference);
 }
        private bool NeedsGrouping(ODataExpression expr)
        {
            if (_operator == ExpressionOperator.None)
                return false;
            if (ReferenceEquals(expr, null))
                return false;
            if (expr._operator == ExpressionOperator.None)
                return false;

            int outerPrecedence = GetPrecedence(_operator);
            int innerPrecedence = GetPrecedence(expr._operator);
            return outerPrecedence < innerPrecedence;
        }
Ejemplo n.º 14
0
 public void For(ODataExpression expression)
 {
     For(expression.ToString());
 }
Ejemplo n.º 15
0
        private FluentCommand Resolve()
        {
            if (!ReferenceEquals(_collectionExpression, null))
            {
                For(_collectionExpression.AsString());
                _collectionExpression = null;
            }

            if (!ReferenceEquals(_derivedCollectionExpression, null))
            {
                As(_derivedCollectionExpression.AsString());
                _derivedCollectionExpression = null;
            }

            if (!ReferenceEquals(_filterExpression, null))
            {
                _namedKeyValues = TryInterpretFilterExpressionAsKey(_filterExpression);
                if (_namedKeyValues == null)
                {
                    _filter = _filterExpression.Format(_schema, this.Table);
                }
                else
                {
                    _topCount = -1;
                }
                _filterExpression = null;
            }

            if (!ReferenceEquals(_linkExpression, null))
            {
                Link(_linkExpression.AsString());
                _linkExpression = null;
            }

            return this;
        }
Ejemplo n.º 16
0
 public void Link(ODataExpression expression)
 {
     _linkExpression = expression;
 }
Ejemplo n.º 17
0
 public void Filter(ODataExpression expression)
 {
     _filterExpression = expression;
 }
Ejemplo n.º 18
0
 public void Filter(ODataExpression expression)
 {
     _namedKeyValues = TryInterpretFilterExpressionAsKey(expression);
     if (_namedKeyValues == null)
     {
         _filter = expression.Format(_schema, this.Table);
     }
     else
     {
         _topCount = -1;
     }
 }
Ejemplo n.º 19
0
 private IDictionary<string, object> TryInterpretFilterExpressionAsKey(ODataExpression expression)
 {
     bool ok = false;
     IDictionary<string, object> namedKeyValues = new Dictionary<string, object>();
     if (!ReferenceEquals(expression, null))
     {
         ok = expression.ExtractEqualityComparisons(namedKeyValues);
     }
     return ok &&
         this.Table.GetKeyNames().Count == namedKeyValues.Count() &&
         this.Table.GetKeyNames().All(namedKeyValues.ContainsKey) ? namedKeyValues : null;
 }
        private static ODataExpression ParseBinaryExpression(ODataExpression leftExpression, ODataExpression rightExpression, Expression operandExpression)
        {
            switch (operandExpression.NodeType)
            {
                case ExpressionType.Equal:
                    return leftExpression == rightExpression;
                case ExpressionType.NotEqual:
                    return leftExpression != rightExpression;
                case ExpressionType.LessThan:
                    return leftExpression < rightExpression;
                case ExpressionType.LessThanOrEqual:
                    return leftExpression <= rightExpression;
                case ExpressionType.GreaterThan:
                    return leftExpression > rightExpression;
                case ExpressionType.GreaterThanOrEqual:
                    return leftExpression >= rightExpression;
                case ExpressionType.And:
                case ExpressionType.AndAlso:
                    return leftExpression && rightExpression;
                case ExpressionType.Or:
                case ExpressionType.OrElse:
                    return leftExpression || rightExpression;
                case ExpressionType.Add:
                case ExpressionType.AddChecked:
                    return leftExpression + rightExpression;
                case ExpressionType.Subtract:
                case ExpressionType.SubtractChecked:
                    return leftExpression - rightExpression;
                case ExpressionType.Multiply:
                case ExpressionType.MultiplyChecked:
                    return leftExpression * rightExpression;
                case ExpressionType.Divide:
                    return leftExpression / rightExpression;
                case ExpressionType.Modulo:
                    return leftExpression % rightExpression;
            }

            throw Utils.NotSupportedExpression(operandExpression);
        }
 protected DynamicODataExpression(ODataExpression left, ODataExpression right, ExpressionType expressionOperator)
     : base(left, right, expressionOperator)
 {
 }
 protected internal ODataExpression(ODataExpression caller, string reference)
 {
     _functionCaller = caller;
     this.Reference = reference;
 }
 protected DynamicODataExpression(ODataExpression caller, string reference)
     : base(caller, reference)
 {
 }
 protected internal ODataExpression(ODataExpression expr, Type conversionType)
 {
     _left = expr;
     _conversionType = conversionType;
 }
 protected DynamicODataExpression(ODataExpression caller, ExpressionFunction function)
     : base(caller, function)
 {
 }
        public FluentCommand Link(ODataExpression expression)
        {
            if (IsBatchResponse) return this;

            _details.LinkExpression = expression;
            return this;
        }
        internal string Format(ExpressionContext context)
        {
            if (context.IsQueryOption && _operator != ExpressionOperator.None && 
                _operator != ExpressionOperator.AND && _operator != ExpressionOperator.EQ)
            {
                throw new InvalidOperationException("Invalid custom query option");
            }

            if (_operator == ExpressionOperator.None && _conversionType == null)
            {
                return this.Reference != null ?
                    FormatReference(context) : this.Function != null ?
                    FormatFunction(context) :
                    FormatValue(context);
            }
            else if (_conversionType != null)
            {
                var expr = _left;
                if (expr.Reference == null && expr.Function == null && expr._conversionType == null)
                {
                    object result;
                    if (expr.Value != null && expr.Value.GetType().IsEnumType())
                    {
                        expr = new ODataExpression(expr.Value);
                    }
                    else if (Utils.TryConvert(expr.Value, _conversionType, out result))
                    {
                        expr = new ODataExpression(result);
                    }
                }
                return FormatExpression(expr, context);
            }
            else if (_operator == ExpressionOperator.NOT || _operator == ExpressionOperator.NEG)
            {
                var left = FormatExpression(_left, context);
                var op = FormatOperator(context);
                if (NeedsGrouping(_left))
                    return string.Format("{0}({1})", op, left);
                else
                    return string.Format("{0} {1}", op, left);
            }
            else
            {
                var left = FormatExpression(_left, context);
                var right = FormatExpression(_right, context);
                var op = FormatOperator(context);

                if (context.IsQueryOption)
                {
                    return string.Format("{0}{1}{2}", left, op, right);
                }
                else
                {
                    if (NeedsGrouping(_left))
                        return string.Format("({0}) {1} {2}", left, op, right);
                    else if (NeedsGrouping(_right))
                        return string.Format("{0} {1} ({2})", left, op, right);
                    else
                        return string.Format("{0} {1} {2}", left, op, right);
                }
            }
        }
        private IDictionary<string, object> TryInterpretFilterExpressionAsKey(ODataExpression expression)
        {
            bool ok = false;
            IDictionary<string, object> namedKeyValues = new Dictionary<string, object>();
            if (!ReferenceEquals(expression, null))
            {
                ok = expression.ExtractLookupColumns(namedKeyValues);
            }
            if (!ok)
                return null;

            var keyNames = _details.Session.Metadata.GetDeclaredKeyPropertyNames(this.EntityCollection.Name).ToList();
            return keyNames.Count == namedKeyValues.Count() && keyNames.All(namedKeyValues.ContainsKey)
                ? namedKeyValues
                : null;
        }
Ejemplo n.º 29
0
 public void For(ODataExpression expression)
 {
     _collectionExpression = expression;
 }