コード例 #1
0
        /// <inheritdoc />
        public override bool TryMatch(ODataPathSegment pathSegment, IDictionary<string, object> values)
        {
            if (pathSegment.SegmentKind == ODataSegmentKinds.Function)
            {
                BoundFunctionPathSegment functionSegment = (BoundFunctionPathSegment)pathSegment;
                if (FunctionName == functionSegment.FunctionName)
                {
                    var enumNames = functionSegment.Function.Parameters.Where(p => p.Type.IsEnum()).Select(p => p.Name);
                    if (KeyValuePathSegmentTemplate.TryMatch(ParameterMappings, functionSegment.Values, values,
                        enumNames))
                    {
                        foreach (KeyValuePair<string, string> nameAndValue in functionSegment.Values)
                        {
                            string name = nameAndValue.Key;
                            object value = functionSegment.GetParameterValue(name);

                            //ProcedureRoutingConventionHelpers.AddFunctionParameters(functionSegment.Function, name,
                            //    value, values, values, ParameterMappings);
                            throw new NotImplementedException("ProcedureRoutingConventionHelpers.AddFunctionParameters");
                        }

                        return true;
                    }
                }
            }

            return false;
        }
コード例 #2
0
        /// <inheritdoc />
        public override bool TryMatch(ODataPathSegment pathSegment, IDictionary<string, object> values)
        {
            if (pathSegment.SegmentKind == ODataSegmentKinds.DynamicProperty)
            {
                var dynamicPropertyPathSegment = (DynamicPropertyPathSegment)pathSegment;

                // If we're treating the property name as a parameter store the provided name in our values collection
                // using the name from the template as the key.
                if (TreatPropertyNameAsParameterName)
                {
                    //values[PropertyName] = dynamicPropertyPathSegment.PropertyName;
                    //values[ODataParameterValue.ParameterValuePrefix + PropertyName] =
                    //    new ODataParameterValue(dynamicPropertyPathSegment.PropertyName,
                    //        EdmLibHelpers.GetEdmPrimitiveTypeReferenceOrNull(typeof(string)));
                    //return true;
                    throw new NotImplementedException("DynamicPropertyPathSegmentTemplate");
                }

                if (PropertyName == dynamicPropertyPathSegment.PropertyName)
                {
                    return true;
                }
            }

            return false;
        }
コード例 #3
0
        /// <inheritdoc />
        public override bool TryMatch(ODataPathSegment pathSegment, IDictionary<string, object> values)
        {
            if (pathSegment.SegmentKind == ODataSegmentKinds.Key)
            {
                KeyValuePathSegment keySegment = (KeyValuePathSegment)pathSegment;
                return TryMatch(ParameterMappings, keySegment.Values, values, null);
            }

            return false;
        }
コード例 #4
0
ファイル: CastPathSegment.cs プロジェクト: akrisiun/WebApi
        /// <inheritdoc/>
        public override bool TryMatch(ODataPathSegment pathSegment, IDictionary<string, object> values)
        {
            if (pathSegment.SegmentKind == ODataSegmentKinds.Cast)
            {
                CastPathSegment castSegment = (CastPathSegment)pathSegment;
                return castSegment.CastType == CastType
                    && castSegment.CastTypeName == CastTypeName;
            }

            return false;
        }
コード例 #5
0
        private void HandleNavigationPathSegment(ODataPathSegment segment)
        {
            var navigationSegment = (NavigationPathSegment)segment;
            var entityParameterExpression = Expression.Parameter(this.currentType);
            var navigationPropertyExpression =
                Expression.Property(entityParameterExpression, navigationSegment.NavigationPropertyName);

            this.currentEntityType = navigationSegment.NavigationProperty.ToEntityType();

            if (navigationSegment.NavigationProperty.TargetMultiplicity() == EdmMultiplicity.Many)
            {
                // get the element type of the target
                // (the type should be an EntityCollection<T> for navigation queries).
                this.currentType = navigationPropertyExpression.Type.GetEnumerableItemType();

                // need to explicitly define the delegate type as IEnumerable<T>
                Type delegateType = typeof(Func<,>).MakeGenericType(
                    queryable.ElementType,
                    typeof(IEnumerable<>).MakeGenericType(this.currentType));
                LambdaExpression selectBody =
                    Expression.Lambda(delegateType, navigationPropertyExpression, entityParameterExpression);

                this.queryable = ExpressionHelpers.SelectMany(this.queryable, selectBody, this.currentType);
            }
            else
            {
                this.currentType = navigationPropertyExpression.Type;
                LambdaExpression selectBody =
                    Expression.Lambda(navigationPropertyExpression, entityParameterExpression);
                this.queryable = ExpressionHelpers.Select(this.queryable, selectBody);
            }
        }
コード例 #6
0
        private void HandlePropertyAccessPathSegment(ODataPathSegment segment)
        {
            var propertySegment = (PropertyAccessPathSegment)segment;
            var entityParameterExpression = Expression.Parameter(this.currentType);
            var structuralPropertyExpression =
                Expression.Property(entityParameterExpression, propertySegment.PropertyName);

            if (propertySegment.Property.Type.IsCollection())
            {
                // Produces new query like 'queryable.SelectMany(param => param.PropertyName)'.
                // Suppose 'param.PropertyName' is of type 'IEnumerable<T>', the type of the
                // resulting query would be 'IEnumerable<T>' too.
                this.currentType = structuralPropertyExpression.Type.GetEnumerableItemType();
                var delegateType = typeof(Func<,>).MakeGenericType(
                    this.queryable.ElementType,
                    typeof(IEnumerable<>).MakeGenericType(this.currentType));
                var selectBody =
                    Expression.Lambda(delegateType, structuralPropertyExpression, entityParameterExpression);
                this.queryable = ExpressionHelpers.SelectMany(this.queryable, selectBody, this.currentType);
            }
            else
            {
                // Produces new query like 'queryable.Select(param => param.PropertyName)'.
                this.currentType = structuralPropertyExpression.Type;
                LambdaExpression selectBody =
                    Expression.Lambda(structuralPropertyExpression, entityParameterExpression);
                this.queryable = ExpressionHelpers.Select(this.queryable, selectBody);
            }
        }
コード例 #7
0
 private void HandleValuePathSegment(ODataPathSegment segment)
 {
     this.IsValuePathSegmentPresent = true;
 }
コード例 #8
0
        private void HandleKeyValuePathSegment(ODataPathSegment segment)
        {
            var keySegment = (KeyValuePathSegment)segment;

            var parameterExpression = Expression.Parameter(this.currentType, DefaultNameOfParameterExpression);
            var keyValues = GetPathKeyValues(keySegment, this.currentEntityType);

            BinaryExpression keyFilter = null;
            foreach (KeyValuePair<string, object> keyValuePair in keyValues)
            {
                var equalsExpression =
                    CreateEqualsExpression(parameterExpression, keyValuePair.Key, keyValuePair.Value);
                keyFilter = keyFilter == null ? equalsExpression : Expression.And(keyFilter, equalsExpression);
            }

            var whereExpression = Expression.Lambda(keyFilter, parameterExpression);
            this.queryable = ExpressionHelpers.Where(this.queryable, whereExpression, this.currentType);
        }
コード例 #9
0
ファイル: EntitySetPathSegment.cs プロジェクト: genusP/WebApi
        /// <inheritdoc/>
        public override bool TryMatch(ODataPathSegment pathSegment, IDictionary<string, object> values)
        {
            if (pathSegment.SegmentKind == ODataSegmentKinds.EntitySet)
            {
                EntitySetPathSegment entitySetSegment = (EntitySetPathSegment)pathSegment;
                return entitySetSegment.EntitySetBase == EntitySetBase && entitySetSegment.EntitySetName == EntitySetName;
            }

            return false;
        }
コード例 #10
0
 private void HandleCountPathSegment(ODataPathSegment segment)
 {
     this.IsCountPathSegmentPresent = true;
 }
コード例 #11
0
        /// <inheritdoc/>
        public override bool TryMatch(ODataPathSegment pathSegment, IDictionary<string, object> values)
        {
            if (pathSegment.SegmentKind == ODataSegmentKinds.Navigation)
            {
                NavigationPathSegment navigationSegment = (NavigationPathSegment)pathSegment;
                return navigationSegment.NavigationProperty == NavigationProperty
                    && navigationSegment.NavigationPropertyName == NavigationPropertyName;
            }

            return false;
        }
コード例 #12
0
 /// <inheritdoc/>
 public override bool TryMatch(ODataPathSegment pathSegment, IDictionary<string, object> values)
 {
     return
         pathSegment.SegmentKind == ODataSegmentKinds.DynamicProperty &&
         ((DynamicPropertyPathSegment)pathSegment).PropertyName == PropertyName;
 }
コード例 #13
0
        /// <inheritdoc/>
        public override bool TryMatch(ODataPathSegment pathSegment, IDictionary<string, object> values)
        {
            if (pathSegment.SegmentKind == ODataSegmentKinds.Action)
            {
                BoundActionPathSegment actionSegment = (BoundActionPathSegment)pathSegment;
                return actionSegment.Action == Action && actionSegment.ActionName == ActionName;
            }

            return false;
        }
コード例 #14
0
        /// <inheritdoc />
        public override bool TryMatch(ODataPathSegment pathSegment, IDictionary<string, object> values)
        {
            if (pathSegment.SegmentKind == ODataSegmentKinds.UnboundFunction)
            {
                UnboundFunctionPathSegment functionSegment = (UnboundFunctionPathSegment)pathSegment;
                return functionSegment.Function == Function && functionSegment.FunctionName == FunctionName;
            }

            return false;
        }
コード例 #15
0
 /// <inheritdoc/>
 public override bool TryMatch(ODataPathSegment pathSegment, IDictionary<string, object> values)
 {
     return false;
 }
コード例 #16
0
ファイル: BatchPathSegment.cs プロジェクト: tvdburgt/WebApi
 /// <inheritdoc/>
 public override bool TryMatch(ODataPathSegment pathSegment, IDictionary <string, object> values)
 {
     return(pathSegment.SegmentKind == ODataSegmentKinds.Batch);
 }
コード例 #17
0
 /// <inheritdoc/>
 public override bool TryMatch(ODataPathSegment pathSegment, IDictionary <string, object> values)
 {
     return(false);
 }
コード例 #18
0
        /// <inheritdoc/>
        public override bool TryMatch(ODataPathSegment pathSegment, IDictionary<string, object> values)
        {
            if (pathSegment.SegmentKind == ODataSegmentKinds.Property)
            {
                PropertyAccessPathSegment propertySegment = (PropertyAccessPathSegment)pathSegment;
                return propertySegment.Property == Property && propertySegment.PropertyName == PropertyName;
            }

            return false;
        }
コード例 #19
0
        private void HandleUnboundFunctionPathSegment(ODataPathSegment segment)
        {
            var unboundFunctionPathSegment = (UnboundFunctionPathSegment)segment;
            var functionImport = unboundFunctionPathSegment.Function;
            var entityTypeRef = functionImport.Function.ReturnType.AsEntity();
            this.currentEntityType = entityTypeRef == null ? null : entityTypeRef.EntityDefinition();

            object[] queryArgs = null;
            if (functionImport.Function.Parameters.Any())
            {
                queryArgs = functionImport.Function.Parameters.Select(
                    p => unboundFunctionPathSegment.GetParameterValue(p.Name)).ToArray();
            }

            this.queryable = this.api.Source(functionImport.Name, queryArgs);
            this.currentType = queryable.ElementType;
        }
コード例 #20
0
 private void HandleEntitySetPathSegment(ODataPathSegment segment)
 {
     var entitySetPathSegment = (EntitySetPathSegment)segment;
     var entitySet = entitySetPathSegment.EntitySetBase;
     this.currentEntityType = entitySet.EntityType();
     this.queryable = this.api.Source(entitySet.Name, (object[])null);
     this.currentType = this.queryable.ElementType;
 }
コード例 #21
0
        /// <inheritdoc/>
        public override bool TryMatch(ODataPathSegment pathSegment, IDictionary<string, object> values)
        {
            if (pathSegment.SegmentKind == ODataSegmentKinds.Singleton)
            {
                SingletonPathSegment singletonSegment = (SingletonPathSegment)pathSegment;
                return singletonSegment.Singleton == Singleton && singletonSegment.SingletonName == SingletonName;
            }

            return false;
        }
コード例 #22
0
ファイル: BatchPathSegment.cs プロジェクト: genusP/WebApi
 /// <inheritdoc/>
 public override bool TryMatch(ODataPathSegment pathSegment, IDictionary<string, object> values)
 {
     return pathSegment.SegmentKind == ODataSegmentKinds.Batch;
 }
コード例 #23
0
 private void HandleSingletonPathSegment(ODataPathSegment segment)
 {
     var singletonPathSegment = (SingletonPathSegment)segment;
     var singleton = singletonPathSegment.Singleton;
     this.currentEntityType = singleton.EntityType();
     this.queryable = this.api.Source(singleton.Name, (object[])null);
     this.currentType = this.queryable.ElementType;
 }