private static IEdmFunction GetFunction(ODataPath odataPath)
        {
            ODataPathSegment         odataSegment    = odataPath.Segments.Last();
            IEdmFunction             function        = null;
            BoundFunctionPathSegment functionSegment = odataSegment as BoundFunctionPathSegment;

            if (functionSegment != null)
            {
                function = functionSegment.Function;
            }

            return(function);
        }
        public static void AddFunctionParameterToRouteData(this HttpControllerContext controllerContext, BoundFunctionPathSegment functionSegment)
        {
            Contract.Assert(controllerContext != null);
            Contract.Assert(functionSegment != null);

            IDictionary<string, object> routingConventionsStore = controllerContext.Request.ODataProperties().RoutingConventionsStore;

            foreach (KeyValuePair<string, string> nameAndValue in functionSegment.Values)
            {
                string name = nameAndValue.Key;
                object value = functionSegment.GetParameterValue(name);

                AddFunctionParameters(functionSegment.Function, name, value, controllerContext.RouteData.Values,
                    routingConventionsStore, null);
            }
        }
        public static void AddFunctionParameterToRouteData(this HttpControllerContext controllerContext, BoundFunctionPathSegment functionSegment)
        {
            Contract.Assert(controllerContext != null);
            Contract.Assert(functionSegment != null);

            foreach (KeyValuePair<string, string> nameAndValue in functionSegment.Values)
            {
                string name = nameAndValue.Key;
                object value = functionSegment.GetParameterValue(name);
                UnresolvedParameterValue unresolvedParameterValue = value as UnresolvedParameterValue;
                if (unresolvedParameterValue != null)
                {
                    value = unresolvedParameterValue.Resolve(controllerContext.Request.RequestUri);
                }
                controllerContext.RouteData.Values.Add(name, value);
            }
        }
        public static void AddFunctionParameterToRouteData(this HttpControllerContext controllerContext, BoundFunctionPathSegment functionSegment)
        {
            Contract.Assert(controllerContext != null);
            Contract.Assert(functionSegment != null);

            foreach (KeyValuePair<string, string> nameAndValue in functionSegment.Values)
            {
                string name = nameAndValue.Key;
                object value = functionSegment.GetParameterValue(name);

                ODataEnumValue enumValue = value as ODataEnumValue;
                if (enumValue != null)
                {
                    // Remove the type name of the ODataEnumValue and keep the value.
                    value = enumValue.Value;
                }

                controllerContext.RouteData.Values.Add(name, value);
            }
        }
예제 #5
0
        private static void AddFunctionParametersToRouteData(HttpControllerContext controllerContext,
                                                             BoundFunctionPathSegment functionSegment)
        {
            // skip the first binding parameter
            for (int i = 1; i < functionSegment.Function.Parameters.Count(); i++)
            {
                var    param = functionSegment.Function.Parameters.ElementAt(i);
                string name  = param.Name;

                object         value     = functionSegment.GetParameterValue(name);
                ODataEnumValue enumValue = value as ODataEnumValue;
                if (enumValue != null)
                {
                    // Remove the type name of the ODataEnumValue and keep the value.
                    value = enumValue.Value;
                }

                controllerContext.RouteData.Values.Add(name, value);

                Type   type     = typeof(ODataConventionModelBuilder).Assembly.GetTypes().First(c => c.Name == "ODataParameterValue");
                object instance = Activator.CreateInstance(type, value, param.Type);
                controllerContext.Request.ODataProperties().RoutingConventionsStore.Add("DF908045-6922-46A0-82F2-2F6E7F43D1B1_" + name, instance);
            }
        }
예제 #6
0
        public static void AddFunctionParameterToRouteData(this HttpControllerContext controllerContext, BoundFunctionPathSegment functionSegment)
        {
            Contract.Assert(controllerContext != null);
            Contract.Assert(functionSegment != null);

            foreach (KeyValuePair <string, string> nameAndValue in functionSegment.Values)
            {
                string name  = nameAndValue.Key;
                object value = functionSegment.GetParameterValue(name);
                UnresolvedParameterValue unresolvedParameterValue = value as UnresolvedParameterValue;
                if (unresolvedParameterValue != null)
                {
                    value = unresolvedParameterValue.Resolve(controllerContext.Request.RequestUri);
                }
                controllerContext.RouteData.Values.Add(name, value);
            }
        }
        public static void AddFunctionParameterToRouteData(this HttpControllerContext controllerContext, BoundFunctionPathSegment functionSegment)
        {
            Contract.Assert(controllerContext != null);
            Contract.Assert(functionSegment != null);

            IDictionary<string, object> routingConventionsStore = controllerContext.Request.ODataProperties().RoutingConventionsStore;

            foreach (KeyValuePair<string, string> nameAndValue in functionSegment.Values)
            {
                string name = nameAndValue.Key;
                object value = functionSegment.GetParameterValue(name);

                AddFunctionParameters(functionSegment.Function, name, value, controllerContext.RouteData.Values,
                    routingConventionsStore, null);
            }
        }
        /// <inheritdoc/>
        public override string SelectAction(ODataPath odataPath, HttpControllerContext controllerContext,
                                            ILookup <string, HttpActionDescriptor> actionMap)
        {
            if (odataPath == null)
            {
                throw Error.ArgumentNull("odataPath");
            }

            if (controllerContext == null)
            {
                throw Error.ArgumentNull("controllerContext");
            }

            if (actionMap == null)
            {
                throw Error.ArgumentNull("actionMap");
            }

            if (controllerContext.Request.Method == HttpMethod.Get)
            {
                string actionName = null;
                BoundFunctionPathSegment function = null;
                switch (odataPath.PathTemplate)
                {
                case "~/entityset/key/cast/function":
                case "~/entityset/key/function":
                    function   = odataPath.Segments.Last() as BoundFunctionPathSegment;
                    actionName = GetFunction(function).SelectAction(actionMap, isCollection: false);
                    if (actionName != null)
                    {
                        controllerContext.AddKeyValueToRouteData(odataPath);
                    }
                    break;

                case "~/entityset/key/cast/function/$count":
                case "~/entityset/key/function/$count":
                    function   = odataPath.Segments[odataPath.Segments.Count - 2] as BoundFunctionPathSegment;
                    actionName = GetFunction(function).SelectAction(actionMap, isCollection: false);
                    if (actionName != null)
                    {
                        controllerContext.AddKeyValueToRouteData(odataPath);
                    }
                    break;

                case "~/entityset/cast/function":
                case "~/entityset/function":
                    function   = odataPath.Segments.Last() as BoundFunctionPathSegment;
                    actionName = GetFunction(function).SelectAction(actionMap, isCollection: true);
                    break;

                case "~/entityset/cast/function/$count":
                case "~/entityset/function/$count":
                    function   = odataPath.Segments[odataPath.Segments.Count - 2] as BoundFunctionPathSegment;
                    actionName = GetFunction(function).SelectAction(actionMap, isCollection: true);
                    break;

                case "~/singleton/function":
                case "~/singleton/cast/function":
                    function   = odataPath.Segments.Last() as BoundFunctionPathSegment;
                    actionName = GetFunction(function).SelectAction(actionMap, isCollection: false);
                    break;

                case "~/singleton/function/$count":
                case "~/singleton/cast/function/$count":
                    function   = odataPath.Segments[odataPath.Segments.Count - 2] as BoundFunctionPathSegment;
                    actionName = GetFunction(function).SelectAction(actionMap, isCollection: false);
                    break;
                }

                if (actionName != null)
                {
                    controllerContext.AddFunctionParameterToRouteData(function);
                    return(actionName);
                }
            }

            return(null);
        }
        private static IEdmFunction GetFunction(BoundFunctionPathSegment function)
        {
            if (function != null)
            {
                return function.Function;
            }

            return null;
        }
예제 #10
0
        public static void AddFunctionParameterToRouteData(this HttpControllerContext controllerContext, BoundFunctionPathSegment functionSegment)
        {
            Contract.Assert(controllerContext != null);
            Contract.Assert(functionSegment != null);

            foreach (KeyValuePair <string, string> nameAndValue in functionSegment.Values)
            {
                string name  = nameAndValue.Key;
                object value = functionSegment.GetParameterValue(name);

                ODataEnumValue enumValue = value as ODataEnumValue;
                if (enumValue != null)
                {
                    // Remove the type name of the ODataEnumValue and keep the value.
                    value = enumValue.Value;
                }

                controllerContext.RouteData.Values.Add(name, value);
            }
        }