Exemple #1
0
		private ServiceAction(string name, ResourceType returnType, ResourceSet resultSet, ResourceSetPathExpression resultSetPathExpression, IEnumerable<ServiceActionParameter> parameters, OperationParameterBindingKind operationParameterBindingKind) : base(name, Operation.GetResultKindFromReturnType(returnType, false), returnType, resultSet, resultSetPathExpression, "POST", parameters, operationParameterBindingKind, OperationKind.Action)
        {
            if (base.OperationParameters == OperationParameter.EmptyOperationParameterCollection)
            {
                this.parameters = ServiceActionParameter.EmptyServiceActionParameterCollection;
            }
            else
            {
                this.parameters = new ReadOnlyCollection<ServiceActionParameter>(base.OperationParameters.Cast<ServiceActionParameter>().ToList<ServiceActionParameter>());
            }
        }
        internal MetadataProviderEdmFunctionImport(MetadataProviderEdmModel model, MetadataProviderEdmEntityContainer container, OperationWrapper operation)
        {
            this.container = container;
            this.model     = model;
            this.operation = operation;
            if (operation.Kind == OperationKind.Action)
            {
                this.isSideEffecting = true;
                this.isComposable    = false;
                this.isBindable      = this.operation.BindingParameter != null;
            }
            else
            {
                this.isComposable    = false;
                this.isSideEffecting = true;
                this.isBindable      = false;
            }
            ResourceSetPathExpression resultSetPathExpression = operation.ResultSetPathExpression;

            this.entitySetPath = (resultSetPathExpression == null) ? null : resultSetPathExpression.PathExpression;
            if (operation.Kind == OperationKind.ServiceOperation)
            {
                model.SetHttpMethod(this, operation.Method);
            }
            string mimeType = operation.MimeType;

            if (!string.IsNullOrEmpty(mimeType))
            {
                model.SetMimeType(this, mimeType);
            }
            if (operation.OperationParameterBindingKind == OperationParameterBindingKind.Always)
            {
                model.SetIsAlwaysBindable(this, true);
            }
            ReadOnlyCollection <OperationParameter> parameters = operation.Parameters;

            if ((parameters != null) && (parameters.Count > 0))
            {
                List <IEdmFunctionParameter> list = new List <IEdmFunctionParameter>(parameters.Count);
                foreach (OperationParameter parameter in parameters)
                {
                    IEdmTypeReference typeReference = this.model.EnsureTypeReference(parameter.ParameterType, null);
                    if (!typeReference.IsNullable && (this.model.GetEdmVersion() < DataServiceProtocolVersion.V3.ToVersion()))
                    {
                        typeReference = typeReference.Clone(true);
                    }
                    EdmFunctionParameter item = new EdmFunctionParameter(this, parameter.Name, typeReference, EdmFunctionParameterMode.In);
                    list.Add(item);
                }
                this.parameters = new ReadOnlyCollection <IEdmFunctionParameter>(list);
            }
        }
Exemple #3
0
 internal Operation(string name, ServiceOperationResultKind resultKind, ResourceType returnType, System.Data.Services.Providers.ResourceSet resultSet, ResourceSetPathExpression resultSetPathExpression, string method, IEnumerable<OperationParameter> parameters, System.Data.Services.Providers.OperationParameterBindingKind operationParameterBindingKind, OperationKind kind)
 {
     WebUtil.CheckStringArgumentNullOrEmpty(name, "name");
     WebUtil.CheckServiceOperationResultKind(resultKind, "resultKind");
     WebUtil.CheckStringArgumentNullOrEmpty(method, "method");
     ValidateConstructorArguments(name, returnType, resultSet, resultSetPathExpression, method, operationParameterBindingKind, kind);
     this.name = name;
     this.resultKind = resultKind;
     this.returnType = returnType;
     this.resourceSet = resultSet;
     this.resultSetPathExpression = resultSetPathExpression;
     this.method = method;
     this.kind = kind;
     this.operationParameterBindingKind = operationParameterBindingKind;
     this.operationParameters = ValidateParameters(this.operationParameterBindingKind, parameters);
     if (this.operationParameterBindingKind != System.Data.Services.Providers.OperationParameterBindingKind.Never)
     {
         this.bindingParameter = this.operationParameters.FirstOrDefault<OperationParameter>();
         if (this.bindingParameter == null)
         {
             throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_BindableOperationMustHaveAtLeastOneParameter, "operationParameterBindingKind");
         }
         if (((resultSetPathExpression != null) && (this.bindingParameter.ParameterType.ResourceTypeKind != ResourceTypeKind.EntityType)) && (this.bindingParameter.ParameterType.ResourceTypeKind != ResourceTypeKind.EntityCollection))
         {
             throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_BindingParameterMustBeEntityToUsePathExpression("resultSetPathExpression"));
         }
         if (((this.kind == OperationKind.Action) && (this.bindingParameter.ParameterType.ResourceTypeKind != ResourceTypeKind.EntityType)) && (this.bindingParameter.ParameterType.ResourceTypeKind != ResourceTypeKind.EntityCollection))
         {
             throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_ActionBindingMustBeEntityOrEntityCollection, "parameters");
         }
         if (this.resultSetPathExpression != null)
         {
             this.resultSetPathExpression.SetBindingParameter(this.bindingParameter);
         }
     }
 }
Exemple #4
0
 internal Operation(string name, ServiceOperationResultKind resultKind, ResourceType returnType, System.Data.Services.Providers.ResourceSet resultSet, ResourceSetPathExpression resultSetPathExpression, string method, IEnumerable <OperationParameter> parameters, System.Data.Services.Providers.OperationParameterBindingKind operationParameterBindingKind, OperationKind kind)
 {
     WebUtil.CheckStringArgumentNullOrEmpty(name, "name");
     WebUtil.CheckServiceOperationResultKind(resultKind, "resultKind");
     WebUtil.CheckStringArgumentNullOrEmpty(method, "method");
     ValidateConstructorArguments(name, returnType, resultSet, resultSetPathExpression, method, operationParameterBindingKind, kind);
     this.name                          = name;
     this.resultKind                    = resultKind;
     this.returnType                    = returnType;
     this.resourceSet                   = resultSet;
     this.resultSetPathExpression       = resultSetPathExpression;
     this.method                        = method;
     this.kind                          = kind;
     this.operationParameterBindingKind = operationParameterBindingKind;
     this.operationParameters           = ValidateParameters(this.operationParameterBindingKind, parameters);
     if (this.operationParameterBindingKind != System.Data.Services.Providers.OperationParameterBindingKind.Never)
     {
         this.bindingParameter = this.operationParameters.FirstOrDefault <OperationParameter>();
         if (this.bindingParameter == null)
         {
             throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_BindableOperationMustHaveAtLeastOneParameter, "operationParameterBindingKind");
         }
         if (((resultSetPathExpression != null) && (this.bindingParameter.ParameterType.ResourceTypeKind != ResourceTypeKind.EntityType)) && (this.bindingParameter.ParameterType.ResourceTypeKind != ResourceTypeKind.EntityCollection))
         {
             throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_BindingParameterMustBeEntityToUsePathExpression("resultSetPathExpression"));
         }
         if (((this.kind == OperationKind.Action) && (this.bindingParameter.ParameterType.ResourceTypeKind != ResourceTypeKind.EntityType)) && (this.bindingParameter.ParameterType.ResourceTypeKind != ResourceTypeKind.EntityCollection))
         {
             throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_ActionBindingMustBeEntityOrEntityCollection, "parameters");
         }
         if (this.resultSetPathExpression != null)
         {
             this.resultSetPathExpression.SetBindingParameter(this.bindingParameter);
         }
     }
 }
Exemple #5
0
 private static void ValidateConstructorArguments(string operationName, ResourceType returnType, System.Data.Services.Providers.ResourceSet resultSet, ResourceSetPathExpression resultSetPathExpression, string method, System.Data.Services.Providers.OperationParameterBindingKind operationParameterBindingKind, OperationKind kind)
 {
     if ((returnType != null) && ((returnType.ResourceTypeKind == ResourceTypeKind.EntityType) || (returnType.ResourceTypeKind == ResourceTypeKind.EntityCollection)))
     {
         ResourceType subType = (returnType.ResourceTypeKind == ResourceTypeKind.EntityCollection) ? ((EntityCollectionResourceType) returnType).ItemType : returnType;
         if (((resultSet == null) && (resultSetPathExpression == null)) || ((resultSet != null) && !resultSet.ResourceType.IsAssignableFrom(subType)))
         {
             if (kind == OperationKind.ServiceOperation)
             {
                 throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_ResultTypeAndResultSetMustMatch("resultType", "resultSet"));
             }
             throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_ReturnTypeAndResultSetMustMatch("returnType", "resultSetPathExpression", "resultSet"));
         }
     }
     else if ((resultSet != null) || (resultSetPathExpression != null))
     {
         string str = (resultSet != null) ? "resultSet" : "resultSetPathExpression";
         if (kind == OperationKind.ServiceOperation)
         {
             throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_ResultSetMustBeNullForGivenResultType(str, "resultType"));
         }
         throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_ResultSetMustBeNullForGivenReturnType(str, "returnType"));
     }
     if ((returnType != null) && (returnType == ResourceType.GetPrimitiveResourceType(typeof(Stream))))
     {
         string str2;
         string str3;
         if (kind == OperationKind.ServiceOperation)
         {
             str2 = "resultType";
             str3 = System.Data.Services.Strings.ServiceOperation_InvalidResultType(returnType.FullName);
         }
         else
         {
             str2 = "returnType";
             str3 = System.Data.Services.Strings.ServiceOperation_InvalidReturnType(returnType.FullName);
         }
         throw new ArgumentException(str3, str2);
     }
     if ((string.CompareOrdinal("GET", method) != 0) && (string.CompareOrdinal("POST", method) != 0))
     {
         throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_NotSupportedProtocolMethod(method, operationName), "method");
     }
     if ((resultSetPathExpression != null) && (operationParameterBindingKind == System.Data.Services.Providers.OperationParameterBindingKind.Never))
     {
         throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_MustBeBindableToUsePathExpression("resultSetPathExpression"), "resultSetPathExpression");
     }
 }
Exemple #6
0
 private static void ValidateConstructorArguments(string operationName, ResourceType returnType, System.Data.Services.Providers.ResourceSet resultSet, ResourceSetPathExpression resultSetPathExpression, string method, System.Data.Services.Providers.OperationParameterBindingKind operationParameterBindingKind, OperationKind kind)
 {
     if ((returnType != null) && ((returnType.ResourceTypeKind == ResourceTypeKind.EntityType) || (returnType.ResourceTypeKind == ResourceTypeKind.EntityCollection)))
     {
         ResourceType subType = (returnType.ResourceTypeKind == ResourceTypeKind.EntityCollection) ? ((EntityCollectionResourceType)returnType).ItemType : returnType;
         if (((resultSet == null) && (resultSetPathExpression == null)) || ((resultSet != null) && !resultSet.ResourceType.IsAssignableFrom(subType)))
         {
             if (kind == OperationKind.ServiceOperation)
             {
                 throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_ResultTypeAndResultSetMustMatch("resultType", "resultSet"));
             }
             throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_ReturnTypeAndResultSetMustMatch("returnType", "resultSetPathExpression", "resultSet"));
         }
     }
     else if ((resultSet != null) || (resultSetPathExpression != null))
     {
         string str = (resultSet != null) ? "resultSet" : "resultSetPathExpression";
         if (kind == OperationKind.ServiceOperation)
         {
             throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_ResultSetMustBeNullForGivenResultType(str, "resultType"));
         }
         throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_ResultSetMustBeNullForGivenReturnType(str, "returnType"));
     }
     if ((returnType != null) && (returnType == ResourceType.GetPrimitiveResourceType(typeof(Stream))))
     {
         string str2;
         string str3;
         if (kind == OperationKind.ServiceOperation)
         {
             str2 = "resultType";
             str3 = System.Data.Services.Strings.ServiceOperation_InvalidResultType(returnType.FullName);
         }
         else
         {
             str2 = "returnType";
             str3 = System.Data.Services.Strings.ServiceOperation_InvalidReturnType(returnType.FullName);
         }
         throw new ArgumentException(str3, str2);
     }
     if ((string.CompareOrdinal("GET", method) != 0) && (string.CompareOrdinal("POST", method) != 0))
     {
         throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_NotSupportedProtocolMethod(method, operationName), "method");
     }
     if ((resultSetPathExpression != null) && (operationParameterBindingKind == System.Data.Services.Providers.OperationParameterBindingKind.Never))
     {
         throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_MustBeBindableToUsePathExpression("resultSetPathExpression"), "resultSetPathExpression");
     }
 }
Exemple #7
0
 public ServiceAction(string name, ResourceType returnType, OperationParameterBindingKind operationParameterBindingKind, IEnumerable<ServiceActionParameter> parameters, ResourceSetPathExpression resultSetPathExpression) : this(name, returnType, null, resultSetPathExpression, parameters, operationParameterBindingKind)
 {
 }
Exemple #8
0
 private ServiceAction(string name, ResourceType returnType, ResourceSet resultSet, ResourceSetPathExpression resultSetPathExpression, IEnumerable <ServiceActionParameter> parameters, OperationParameterBindingKind operationParameterBindingKind) : base(name, Operation.GetResultKindFromReturnType(returnType, false), returnType, resultSet, resultSetPathExpression, "POST", parameters, operationParameterBindingKind, OperationKind.Action)
 {
     if (base.OperationParameters == OperationParameter.EmptyOperationParameterCollection)
     {
         this.parameters = ServiceActionParameter.EmptyServiceActionParameterCollection;
     }
     else
     {
         this.parameters = new ReadOnlyCollection <ServiceActionParameter>(base.OperationParameters.Cast <ServiceActionParameter>().ToList <ServiceActionParameter>());
     }
 }
Exemple #9
0
 public ServiceAction(string name, ResourceType returnType, OperationParameterBindingKind operationParameterBindingKind, IEnumerable <ServiceActionParameter> parameters, ResourceSetPathExpression resultSetPathExpression) : this(name, returnType, null, resultSetPathExpression, parameters, operationParameterBindingKind)
 {
 }