Example #1
0
 private static ResourceType GetReturnTypeFromResultType(ResourceType resultType, ServiceOperationResultKind resultKind)
 {
     if (((resultKind == ServiceOperationResultKind.Void) && (resultType != null)) || ((resultKind != ServiceOperationResultKind.Void) && (resultType == null)))
     {
         throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_ResultTypeAndKindMustMatch("resultKind", "resultType", ServiceOperationResultKind.Void));
     }
     if ((resultType != null) && (resultType.ResourceTypeKind == ResourceTypeKind.Collection))
     {
         throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_InvalidResultType(resultType.FullName));
     }
     if ((resultType != null) && (resultType.ResourceTypeKind == ResourceTypeKind.EntityCollection))
     {
         throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_InvalidResultType(resultType.FullName));
     }
     if (resultType == null)
     {
         return null;
     }
     if (((resultType.ResourceTypeKind == ResourceTypeKind.Primitive) || (resultType.ResourceTypeKind == ResourceTypeKind.ComplexType)) && ((resultKind == ServiceOperationResultKind.Enumeration) || (resultKind == ServiceOperationResultKind.QueryWithMultipleResults)))
     {
         return ResourceType.GetCollectionResourceType(resultType);
     }
     if ((resultType.ResourceTypeKind == ResourceTypeKind.EntityType) && ((resultKind == ServiceOperationResultKind.Enumeration) || (resultKind == ServiceOperationResultKind.QueryWithMultipleResults)))
     {
         return ResourceType.GetEntityCollectionResourceType(resultType);
     }
     return resultType;
 }
Example #2
0
 internal static void CheckServiceOperationResultKind(ServiceOperationResultKind kind, string parameterName)
 {
     if ((kind < ServiceOperationResultKind.DirectValue) || (kind > ServiceOperationResultKind.Void))
     {
         throw new ArgumentException(System.Data.Services.Strings.InvalidEnumValue(kind.GetType().Name), parameterName);
     }
 }
Example #3
0
        /// <summary>
        /// Initializes a new <see cref="ServiceOperation"/> instance.
        /// </summary>
        /// <param name="name">name of the service operation.</param>
        /// <param name="resultKind">Kind of result expected from this operation.</param>
        /// <param name="resultType">Type of element of the method result.</param>
        /// <param name="resultSet">EntitySet of the result expected from this operation.</param>
        /// <param name="method">Protocol (for example HTTP) method the service operation responds to.</param>
        /// <param name="parameters">In-order parameters for this operation.</param>
        public ServiceOperation(
            string name,
            ServiceOperationResultKind resultKind,
            ResourceType resultType,
            ResourceSet resultSet,
            string method,
            IEnumerable <ServiceOperationParameter> parameters)
        {
            ExceptionUtils.CheckArgumentStringNotNullOrEmpty(name, "name");
            CheckServiceOperationResultKind(resultKind, "resultKind");
            ExceptionUtils.CheckArgumentStringNotNullOrEmpty(method, "method");

            if ((resultKind == ServiceOperationResultKind.Void && resultType != null) ||
                (resultKind != ServiceOperationResultKind.Void && resultType == null))
            {
                throw new ArgumentException(Strings.ServiceOperation_ResultTypeAndKindMustMatch("resultKind", "resultType", ServiceOperationResultKind.Void));
            }

            if ((resultType == null || resultType.ResourceTypeKind != ResourceTypeKind.EntityType) && resultSet != null)
            {
                throw new ArgumentException(Strings.ServiceOperation_ResultSetMustBeNull("resultSet", "resultType"));
            }

            if (resultType != null && resultType.ResourceTypeKind == ResourceTypeKind.EntityType && (resultSet == null || !resultSet.ResourceType.IsAssignableFrom(resultType)))
            {
                throw new ArgumentException(Strings.ServiceOperation_ResultTypeAndResultSetMustMatch("resultType", "resultSet"));
            }

            if (resultType != null && resultType.ResourceTypeKind == ResourceTypeKind.MultiValue)
            {
                throw new ArgumentException(Strings.ServiceOperation_InvalidResultType(resultType.FullName));
            }

            if (method != HttpConstants.HttpMethodGet && method != HttpConstants.HttpMethodPost)
            {
                throw new ArgumentException(Strings.ServiceOperation_NotSupportedProtocolMethod(method, name));
            }

            this.name        = name;
            this.resultKind  = resultKind;
            this.resultType  = resultType;
            this.resourceSet = resultSet;
            this.method      = method;
            if (parameters == null)
            {
                this.parameters = ServiceOperation.emptyParameterCollection;
            }
            else
            {
                this.parameters = new ReadOnlyCollection <ServiceOperationParameter>(new List <ServiceOperationParameter>(parameters));
                HashSet <string> paramNames = new HashSet <string>(StringComparer.Ordinal);
                foreach (ServiceOperationParameter p in this.parameters)
                {
                    if (!paramNames.Add(p.Name))
                    {
                        throw new ArgumentException(Strings.ServiceOperation_DuplicateParameterName(p.Name), "parameters");
                    }
                }
            }
        }
Example #4
0
        /// <summary>
        /// Initializes a new <see cref="ServiceOperation"/> instance.
        /// </summary>
        /// <param name="name">name of the service operation.</param>
        /// <param name="resultKind">Kind of result expected from this operation.</param>
        /// <param name="resultType">Type of element of the method result.</param>
        /// <param name="resultSet">EntitySet of the result expected from this operation.</param>
        /// <param name="method">Protocol (for example HTTP) method the service operation responds to.</param>
        /// <param name="parameters">In-order parameters for this operation.</param>
        public ServiceOperation  AddServiceOperation(string name, ServiceOperationResultKind resultKind, ResourceType resultType, ResourceSet resultSet, string method, IEnumerable <ServiceOperationParameter> parameters)
        {
            ServiceOperation so = new ServiceOperation(name, resultKind, resultType, resultSet, method, parameters);

            this.serviceOperationsByName.Add(name, so);
            return(so);
        }
Example #5
0
        public void AddServiceOperation(string name, string serviceOperationResultKind, string typeName)
        {
            NonClrContext context = (NonClrContext)this.CurrentDataSource;

            ServiceOperationResultKind operationResult = context.ConvertServiceOperationResultKind(serviceOperationResultKind);

            context.AddServiceOperation(name, operationResult, typeName, "GET");
        }
Example #6
0
 /// <summary>
 /// Check whether the given value for ServiceOperationResultKind is valid. If not, throw argument exception.
 /// </summary>
 /// <param name="kind">value for ServiceOperationResultKind</param>
 /// <param name="parameterName">name of the parameter</param>
 /// <exception cref="ArgumentException">if the value is not valid.</exception>
 private static void CheckServiceOperationResultKind(ServiceOperationResultKind kind, string parameterName)
 {
     if (kind < ServiceOperationResultKind.DirectValue ||
         kind > ServiceOperationResultKind.Void)
     {
         throw new ArgumentException(Strings.General_InvalidEnumValue(kind.GetType().Name), parameterName);
     }
 }
        /// <summary>
        /// Initializes a new <see cref="ServiceOperation"/> instance.
        /// </summary>
        /// <param name="name">name of the service operation.</param>
        /// <param name="resultKind">Kind of result expected from this operation.</param>
        /// <param name="resultType">Type of element of the method result.</param>
        /// <param name="resultSet">EntitySet of the result expected from this operation.</param>
        /// <param name="method">Protocol (for example HTTP) method the service operation responds to.</param>
        /// <param name="parameters">In-order parameters for this operation.</param>
        public ServiceOperation(
            string name,
            ServiceOperationResultKind resultKind,
            ResourceType resultType,
            ResourceSet resultSet,
            string method,
            IEnumerable<ServiceOperationParameter> parameters)
        {
            WebUtil.CheckStringArgumentNull(name, "name");
            WebUtil.CheckServiceOperationResultKind(resultKind, "resultKind");
            WebUtil.CheckStringArgumentNull(method, "method");

            if ((resultKind == ServiceOperationResultKind.Void && resultType != null) ||
                (resultKind != ServiceOperationResultKind.Void && resultType == null))
            {
                throw new ArgumentException(Strings.ServiceOperation_ResultTypeAndKindMustMatch("resultKind", "resultType", ServiceOperationResultKind.Void));
            }

            if ((resultType == null || resultType.ResourceTypeKind != ResourceTypeKind.EntityType) && resultSet != null)
            {
                throw new ArgumentException(Strings.ServiceOperation_ResultSetMustBeNull("resultSet", "resultType"));
            }

            if (resultType != null && resultType.ResourceTypeKind == ResourceTypeKind.EntityType && (resultSet == null || !resultSet.ResourceType.IsAssignableFrom(resultType)))
            {
                throw new ArgumentException(Strings.ServiceOperation_ResultTypeAndResultSetMustMatch("resultType", "resultSet"));
            }

            if (method != XmlConstants.HttpMethodGet && method != XmlConstants.HttpMethodPost)
            {
                throw new ArgumentException(Strings.ServiceOperation_NotSupportedProtocolMethod(method, name));
            }

            this.name = name;
            this.resultKind = resultKind;
            this.resultType = resultType;
            this.resourceSet = resultSet;
            this.method = method;
            if (parameters == null)
            {
                this.parameters = ServiceOperation.emptyParameterCollection;
            }
            else
            {
                this.parameters = new ReadOnlyCollection<ServiceOperationParameter>(new List<ServiceOperationParameter>(parameters));
                HashSet<string> paramNames = new HashSet<string>(StringComparer.Ordinal);
                foreach (ServiceOperationParameter p in this.parameters)
                {
                    if (!paramNames.Add(p.Name))
                    {
                        throw new ArgumentException(Strings.ServiceOperation_DuplicateParameterName(p.Name), "parameters");
                    }
                }
            }
        }
Example #8
0
 public ServiceOperation(string name, ServiceOperationResultKind resultKind, ResourceType resultType, ResourceSet resultSet, string method, IEnumerable <ServiceOperationParameter> parameters) : base(name, resultKind, GetReturnTypeFromResultType(resultType, resultKind), resultSet, null, method, parameters, OperationParameterBindingKind.Never, OperationKind.ServiceOperation)
 {
     if (base.OperationParameters == OperationParameter.EmptyOperationParameterCollection)
     {
         this.parameters = ServiceOperationParameter.EmptyServiceOperationParameterCollection;
     }
     else
     {
         this.parameters = new ReadOnlyCollection <ServiceOperationParameter>(base.OperationParameters.Cast <ServiceOperationParameter>().ToList <ServiceOperationParameter>());
     }
 }
 /// <summary>
 /// Initializes a new <see cref="DomainDataServiceOperation"/> instance.
 /// </summary>
 /// <param name="name">name of the service operation.</param>
 /// <param name="resultKind">Kind of result expected from this operation.</param>
 /// <param name="resultType">Type of element of the method result.</param>
 /// <param name="resultSet">EntitySet of the result expected from this operation.</param>
 /// <param name="method">Protocol (for example HTTP) method the service operation responds to.</param>
 /// <param name="parameters">In-order parameters for this operation.</param>
 /// <param name="operationKind">Kind of domain service operation.</param>
 internal DomainDataServiceOperation(
     string name,
     ServiceOperationResultKind resultKind,
     ResourceType resultType,
     ResourceSet resultSet,
     string method,
     IEnumerable <ServiceOperationParameter> parameters,
     DomainOperation operationKind) : base(name, resultKind, resultType, resultSet, method, parameters)
 {
     this.OperationKind = operationKind;
 }
Example #10
0
 public ServiceOperation(string name, ServiceOperationResultKind resultKind, ResourceType resultType, ResourceSet resultSet, string method, IEnumerable<ServiceOperationParameter> parameters) : base(name, resultKind, GetReturnTypeFromResultType(resultType, resultKind), resultSet, null, method, parameters, OperationParameterBindingKind.Never, OperationKind.ServiceOperation)
 {
     if (base.OperationParameters == OperationParameter.EmptyOperationParameterCollection)
     {
         this.parameters = ServiceOperationParameter.EmptyServiceOperationParameterCollection;
     }
     else
     {
         this.parameters = new ReadOnlyCollection<ServiceOperationParameter>(base.OperationParameters.Cast<ServiceOperationParameter>().ToList<ServiceOperationParameter>());
     }
 }
        /// <summary>
        /// Adds a new service operation.
        /// </summary>
        /// <param name="name">The name of the service operation.</param>
        /// <param name="resultKind">The kind of service operation.</param>
        /// <param name="resultType">The type of service operation.</param>
        /// <param name="resultSet">Information about the resource.</param>
        /// <param name="method">The method of the service operation.</param>
        /// <param name="parameters">Parameters for the service operation.</param>
        /// <returns>The newly added service operation.</returns>
        public ServiceOperation AddServiceOperation(string name, ServiceOperationResultKind resultKind, ResourceType resultType, ResourceSet resultSet,
                                                    string method, IEnumerable <ServiceOperationParameter> parameters)
        {
            ServiceOperation serviceOperation = new ServiceOperation(name, resultKind, resultType, resultSet, method, parameters);

            serviceOperation.SetReadOnly();
            readerWriterLock.EnterWriteLock();
            try
            {
                this.serviceOperations.Add(name, serviceOperation);
            }
            finally
            {
                readerWriterLock.ExitWriteLock();
            }
            return(serviceOperation);
        }
Example #12
0
        /// <summary>
        /// Gets the return type of the operation.
        /// </summary>
        /// <param name="resultType">Type of element of the method result. This is the item type of the return type if the return type is a collection type.</param>
        /// <param name="resultKind">Kind of result expected from this operation.</param>
        /// <returns>Returns the return type of the operation.</returns>
        private static ResourceType GetReturnTypeFromResultType(ResourceType resultType, ServiceOperationResultKind resultKind)
        {
            if ((resultKind == ServiceOperationResultKind.Void && resultType != null) ||
                (resultKind != ServiceOperationResultKind.Void && resultType == null))
            {
                throw new ArgumentException(Strings.ServiceOperation_ResultTypeAndKindMustMatch("resultKind", "resultType", ServiceOperationResultKind.Void));
            }

            if (resultType != null && resultType.ResourceTypeKind == ResourceTypeKind.Collection)
            {
                throw new ArgumentException(Strings.ServiceOperation_InvalidResultType(resultType.FullName));
            }

            if (resultType != null && resultType.ResourceTypeKind == ResourceTypeKind.EntityCollection)
            {
                throw new ArgumentException(Strings.ServiceOperation_InvalidResultType(resultType.FullName));
            }

            ResourceType returnType;
            if (resultType == null)
            {
                Debug.Assert(resultKind == ServiceOperationResultKind.Void, "resultKind == ServiceOperationResultKind.Void");
                returnType = null;
            }
            else if ((resultType.ResourceTypeKind == ResourceTypeKind.Primitive || resultType.ResourceTypeKind == ResourceTypeKind.ComplexType) && (resultKind == ServiceOperationResultKind.Enumeration || resultKind == ServiceOperationResultKind.QueryWithMultipleResults))
            {
                returnType = ResourceType.GetCollectionResourceType(resultType);
            }
            else if (resultType.ResourceTypeKind == ResourceTypeKind.EntityType && (resultKind == ServiceOperationResultKind.Enumeration || resultKind == ServiceOperationResultKind.QueryWithMultipleResults))
            {
                returnType = ResourceType.GetEntityCollectionResourceType(resultType);
            }
            else
            {
                Debug.Assert(
                    resultKind == ServiceOperationResultKind.DirectValue || resultKind == ServiceOperationResultKind.QueryWithSingleResult,
                    "resultKind == ServiceOperationResultKind.DirectValue || resultKind == ServiceOperationResultKind.QueryWithSingleResult");
                returnType = resultType;
            }

            return returnType;
        }
Example #13
0
 /// <summary>Creates a new instance of the service operation.</summary>
 /// <param name="name">Name of the service operation.</param>
 /// <param name="resultKind">
 ///   <see cref="T:Microsoft.OData.Service.Providers.ServiceOperationResultKind" /> that is the kind of result expected from this operation.</param>
 /// <param name="resultType">
 ///   <see cref="T:Microsoft.OData.Service.Providers.ResourceType" /> that is the result of the operation.</param>
 /// <param name="resultSet">
 ///   <see cref="T:Microsoft.OData.Service.Providers.ResourceSet" /> that is the result of the operation.</param>
 /// <param name="method">Protocol method to which the service operation responds.</param>
 /// <param name="parameters">Ordered collection of <see cref="T:Microsoft.OData.Service.Providers.ServiceOperationParameter" /> objects that are parameters for the operation.</param>
 public ServiceOperation(string name, ServiceOperationResultKind resultKind, ResourceType resultType, ResourceSet resultSet, string method, IEnumerable<ServiceOperationParameter> parameters)
     : base(
     name,
     resultKind,
     ServiceOperation.GetReturnTypeFromResultType(resultType, resultKind),
     resultSet,
     null /*resultSetExpression*/,
     method,
     parameters,
     OperationParameterBindingKind.Never,
     OperationKind.ServiceOperation)
 {
     Debug.Assert(this.OperationParameters != null, "this.OperationParameters != null");
     if (this.OperationParameters == OperationParameter.EmptyOperationParameterCollection)
     {
         this.parameters = ServiceOperationParameter.EmptyServiceOperationParameterCollection;
     }
     else
     {
         this.parameters = new ReadOnlyCollection<ServiceOperationParameter>(this.OperationParameters.Cast<ServiceOperationParameter>().ToList());
     }
 }
Example #14
0
 /// <summary>Creates a new instance of the service operation.</summary>
 /// <param name="name">Name of the service operation.</param>
 /// <param name="resultKind">
 ///   <see cref="T:Microsoft.OData.Service.Providers.ServiceOperationResultKind" /> that is the kind of result expected from this operation.</param>
 /// <param name="resultType">
 ///   <see cref="T:Microsoft.OData.Service.Providers.ResourceType" /> that is the result of the operation.</param>
 /// <param name="resultSet">
 ///   <see cref="T:Microsoft.OData.Service.Providers.ResourceSet" /> that is the result of the operation.</param>
 /// <param name="method">Protocol method to which the service operation responds.</param>
 /// <param name="parameters">Ordered collection of <see cref="T:Microsoft.OData.Service.Providers.ServiceOperationParameter" /> objects that are parameters for the operation.</param>
 public ServiceOperation(string name, ServiceOperationResultKind resultKind, ResourceType resultType, ResourceSet resultSet, string method, IEnumerable <ServiceOperationParameter> parameters)
     : base(
         name,
         resultKind,
         ServiceOperation.GetReturnTypeFromResultType(resultType, resultKind),
         resultSet,
         null /*resultSetExpression*/,
         method,
         parameters,
         OperationParameterBindingKind.Never,
         OperationKind.ServiceOperation)
 {
     Debug.Assert(this.OperationParameters != null, "this.OperationParameters != null");
     if (this.OperationParameters == OperationParameter.EmptyOperationParameterCollection)
     {
         this.parameters = ServiceOperationParameter.EmptyServiceOperationParameterCollection;
     }
     else
     {
         this.parameters = new ReadOnlyCollection <ServiceOperationParameter>(this.OperationParameters.Cast <ServiceOperationParameter>().ToList());
     }
 }
Example #15
0
        /// <summary>
        /// Returns the <see cref="ServiceOperationResultKind"/> based on the <paramref name="returnType"/> of the operation.
        /// </summary>
        /// <param name="returnType">The return type of the operation.</param>
        /// <param name="isComposable">true if further composition is allowed after calling this operation; false otherwise.</param>
        /// <returns>Returns the <see cref="ServiceOperationResultKind"/> based on the <paramref name="returnType"/> of the operation.</returns>
        internal static ServiceOperationResultKind GetResultKindFromReturnType(ResourceType returnType, bool isComposable)
        {
            ServiceOperationResultKind resultKind;

            if (returnType == null)
            {
                resultKind = ServiceOperationResultKind.Void;
            }
            else if (returnType.ResourceTypeKind == ResourceTypeKind.EntityCollection && isComposable)
            {
                resultKind = ServiceOperationResultKind.QueryWithMultipleResults;
            }
            else if ((returnType.ResourceTypeKind == ResourceTypeKind.EntityCollection && !isComposable) || returnType.ResourceTypeKind == ResourceTypeKind.Collection)
            {
                resultKind = ServiceOperationResultKind.Enumeration;
            }
            else
            {
                resultKind = ServiceOperationResultKind.DirectValue;
            }

            return(resultKind);
        }
Example #16
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);
         }
     }
 }
Example #17
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);
         }
     }
 }
 /// <summary>
 /// Check whether the given value for ServiceOperationResultKind is valid. If not, throw argument exception.
 /// </summary>
 /// <param name="kind">value for ServiceOperationResultKind</param>
 /// <param name="parameterName">name of the parameter</param>
 /// <exception cref="ArgumentException">if the value is not valid.</exception>
 private static void CheckServiceOperationResultKind(ServiceOperationResultKind kind, string parameterName)
 {
     if (kind < ServiceOperationResultKind.DirectValue ||
         kind > ServiceOperationResultKind.Void)
     {
         throw new ArgumentException(Strings.General_InvalidEnumValue(kind.GetType().Name), parameterName);
     }
 }
Example #19
0
 private static ResourceType GetReturnTypeFromResultType(ResourceType resultType, ServiceOperationResultKind resultKind)
 {
     if (((resultKind == ServiceOperationResultKind.Void) && (resultType != null)) || ((resultKind != ServiceOperationResultKind.Void) && (resultType == null)))
     {
         throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_ResultTypeAndKindMustMatch("resultKind", "resultType", ServiceOperationResultKind.Void));
     }
     if ((resultType != null) && (resultType.ResourceTypeKind == ResourceTypeKind.Collection))
     {
         throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_InvalidResultType(resultType.FullName));
     }
     if ((resultType != null) && (resultType.ResourceTypeKind == ResourceTypeKind.EntityCollection))
     {
         throw new ArgumentException(System.Data.Services.Strings.ServiceOperation_InvalidResultType(resultType.FullName));
     }
     if (resultType == null)
     {
         return(null);
     }
     if (((resultType.ResourceTypeKind == ResourceTypeKind.Primitive) || (resultType.ResourceTypeKind == ResourceTypeKind.ComplexType)) && ((resultKind == ServiceOperationResultKind.Enumeration) || (resultKind == ServiceOperationResultKind.QueryWithMultipleResults)))
     {
         return(ResourceType.GetCollectionResourceType(resultType));
     }
     if ((resultType.ResourceTypeKind == ResourceTypeKind.EntityType) && ((resultKind == ServiceOperationResultKind.Enumeration) || (resultKind == ServiceOperationResultKind.QueryWithMultipleResults)))
     {
         return(ResourceType.GetEntityCollectionResourceType(resultType));
     }
     return(resultType);
 }
Example #20
0
		public ServiceOperation (string name, ServiceOperationResultKind resultKind, ResourceType resultType, ResourceSet resultSet, string method, IEnumerable <ServiceOperationParameter> parameters)
		{
			throw new NotImplementedException ();
		}
Example #21
0
        /// <summary>
        /// Gets the return type of the operation.
        /// </summary>
        /// <param name="resultType">Type of element of the method result. This is the item type of the return type if the return type is a collection type.</param>
        /// <param name="resultKind">Kind of result expected from this operation.</param>
        /// <returns>Returns the return type of the operation.</returns>
        private static ResourceType GetReturnTypeFromResultType(ResourceType resultType, ServiceOperationResultKind resultKind)
        {
            if ((resultKind == ServiceOperationResultKind.Void && resultType != null) ||
                (resultKind != ServiceOperationResultKind.Void && resultType == null))
            {
                throw new ArgumentException(Strings.ServiceOperation_ResultTypeAndKindMustMatch("resultKind", "resultType", ServiceOperationResultKind.Void));
            }

            if (resultType != null && resultType.ResourceTypeKind == ResourceTypeKind.Collection)
            {
                throw new ArgumentException(Strings.ServiceOperation_InvalidResultType(resultType.FullName));
            }

            if (resultType != null && resultType.ResourceTypeKind == ResourceTypeKind.EntityCollection)
            {
                throw new ArgumentException(Strings.ServiceOperation_InvalidResultType(resultType.FullName));
            }

            ResourceType returnType;

            if (resultType == null)
            {
                Debug.Assert(resultKind == ServiceOperationResultKind.Void, "resultKind == ServiceOperationResultKind.Void");
                returnType = null;
            }
            else if ((resultType.ResourceTypeKind == ResourceTypeKind.Primitive || resultType.ResourceTypeKind == ResourceTypeKind.ComplexType) && (resultKind == ServiceOperationResultKind.Enumeration || resultKind == ServiceOperationResultKind.QueryWithMultipleResults))
            {
                returnType = ResourceType.GetCollectionResourceType(resultType);
            }
            else if (resultType.ResourceTypeKind == ResourceTypeKind.EntityType && (resultKind == ServiceOperationResultKind.Enumeration || resultKind == ServiceOperationResultKind.QueryWithMultipleResults))
            {
                returnType = ResourceType.GetEntityCollectionResourceType(resultType);
            }
            else
            {
                Debug.Assert(
                    resultKind == ServiceOperationResultKind.DirectValue || resultKind == ServiceOperationResultKind.QueryWithSingleResult,
                    "resultKind == ServiceOperationResultKind.DirectValue || resultKind == ServiceOperationResultKind.QueryWithSingleResult");
                returnType = resultType;
            }

            return(returnType);
        }
 // paramters can be null
 public ServiceOperation(string name, ServiceOperationResultKind resultKind, ResourceType resultType, ResourceSet resultSet, string method, IEnumerable<ServiceOperationParameter> parameters)
 {
   Contract.Requires(!string.IsNullOrEmpty(method));
   Contract.Requires(!string.IsNullOrEmpty(name));
   Contract.Requires(method == "GET" || method == "POST");
 }
Example #23
0
 /// <summary>
 /// Initializes a new <see cref="ServiceOperation"/> instance.
 /// </summary>
 /// <param name="name">name of the service operation.</param>
 /// <param name="resultKind">Kind of result expected from this operation.</param>
 /// <param name="resultType">Type of element of the method result.</param>
 /// <param name="resultSet">EntitySet of the result expected from this operation.</param>
 /// <param name="method">Protocol (for example HTTP) method the service operation responds to.</param>
 /// <param name="parameters">In-order parameters for this operation.</param>
 public ServiceOperation  AddServiceOperation(string name, ServiceOperationResultKind resultKind, ResourceType resultType, ResourceSet resultSet, string method, IEnumerable<ServiceOperationParameter> parameters)
 {
     ServiceOperation so = new ServiceOperation(name, resultKind, resultType, resultSet, method, parameters);
     this.serviceOperationsByName.Add(name, so);
     return so;
 }
Example #24
0
 public void AddServiceOperation(string name, ServiceOperationResultKind kind, string typeName)
 {
     // call service op to add to metadata
     string url = this.ServiceUri + String.Format("/AddServiceOperation?name='{0}'&serviceOperationResultKind='{1}'&typeName='{2}'", name, kind.ToString(), typeName);
     this.ExecuteServiceOp(url);
 }
Example #25
0
 // paramters can be null
 public ServiceOperation(string name, ServiceOperationResultKind resultKind, ResourceType resultType, ResourceSet resultSet, string method, IEnumerable <ServiceOperationParameter> parameters)
 {
     Contract.Requires(!string.IsNullOrEmpty(method));
     Contract.Requires(!string.IsNullOrEmpty(name));
     Contract.Requires(method == "GET" || method == "POST");
 }
Example #26
0
        /// <summary>
        /// Initializes a new <see cref="Operation"/> instance.
        /// </summary>
        /// <param name="name">name of the operation.</param>
        /// <param name="resultKind">Kind of result expected from this operation.</param>
        /// <param name="returnType">Return type of the operation.</param>
        /// <param name="resultSet">EntitySet of the result expected from this operation, must be null if <paramref name="resultSetPathExpression"/> is not null.</param>
        /// <param name="resultSetPathExpression">Path expression to calculate the result set of the operation, must be null if <paramref name="resultSet"/> is not null.</param>
        /// <param name="method">Protocol (for example HTTP) method the service operation responds to.</param>
        /// <param name="parameters">In-order parameters for this operation.</param>
        /// <param name="operationParameterBindingKind">the kind of the operation parameter binding (Never, Sometimes, Always).</param>
        /// <param name="kind">The kind of the current service operation.</param>
        internal Operation(
            string name,
            ServiceOperationResultKind resultKind,
            ResourceType returnType,
            ResourceSet resultSet,
            ResourceSetPathExpression resultSetPathExpression,
            string method,
            IEnumerable <OperationParameter> parameters,
            OperationParameterBindingKind operationParameterBindingKind,
            OperationKind kind)
        {
            WebUtil.CheckStringArgumentNullOrEmpty(name, "name");
            WebUtil.CheckServiceOperationResultKind(resultKind, "resultKind");
            WebUtil.CheckStringArgumentNullOrEmpty(method, "method");

            Debug.Assert(
                this.GetType() == typeof(ServiceOperation) && kind == OperationKind.ServiceOperation ||
                this.GetType() == typeof(ServiceAction) && kind == OperationKind.Action,
                "OperationKind and the current type doesn't match.");

            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           = Operation.ValidateParameters(this.operationParameterBindingKind, parameters);

            if (this.operationParameterBindingKind != OperationParameterBindingKind.Never)
            {
                Debug.Assert(
                    this.operationParameterBindingKind == OperationParameterBindingKind.Always || this.operationParameterBindingKind == OperationParameterBindingKind.Sometimes,
                    "Value of operationParameterBindingKind was expected to be 'always' or 'sometimes'.");

                Debug.Assert(this.kind != OperationKind.ServiceOperation, "ServiceOperations should never be bindable.");
                this.bindingParameter = this.operationParameters.FirstOrDefault();
                if (this.bindingParameter == null)
                {
                    throw new ArgumentException(Strings.ServiceOperation_BindableOperationMustHaveAtLeastOneParameter, "operationParameterBindingKind");
                }

                if (resourceSet != null)
                {
                    throw new ArgumentException(Strings.Opereration_BoundOperationsMustNotSpecifyEntitySetOnlyEntitySetPath(this.name), "resourceSet");
                }

                if (resultSetPathExpression != null &&
                    this.bindingParameter.ParameterType.ResourceTypeKind != ResourceTypeKind.EntityType &&
                    this.bindingParameter.ParameterType.ResourceTypeKind != ResourceTypeKind.EntityCollection)
                {
                    throw new ArgumentException(Strings.ServiceOperation_BindingParameterMustBeEntityToUsePathExpression("resultSetPathExpression"));
                }

                if (this.kind == OperationKind.Action &&
                    !(this.bindingParameter.ParameterType.ResourceTypeKind == ResourceTypeKind.EntityType ||
                      this.bindingParameter.ParameterType.ResourceTypeKind == ResourceTypeKind.EntityCollection))
                {
                    throw new ArgumentException(Strings.ServiceOperation_ActionBindingMustBeEntityOrEntityCollection, "parameters");
                }

                if (this.resultSetPathExpression != null)
                {
                    this.resultSetPathExpression.SetBindingParameter(this.bindingParameter);
                }
            }

            Debug.Assert(this.kind != OperationKind.Action || string.CompareOrdinal(XmlConstants.HttpMethodPost, this.method) == 0, "HttpMethod must be POST for Actions.");
            Debug.Assert(this.resourceSet == null || this.resultSetPathExpression == null, "'resultSet' and 'resultSetPathExpression' cannot be both set by the constructor.");
        }
Example #27
0
 /// <summary>
 /// Adds a new service operation.
 /// </summary>
 /// <param name="name">The name of the service operation.</param>
 /// <param name="resultKind">The kind of service operation.</param>
 /// <param name="resultType">The type of service operation.</param>
 /// <param name="resultSet">Information about the resource.</param>
 /// <param name="method">The method of the service operation.</param>
 /// <param name="parameters">Parameters for the service operation.</param>
 /// <returns>The newly added service operation.</returns>
 public ServiceOperation AddServiceOperation(string name, ServiceOperationResultKind resultKind, ResourceType resultType, ResourceSet resultSet,
     string method, IEnumerable<ServiceOperationParameter> parameters)
 {
     ServiceOperation serviceOperation = new ServiceOperation(name, resultKind, resultType, resultSet, method, parameters);
     serviceOperation.SetReadOnly();
     readerWriterLock.EnterWriteLock();
     try
     {
         this.serviceOperations.Add(name, serviceOperation);
     }
     finally
     {
         readerWriterLock.ExitWriteLock();
     }
     return serviceOperation;
 }
        /// <summary>
        /// Create a service operation based on a domain operation entry.
        /// </summary>
        /// <param name="operation">Domain operation corresponding to the service operation.</param>
        /// <returns>ServiceOperation instance mapping to the domain operation.</returns>
        private DomainDataServiceOperation CreateServiceOperation(DomainOperationEntry operation)
        {
            List <ServiceOperationParameter> operationParameters = new List <ServiceOperationParameter>();

            foreach (DomainOperationParameter p in operation.Parameters)
            {
                // Only allow primitive type parameters for service operations.
                ResourceType parameterType = ResourceType.GetPrimitiveResourceType(p.ParameterType);
                if (parameterType == null)
                {
                    return(null);
                }

                operationParameters.Add(new ServiceOperationParameter(p.Name, parameterType));
            }

            ServiceOperationResultKind resultKind = ServiceOperationResultKind.Void;
            ResourceType resultResourceType       = null;

            if (operation.ReturnType != null)
            {
                bool isEnumeration;
                resultResourceType = this.ResolveResourceType(operation.ReturnType, out isEnumeration);

                if (resultResourceType == null)
                {
                    // Ignore service operations for which the appropriate resource type could not be inferred.
                    return(null);
                }

                if (isEnumeration)
                {
                    // Will need to distinguish between ServiceOperationResultKind.Enumeration and
                    // ServiceOperationResultKind.QueryWithMultipleResults once we support composition.
                    resultKind = ServiceOperationResultKind.Enumeration;
                }
                else
                {
                    resultKind = ServiceOperationResultKind.DirectValue;
                }
            }

            bool hasSideEffects = false;

            switch (operation.Operation)
            {
            case DomainOperation.Invoke:
                hasSideEffects = (operation.OperationAttribute as InvokeAttribute).HasSideEffects;
                break;

            case DomainOperation.Query:
                hasSideEffects = (operation.OperationAttribute as QueryAttribute).HasSideEffects;
                break;

            default:
                break;
            }

            ResourceSet resultSet = null;

            if (resultResourceType.ResourceTypeKind == ResourceTypeKind.EntityType)
            {
                resultSet = this.sets.Values.SingleOrDefault(s => s.ResourceType.InstanceType.IsAssignableFrom(resultResourceType.InstanceType));
                if (resultSet == null)
                {
                    // Only support those service query operations which have a corresponding entity set.
                    return(null);
                }
            }

            DomainDataServiceOperation op = new DomainDataServiceOperation(
                operation.Name,
                resultKind,
                resultResourceType,
                resultSet,
                hasSideEffects ? ServiceUtils.HttpPostMethodName : ServiceUtils.HttpGetMethodName,
                operationParameters,
                operation.Operation);

            return(op);
        }
Example #29
0
        /// <summary>
        /// Initializes a new <see cref="Operation"/> instance.
        /// </summary>
        /// <param name="name">name of the operation.</param>
        /// <param name="resultKind">Kind of result expected from this operation.</param>
        /// <param name="returnType">Return type of the operation.</param>
        /// <param name="resultSet">EntitySet of the result expected from this operation, must be null if <paramref name="resultSetPathExpression"/> is not null.</param>
        /// <param name="resultSetPathExpression">Path expression to calculate the result set of the operation, must be null if <paramref name="resultSet"/> is not null.</param>
        /// <param name="method">Protocol (for example HTTP) method the service operation responds to.</param>
        /// <param name="parameters">In-order parameters for this operation.</param>
        /// <param name="operationParameterBindingKind">the kind of the operation parameter binding (Never, Sometimes, Always).</param>
        /// <param name="kind">The kind of the current service operation.</param>
        internal Operation(
            string name,
            ServiceOperationResultKind resultKind,
            ResourceType returnType,
            ResourceSet resultSet,
            ResourceSetPathExpression resultSetPathExpression,
            string method,
            IEnumerable<OperationParameter> parameters,
            OperationParameterBindingKind operationParameterBindingKind,
            OperationKind kind)
        {
            WebUtil.CheckStringArgumentNullOrEmpty(name, "name");
            WebUtil.CheckServiceOperationResultKind(resultKind, "resultKind");
            WebUtil.CheckStringArgumentNullOrEmpty(method, "method");

            Debug.Assert(
                this.GetType() == typeof(ServiceOperation) && kind == OperationKind.ServiceOperation ||
                this.GetType() == typeof(ServiceAction) && kind == OperationKind.Action,
                "OperationKind and the current type doesn't match.");

            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 = Operation.ValidateParameters(this.operationParameterBindingKind, parameters);

            if (this.operationParameterBindingKind != OperationParameterBindingKind.Never)
            {
                Debug.Assert(
                    this.operationParameterBindingKind == OperationParameterBindingKind.Always || this.operationParameterBindingKind == OperationParameterBindingKind.Sometimes,
                    "Value of operationParameterBindingKind was expected to be 'always' or 'sometimes'.");

                Debug.Assert(this.kind != OperationKind.ServiceOperation, "ServiceOperations should never be bindable.");
                this.bindingParameter = this.operationParameters.FirstOrDefault();
                if (this.bindingParameter == null)
                {
                    throw new ArgumentException(Strings.ServiceOperation_BindableOperationMustHaveAtLeastOneParameter, "operationParameterBindingKind");
                }

                if (resourceSet != null)
                {
                    throw new ArgumentException(Strings.Opereration_BoundOperationsMustNotSpecifyEntitySetOnlyEntitySetPath(this.name), "resourceSet");
                }

                if (resultSetPathExpression != null &&
                    this.bindingParameter.ParameterType.ResourceTypeKind != ResourceTypeKind.EntityType &&
                    this.bindingParameter.ParameterType.ResourceTypeKind != ResourceTypeKind.EntityCollection)
                {
                    throw new ArgumentException(Strings.ServiceOperation_BindingParameterMustBeEntityToUsePathExpression("resultSetPathExpression"));
                }

                if (this.kind == OperationKind.Action &&
                    !(this.bindingParameter.ParameterType.ResourceTypeKind == ResourceTypeKind.EntityType ||
                    this.bindingParameter.ParameterType.ResourceTypeKind == ResourceTypeKind.EntityCollection))
                {
                    throw new ArgumentException(Strings.ServiceOperation_ActionBindingMustBeEntityOrEntityCollection, "parameters");
                }

                if (this.resultSetPathExpression != null)
                {
                    this.resultSetPathExpression.SetBindingParameter(this.bindingParameter);
                }
            }

            Debug.Assert(this.kind != OperationKind.Action || string.CompareOrdinal(XmlConstants.HttpMethodPost, this.method) == 0, "HttpMethod must be POST for Actions.");
            Debug.Assert(this.resourceSet == null || this.resultSetPathExpression == null, "'resultSet' and 'resultSetPathExpression' cannot be both set by the constructor.");
        }
Example #30
0
        /// <summary>
        /// Returns the <see cref="ServiceOperationResultKind"/> based on the <paramref name="returnType"/> of the operation.
        /// </summary>
        /// <param name="returnType">The return type of the operation.</param>
        /// <param name="isComposable">true if further composition is allowed after calling this operation; false otherwise.</param>
        /// <returns>Returns the <see cref="ServiceOperationResultKind"/> based on the <paramref name="returnType"/> of the operation.</returns>
        internal static ServiceOperationResultKind GetResultKindFromReturnType(ResourceType returnType, bool isComposable)
        {
            ServiceOperationResultKind resultKind;
            if (returnType == null)
            {
                resultKind = ServiceOperationResultKind.Void;
            }
            else if (returnType.ResourceTypeKind == ResourceTypeKind.EntityCollection && isComposable)
            {
                resultKind = ServiceOperationResultKind.QueryWithMultipleResults;
            }
            else if ((returnType.ResourceTypeKind == ResourceTypeKind.EntityCollection && !isComposable) || returnType.ResourceTypeKind == ResourceTypeKind.Collection)
            {
                resultKind = ServiceOperationResultKind.Enumeration;
            }
            else
            {
                resultKind = ServiceOperationResultKind.DirectValue;
            }

            return resultKind;
        }
Example #31
0
 public ServiceOperation(string name, ServiceOperationResultKind resultKind, ResourceType resultType, ResourceSet resultSet, string method, IEnumerable <ServiceOperationParameter> parameters)
 {
     throw new NotImplementedException();
 }