Exemple #1
0
        /// <inheritdoc/>
        public override bool TryMatch(ODataPathSegment pathSegment, IDictionary <string, object> values)
        {
            OperationImportSegment other = pathSegment as OperationImportSegment;

            if (other == null)
            {
                return(false);
            }

            IEdmOperationImport operationImport = Segment.OperationImports.First();
            IEdmOperationImport otherImport     = other.OperationImports.First();

            // for unbound action, just compare the action import
            if (operationImport.IsActionImport() && otherImport.IsActionImport())
            {
                return(operationImport == otherImport);
            }
            else if (operationImport.IsFunctionImport() && otherImport.IsFunctionImport())
            {
                // but for unbound function, we should compare the parameter names and
                // process the parameter values into odata routes.
                if (operationImport.Name != otherImport.Name)
                {
                    return(false);
                }

                IDictionary <string, object> parameterValues = new Dictionary <string, object>();
                foreach (var parameter in other.Parameters)
                {
                    object value = other.GetParameterValue(parameter.Name);
                    parameterValues[parameter.Name] = value;
                }

                if (RoutingConventionHelpers.TryMatch(ParameterMappings, parameterValues, values))
                {
                    foreach (var operationSegmentParameter in other.Parameters)
                    {
                        string name  = operationSegmentParameter.Name;
                        object value = parameterValues[name];

                        RoutingConventionHelpers.AddFunctionParameters((IEdmFunction)otherImport.Operation, name,
                                                                       value, values, values, ParameterMappings);
                    }

                    return(true);
                }
            }

            return(false);
        }
        /// <inheritdoc/>
        public override bool TryMatch(ODataPathSegment pathSegment, IDictionary <string, object> values)
        {
            OperationSegment other = pathSegment as OperationSegment;

            if (other == null)
            {
                return(false);
            }

            IEdmOperation operation      = Segment.Operations.First();
            IEdmOperation otherOperation = other.Operations.First();

            if (operation.IsAction() && otherOperation.IsAction())
            {
                return(operation == otherOperation);
            }
            else if (operation.IsFunction() && otherOperation.IsFunction())
            {
                if (operation.FullName() != otherOperation.FullName())
                {
                    return(false);
                }

                IDictionary <string, object> parameterValues = new Dictionary <string, object>();
                foreach (var parameter in other.Parameters)
                {
                    object value = other.GetParameterValue(parameter.Name);
                    parameterValues[parameter.Name] = value;
                }

                if (RoutingConventionHelpers.TryMatch(ParameterMappings, parameterValues, values))
                {
                    foreach (var operationSegmentParameter in other.Parameters)
                    {
                        string name  = operationSegmentParameter.Name;
                        object value = parameterValues[name];

                        RoutingConventionHelpers.AddFunctionParameters((IEdmFunction)otherOperation, name,
                                                                       value, values, values, ParameterMappings);
                    }

                    return(true);
                }
            }

            return(false);
        }