public ResourceAssociationSet GetResourceAssociationSet(
     ResourceSet resourceSet,
     ResourceType resourceType,
     ResourceProperty resourceProperty)
 {
     // resourceProperty.GetAnnotation().ResourceAssociationSet;
     return resourceProperty.CustomState as ResourceAssociationSet;
 } 
        /// <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");
                    }
                }
            }
        }
Пример #3
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>());
            }
        }
Пример #4
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>
        /// Constructs a new ResourceSetWrapper instance using the ResourceSet instance to be enclosed.
        /// </summary>
        /// <param name="resourceSet">ResourceSet instance to be wrapped by the current instance</param>
        /// <param name="resourceType">Resource type (normalized to a single instance by the caller).</param>
        public ResourceSetWrapper(ResourceSet resourceSet, ResourceType resourceType)
        {
            Debug.Assert(resourceSet != null, "resourceSet != null");

            if (!resourceSet.IsReadOnly)
            {
                throw new DataServiceException(500, Strings.DataServiceProviderWrapper_ResourceContainerNotReadonly(resourceSet.Name));
            }

            this.resourceSet = resourceSet;
            this.resourceType = resourceType;
        }
Пример #6
0
        /// <summary>
        /// Constructs a ResourceAssociationEnd instance.
        /// </summary>
        /// <param name="resourceSet">Resource set of the association end.</param>
        /// <param name="resourceType">Resource type of the association end.</param>
        /// <param name="resourceProperty">Resource property of the association end.</param>
        public ResourceAssociationSetEnd(ResourceSet resourceSet, ResourceType resourceType, ResourceProperty resourceProperty)
        {
            WebUtil.CheckArgumentNull(resourceSet, "resourceSet");
            WebUtil.CheckArgumentNull(resourceType, "resourceType");

            if (resourceProperty != null && (resourceType.TryResolvePropertyName(resourceProperty.Name) == null || resourceProperty.TypeKind != ResourceTypeKind.EntityType))
            {
                throw new ArgumentException(Strings.ResourceAssociationSetEnd_ResourcePropertyMustBeNavigationPropertyOnResourceType);
            }

            if (!resourceSet.ResourceType.IsAssignableFrom(resourceType) && !resourceType.IsAssignableFrom(resourceSet.ResourceType))
            {
                throw new ArgumentException(Strings.ResourceAssociationSetEnd_ResourceTypeMustBeAssignableToResourceSet);
            }

            this.resourceSet = resourceSet;
            this.resourceType = resourceType;

            // Note that for the TargetEnd, resourceProperty can be null.
            this.resourceProperty = resourceProperty;
        }
Пример #7
0
        /// <summary>
        /// Gets the ResourceAssociationSet instance when given the source association end.
        /// </summary>
        /// <param name="resourceSet">Resource set of the source association end.</param>
        /// <param name="resourceType">Resource type of the source association end.</param>
        /// <param name="resourceProperty">Resource property of the source association end.</param>
        /// <returns>ResourceAssociationSet instance.</returns>
        public override ResourceAssociationSet GetResourceAssociationSet(ResourceSet resourceSet, ResourceType resourceType, ResourceProperty resourceProperty)
        {
            Debug.Assert(resourceSet != null, "resourceSet != null");
            Debug.Assert(resourceType != null, "resourceType != null");
            Debug.Assert(resourceProperty != null, "resourceProperty != null");
            Debug.Assert(resourceType == DataServiceProviderWrapper.GetDeclaringTypeForProperty(resourceType, resourceProperty), "resourceType should be the declaring type for resourceProperty");

            ResourceType targetType = resourceProperty.ResourceType;
            Debug.Assert(targetType != null && targetType.ResourceTypeKind == ResourceTypeKind.EntityType, "targetType != null && targetType.ResourceTypeKind == ResourceTypeKind.EntityType");

            ResourceSet targetSet = InternalGetContainerForResourceType(targetType.InstanceType, this.EntitySets.Values);
            Debug.Assert(targetSet != null, "targetSet != null");

            string associationName = resourceType.Name + '_' + resourceProperty.Name;

            // EF associations are first-class, navigation properties come second. So you actually
            // define the two-way association first, then say that the nav props "go through" them.
            // For CLR, however, there is no such constraint - in fact, we're very happy with one-way (link) associations.
            // For one-way associations, the target property is always null.
            ResourceAssociationSetEnd sourceEnd = new ResourceAssociationSetEnd(resourceSet, resourceType, resourceProperty);
            ResourceAssociationSetEnd targetEnd = new ResourceAssociationSetEnd(targetSet, targetType, null);
            return new ResourceAssociationSet(associationName, sourceEnd, targetEnd);
        }
Пример #8
0
 /// <summary>
 /// Returns the IQueryable that represents the container.
 /// </summary>
 /// <param name="container">resource set representing the entity set.</param>
 /// <returns>
 /// An IQueryable that represents the container; null if there is
 /// no container for the specified name.
 /// </returns>
 public IQueryable GetQueryRootForResourceSet(ResourceSet container)
 {
     Debug.Assert(container != null, "resourceContainer != null");
     return(this.GetResourceContainerInstance(container));
 }
Пример #9
0
        /// <summary>
        /// Adds a new <see cref="ServiceOperation"/> based on the specified <paramref name="method"/>
        /// instance.
        /// </summary>
        /// <param name="method">Method to expose as a service operation.</param>
        /// <param name="protocolMethod">Protocol (for example HTTP) method the service operation responds to.</param>
        private void AddServiceOperation(MethodInfo method, string protocolMethod)
        {
            Debug.Assert(method != null, "method != null");
            Debug.Assert(!method.IsAbstract, "!method.IsAbstract - if method is abstract, the type is abstract - already checked");

            // This method is only called for V1 providers, since in case of custom providers,
            // they are suppose to load the metadata themselves.
            if (this.metadata.ServiceOperations.ContainsKey(method.Name))
            {
                throw new InvalidOperationException(Strings.BaseServiceProvider_OverloadingNotSupported(this.Type, method));
            }

            bool hasSingleResult = SingleResultAttribute.MethodHasSingleResult(method);
            ServiceOperationResultKind resultKind;
            ResourceType resourceType = null;

            if (method.ReturnType == typeof(void))
            {
                resultKind = ServiceOperationResultKind.Void;
                this.UpdateEdmSchemaVersion(MetadataEdmSchemaVersion.Version1Dot1);
            }
            else
            {
                // Load the metadata of the resource type on the fly.
                // For Edm provider, it might not mean anything, but for reflection service provider, we need to
                // load the metadata of the type if its used only in service operation case
                Type resultType = null;
                if (WebUtil.IsPrimitiveType(method.ReturnType))
                {
                    resultKind   = ServiceOperationResultKind.DirectValue;
                    resultType   = method.ReturnType;
                    resourceType = ResourceType.GetPrimitiveResourceType(resultType);
                }
                else
                {
                    Type queryableElement = GetGenericInterfaceElementType(method.ReturnType, IQueryableTypeFilter);
                    if (queryableElement != null)
                    {
                        resultKind = hasSingleResult ?
                                     ServiceOperationResultKind.QueryWithSingleResult :
                                     ServiceOperationResultKind.QueryWithMultipleResults;
                        resultType = queryableElement;
                    }
                    else
                    {
                        Type enumerableElement = GetIEnumerableElement(method.ReturnType);
                        if (enumerableElement != null)
                        {
                            resultKind = ServiceOperationResultKind.Enumeration;
                            resultType = enumerableElement;
                        }
                        else
                        {
                            resultType = method.ReturnType;
                            resultKind = ServiceOperationResultKind.DirectValue;
                            this.UpdateEdmSchemaVersion(MetadataEdmSchemaVersion.Version1Dot1);
                        }
                    }

                    Debug.Assert(resultType != null, "resultType != null");
                    resourceType = ResourceType.GetPrimitiveResourceType(resultType);
                    if (resourceType == null)
                    {
                        resourceType = this.PopulateMetadataForType(resultType, this.TypeCache, this.ChildTypesCache, this.EntitySets.Values);
                    }
                }

                if (resourceType == null)
                {
                    throw new InvalidOperationException(Strings.BaseServiceProvider_UnsupportedReturnType(method, method.ReturnType));
                }

                if (resultKind == ServiceOperationResultKind.Enumeration && hasSingleResult)
                {
                    throw new InvalidOperationException(Strings.BaseServiceProvider_IEnumerableAlwaysMultiple(this.Type, method));
                }

                if (hasSingleResult ||
                    (!hasSingleResult &&
                     (resourceType.ResourceTypeKind == ResourceTypeKind.ComplexType ||
                      resourceType.ResourceTypeKind == ResourceTypeKind.Primitive)))
                {
                    this.UpdateEdmSchemaVersion(MetadataEdmSchemaVersion.Version1Dot1);
                }
            }

            ParameterInfo[]             parametersInfo = method.GetParameters();
            ServiceOperationParameter[] parameters     = new ServiceOperationParameter[parametersInfo.Length];
            for (int i = 0; i < parameters.Length; i++)
            {
                ParameterInfo parameterInfo = parametersInfo[i];
                if (parameterInfo.IsOut || parameterInfo.IsRetval)
                {
                    throw new InvalidOperationException(Strings.BaseServiceProvider_ParameterNotIn(method, parameterInfo));
                }

                ResourceType parameterType = ResourceType.GetPrimitiveResourceType(parameterInfo.ParameterType);
                if (parameterType == null)
                {
                    throw new InvalidOperationException(
                              Strings.BaseServiceProvider_ParameterTypeNotSupported(method, parameterInfo, parameterInfo.ParameterType));
                }

                string parameterName = parameterInfo.Name ?? "p" + i.ToString(CultureInfo.InvariantCulture);
                parameters[i] = new ServiceOperationParameter(parameterName, parameterType);
            }

            ResourceSet container = null;

            if (resourceType != null && resourceType.ResourceTypeKind == ResourceTypeKind.EntityType)
            {
                if (!this.TryFindAnyContainerForType(resourceType, out container))
                {
                    throw new InvalidOperationException(
                              Strings.BaseServiceProvider_ServiceOperationMissingSingleEntitySet(method, resourceType.FullName));
                }
            }

            ServiceOperation operation = new ServiceOperation(method.Name, resultKind, resourceType, container, protocolMethod, parameters);

            operation.CustomState = method;
            MimeTypeAttribute attribute = MimeTypeAttribute.GetMimeTypeAttribute(method);

            if (attribute != null)
            {
                operation.MimeType = attribute.MimeType;
            }

            this.metadata.ServiceOperations.Add(method.Name, operation);
        }
Пример #10
0
 public abstract ResourceAssociationSet GetResourceAssociationSet(ResourceSet resourceSet, ResourceType resourceType, ResourceProperty resourceProperty);
Пример #11
0
        /// <summary>
        /// Looks for the first resource set that the specified <paramref name="type"/>
        /// could belong to.
        /// </summary>
        /// <param name="type">Type to look for.</param>
        /// <param name="container">After the method returns, the container to which the type could belong.</param>
        /// <returns>true if a container was found; false otherwise.</returns>
        private bool TryFindAnyContainerForType(ResourceType type, out ResourceSet container)
        {
            Debug.Assert(type != null, "type != null");

            foreach (ResourceSet c in this.EntitySets.Values)
            {
                if (c.ResourceType.IsAssignableFrom(type))
                {
                    container = c;
                    return true;
                }
            }

            container = default(ResourceSet);
            return false;
        }
Пример #12
0
 /// <summary>Given the specified name, tries to find a resource set.</summary>
 /// <param name="name">Name of the resource set to resolve.</param>
 /// <param name="resourceSet">Returns the resolved resource set, null if no resource set for the given name was found.</param>
 /// <returns>True if resource set with the given name was found, false otherwise.</returns>
 public bool TryResolveResourceSet(string name, out ResourceSet resourceSet)
 {
     Debug.Assert(!string.IsNullOrEmpty(name), "!string.IsNullOrEmpty(name)");
     return this.EntitySets.TryGetValue(name, out resourceSet);
 }
Пример #13
0
 /// <summary>
 /// Gets the ResourceAssociationSet instance when given the source association end.
 /// </summary>
 /// <param name="resourceSet">Resource set of the source association end.</param>
 /// <param name="resourceType">Resource type of the source association end.</param>
 /// <param name="resourceProperty">Resource property of the source association end.</param>
 /// <returns>ResourceAssociationSet instance.</returns>
 public abstract ResourceAssociationSet GetResourceAssociationSet(ResourceSet resourceSet, ResourceType resourceType, ResourceProperty resourceProperty);
Пример #14
0
 /// <summary>
 /// Gets the ResourceAssociationSet instance when given the source association end.
 /// </summary>
 /// <param name="resourceSet">Resource set of the source association end.</param>
 /// <param name="resourceType">Resource type of the source association end.</param>
 /// <param name="resourceProperty">Resource property of the source association end.</param>
 /// <returns>ResourceAssociationSet instance.</returns>
 public ResourceAssociationSet GetResourceAssociationSet(ResourceSet resourceSet, ResourceType resourceType, ResourceProperty resourceProperty)
 {
     throw new NotImplementedException("Should never get here, reference properties are not yet supported.");
 }
Пример #15
0
 public ResourceAssociationSetEnd(ResourceSet resourceSet, ResourceType resourceType, ResourceProperty resourceProperty)
 {
     Contract.Requires(resourceSet != null);
     Contract.Requires(resourceType != null);
 }
Пример #16
0
 public ServiceAction(string name, ResourceType returnType, ResourceSet resultSet, OperationParameterBindingKind operationParameterBindingKind, IEnumerable <ServiceActionParameter> parameters) : this(name, returnType, resultSet, null, parameters, operationParameterBindingKind)
 {
 }
Пример #17
0
        internal IEdmEntitySet FindEntitySet(ResourceSet resourceSet)
        {
            string name = resourceSet.EntityContainerName ?? this.metadataProvider.ContainerName;

            return(this.FindExistingEntityContainer(name).FindEntitySet(MetadataProviderUtils.GetEntitySetName(resourceSet)));
        }
Пример #18
0
        private void AddServiceOperation(MethodInfo method, string protocolMethod)
        {
            ServiceOperationResultKind @void;

            if (this.metadata.ServiceOperations.ContainsKey(method.Name))
            {
                throw new InvalidOperationException(System.Data.Services.Strings.BaseServiceProvider_OverloadingNotSupported(this.Type, method));
            }
            bool         flag      = SingleResultAttribute.MethodHasSingleResult(method);
            ResourceType primitive = null;

            if (method.ReturnType == typeof(void))
            {
                @void = ServiceOperationResultKind.Void;
            }
            else
            {
                System.Type returnType;
                if (WebUtil.IsPrimitiveType(method.ReturnType))
                {
                    @void      = ServiceOperationResultKind.DirectValue;
                    returnType = method.ReturnType;
                    primitive  = ResourceType.PrimitiveResourceTypeMap.GetPrimitive(returnType);
                }
                else
                {
                    System.Type genericInterfaceElementType = GetGenericInterfaceElementType(method.ReturnType, new TypeFilter(BaseServiceProvider.IQueryableTypeFilter));
                    if (genericInterfaceElementType != null)
                    {
                        @void      = flag ? ServiceOperationResultKind.QueryWithSingleResult : ServiceOperationResultKind.QueryWithMultipleResults;
                        returnType = genericInterfaceElementType;
                    }
                    else
                    {
                        System.Type iEnumerableElement = GetIEnumerableElement(method.ReturnType);
                        if (iEnumerableElement != null)
                        {
                            @void      = ServiceOperationResultKind.Enumeration;
                            returnType = iEnumerableElement;
                        }
                        else
                        {
                            returnType = method.ReturnType;
                            @void      = ServiceOperationResultKind.DirectValue;
                        }
                    }
                    primitive = ResourceType.PrimitiveResourceTypeMap.GetPrimitive(returnType);
                    if (primitive == null)
                    {
                        primitive = this.PopulateMetadataForType(returnType, this.TypeCache, this.ChildTypesCache, this.EntitySets.Values);
                    }
                }
                if (primitive == null)
                {
                    throw new InvalidOperationException(System.Data.Services.Strings.BaseServiceProvider_UnsupportedReturnType(method, method.ReturnType));
                }
                if ((@void == ServiceOperationResultKind.Enumeration) && flag)
                {
                    throw new InvalidOperationException(System.Data.Services.Strings.BaseServiceProvider_IEnumerableAlwaysMultiple(this.Type, method));
                }
            }
            ParameterInfo[]             parameters     = method.GetParameters();
            ServiceOperationParameter[] parameterArray = new ServiceOperationParameter[parameters.Length];
            for (int i = 0; i < parameterArray.Length; i++)
            {
                ParameterInfo info = parameters[i];
                if (info.IsOut || info.IsRetval)
                {
                    throw new InvalidOperationException(System.Data.Services.Strings.BaseServiceProvider_ParameterNotIn(method, info));
                }
                ResourceType parameterType = ResourceType.PrimitiveResourceTypeMap.GetPrimitive(info.ParameterType);
                if (parameterType == null)
                {
                    throw new InvalidOperationException(System.Data.Services.Strings.BaseServiceProvider_ParameterTypeNotSupported(method, info, info.ParameterType));
                }
                string name = info.Name ?? ("p" + i.ToString(CultureInfo.InvariantCulture));
                parameterArray[i] = new ServiceOperationParameter(name, parameterType);
            }
            ResourceSet container = null;

            if (((primitive != null) && (primitive.ResourceTypeKind == ResourceTypeKind.EntityType)) && !this.TryFindAnyContainerForType(primitive, out container))
            {
                throw new InvalidOperationException(System.Data.Services.Strings.BaseServiceProvider_ServiceOperationMissingSingleEntitySet(method, primitive.FullName));
            }
            ServiceOperation operation = new ServiceOperation(method.Name, @void, primitive, container, protocolMethod, parameterArray)
            {
                CustomState = method
            };
            MimeTypeAttribute mimeTypeAttribute = MimeTypeAttribute.GetMimeTypeAttribute(method);

            if (mimeTypeAttribute != null)
            {
                operation.MimeType = mimeTypeAttribute.MimeType;
            }
            this.metadata.ServiceOperations.Add(method.Name, operation);
        }
Пример #19
0
 public bool TryResolveResourceSet(string name, out ResourceSet resourceSet)
 {
     WebUtil.CheckStringArgumentNullOrEmpty(name, "name");
     return(this.EntitySets.TryGetValue(name, out resourceSet));
 }
Пример #20
0
 protected abstract IQueryable GetResourceContainerInstance(ResourceSet resourceContainer);
Пример #21
0
 private bool TryFindAnyContainerForType(ResourceType type, out ResourceSet container)
 {
     foreach (ResourceSet set in this.EntitySets.Values)
     {
         if (set.ResourceType.IsAssignableFrom(type))
         {
             container = set;
             return true;
         }
     }
     container = null;
     return false;
 }
Пример #22
0
        /// <summary>Checks that the specified <paramref name="method"/> has a correct signature.</summary>
        /// <param name="type">Service type.</param>
        /// <param name="method">Method to check.</param>
        /// <param name="container">Container associated with the interceptor.</param>
        private static void CheckQueryInterceptorSignature(Type type, MethodInfo method, ResourceSet container)
        {
            Debug.Assert(type != null, "type != null");
            Debug.Assert(method != null, "method != null");
            Debug.Assert(container != null, "container != null");

            ParameterInfo[] parameters = method.GetParameters();
            if (parameters.Length != 0)
            {
                throw new InvalidOperationException(Strings.DataService_QueryInterceptorIncorrectParameterCount(method.Name, type.FullName, parameters.Length));
            }

            Type lambdaType = typeof(Func<,>).MakeGenericType(container.ResourceType.InstanceType, typeof(bool));
            Type expectedReturnType = typeof(Expression<>).MakeGenericType(lambdaType);
            Type returnType = method.ReturnType;
            if (returnType == typeof(void))
            {
                throw new InvalidOperationException(Strings.DataService_AuthorizationMethodVoid(method.Name, type.FullName, expectedReturnType));
            }
            else if (!expectedReturnType.IsAssignableFrom(returnType))
            {
                Type nullableLambdaType = typeof(Func<,>).MakeGenericType(container.ResourceType.InstanceType, typeof(bool?));
                if (!(typeof(Expression<>).MakeGenericType(nullableLambdaType).IsAssignableFrom(returnType)))
                {
                    throw new InvalidOperationException(
                        Strings.DataService_AuthorizationReturnTypeNotAssignable(method.Name, type.FullName, returnType.FullName, expectedReturnType.FullName));
                }
            }
        }
Пример #23
0
 public bool TryResolveResourceSet(string name, out ResourceSet resourceSet)
 {
     WebUtil.CheckStringArgumentNullOrEmpty(name, "name");
     return this.EntitySets.TryGetValue(name, out resourceSet);
 }
Пример #24
0
        /// <summary>Adds a resource set to the metadata definition.</summary>
        /// <param name="name">The name of the resource set to add.</param>
        /// <param name="entityType">The type of entities in the resource set.</param>
        /// <returns>The newly created resource set.</returns>
        public ResourceSet AddResourceSet(string name, ResourceType entityType)
        {
            if (entityType.ResourceTypeKind != ResourceTypeKind.EntityType)
            {
                throw new ArgumentException("The resource type specified as the base type of a resource set is not an entity type.");
            }

            ResourceSet resourceSet = new ResourceSet(name, entityType);
            entityType.GetAnnotation().ResourceSet = resourceSet;
            this.resourceSets.Add(name, resourceSet);
            return resourceSet;
        }
Пример #25
0
 /// <summary>Given the specified name, tries to find a resource set.</summary>
 /// <param name="name">Name of the resource set to resolve.</param>
 /// <param name="resourceSet">Returns the resolved resource set, null if no resource set for the given name was found.</param>
 /// <returns>True if resource set with the given name was found, false otherwise.</returns>
 public bool TryResolveResourceSet(string name, out ResourceSet resourceSet)
 {
     Debug.Assert(!string.IsNullOrEmpty(name), "!string.IsNullOrEmpty(name)");
     return(this.EntitySets.TryGetValue(name, out resourceSet));
 }
Пример #26
0
        /// <summary>
        /// Gets the ResourceAssociationSet instance when given the source association end.
        /// </summary>
        /// <param name="resourceSet">Resource set of the source association end.</param>
        /// <param name="resourceType">Resource type of the source association end.</param>
        /// <param name="resourceProperty">Resource property of the source association end.</param>
        /// <returns>ResourceAssociationSet instance.</returns>
        /// <remarks>This method returns a ResourceAssociationSet representing a reference which is specified
        /// by the <paramref name="resourceProperty"/> on the <paramref name="resourceType"/> for instances in the <paramref name="resourceSet"/>.</remarks>
        public ResourceAssociationSet GetResourceAssociationSet(ResourceSet resourceSet, ResourceType resourceType, ResourceProperty resourceProperty)
        {
            // We have the resource association set precreated on the property annotation, so no need to compute anything in here
            ResourceAssociationSet resourceAssociationSet = resourceProperty.GetAnnotation().ResourceAssociationSet;

            // Just few verification to show what is expected of the returned resource association set.
            Debug.Assert(resourceAssociationSet.End1.ResourceSet == resourceSet, "The precreated resource association set doesn't match the specified resource set.");
            Debug.Assert(resourceAssociationSet.End1.ResourceType == resourceType, "The precreated resource association set doesn't match the specified resource type.");
            Debug.Assert(resourceAssociationSet.End1.ResourceProperty == resourceProperty, "The precreated resource association set doesn't match its resource property.");

            return resourceAssociationSet;
        }
Пример #27
0
 /// <summary>
 /// Returns the IQueryable that represents the container.
 /// </summary>
 /// <param name="container">resource set representing the entity set.</param>
 /// <returns>
 /// An IQueryable that represents the container; null if there is 
 /// no container for the specified name.
 /// </returns>
 public IQueryable GetQueryRootForResourceSet(ResourceSet container)
 {
     Debug.Assert(container != null, "resourceContainer != null");
     return this.GetResourceContainerInstance(container);
 }
Пример #28
0
        /// <summary>Helper method to add a reference property.</summary>
        /// <param name="resourceType">The resource type to add the property to.</param>
        /// <param name="name">The name of the property to add.</param>
        /// <param name="targetResourceSet">The resource set the resource reference property points to.</param>
        /// <param name="resourceSetReference">true if the property should be a resource set reference, false if it should be resource reference.</param>
        private void AddReferenceProperty(ResourceType resourceType, string name, ResourceSet targetResourceSet, bool resourceSetReference)
        {
            ResourceProperty property = new ResourceProperty(
                name,
                resourceSetReference ? ResourcePropertyKind.ResourceSetReference : ResourcePropertyKind.ResourceReference,
                targetResourceSet.ResourceType);
            property.CanReflectOnInstanceTypeProperty = false;
            resourceType.AddProperty(property);

            // We don't support type inheritance so the property can only point to the base resource type of the target resource set
            // We also don't support MEST, that is having two resource sets with the same resource type, so we can determine
            //   the resource set from the resource type. That also means that the property can never point to different resource sets
            //   so we can precreate the ResourceAssociationSet for this property right here as we have all the information.
            property.CustomState = new ResourcePropertyAnnotation()
            {
                ResourceAssociationSet = new ResourceAssociationSet(
                    resourceType.Name + "_" + name + "_" + targetResourceSet.Name,
                    new ResourceAssociationSetEnd(resourceType.GetAnnotation().ResourceSet, resourceType, property),
                    new ResourceAssociationSetEnd(targetResourceSet, targetResourceSet.ResourceType, null))
            };
        }
Пример #29
0
 /// <summary>
 /// Creates the object query for the given resource set and returns it
 /// </summary>
 /// <param name="resourceContainer">resource set for which IQueryable instance needs to be created</param>
 /// <returns>returns the IQueryable instance for the given resource set</returns>
 protected abstract IQueryable GetResourceContainerInstance(ResourceSet resourceContainer);
Пример #30
0
        private void PopulateMetadataFromCollection(MongoContext context, string collectionName, ResourceSet resourceSet)
        {
            var collection = context.Database.GetCollection<BsonDocument>(collectionName);
            const string naturalSort = "$natural";
            var sortBuilder = Builders<BsonDocument>.Sort;
            var sort = this.Configuration.FetchPosition == MongoConfiguration.FetchPosition.End
                                ? sortBuilder.Descending(naturalSort)
                                : sortBuilder.Ascending(naturalSort);
            var documents = collection.Find(new BsonDocument()).Sort(sort).ToListAsync().GetAwaiter().GetResult();
            int rowCount = 0;
            foreach (var document in documents)
            {
                if (resourceSet == null)
                {
                    resourceSet = AddResourceSet(context, collectionName, document);
                }
                else
                {
                    UpdateResourceSet(context, resourceSet, document);
                }

                ++rowCount;
                if (this.Configuration.PrefetchRows >= 0 && rowCount >= this.Configuration.PrefetchRows)
                    break;
            }
        }
Пример #31
0
 private static void CheckQueryInterceptorSignature(Type type, MethodInfo method, ResourceSet container)
 {
     ParameterInfo[] parameters = method.GetParameters();
     if (parameters.Length != 0)
     {
         throw new InvalidOperationException(System.Data.Services.Strings.DataService_QueryInterceptorIncorrectParameterCount(method.Name, type.FullName, parameters.Length));
     }
     Type type2 = typeof(Func<,>).MakeGenericType(new Type[] { container.ResourceType.InstanceType, typeof(bool) });
     Type type3 = typeof(Expression<>).MakeGenericType(new Type[] { type2 });
     Type returnType = method.ReturnType;
     if (returnType == typeof(void))
     {
         throw new InvalidOperationException(System.Data.Services.Strings.DataService_AuthorizationMethodVoid(method.Name, type.FullName, type3));
     }
     if (!type3.IsAssignableFrom(returnType))
     {
         Type type5 = typeof(Func<,>).MakeGenericType(new Type[] { container.ResourceType.InstanceType, typeof(bool?) });
         if (!typeof(Expression<>).MakeGenericType(new Type[] { type5 }).IsAssignableFrom(returnType))
         {
             throw new InvalidOperationException(System.Data.Services.Strings.DataService_AuthorizationReturnTypeNotAssignable(method.Name, type.FullName, returnType.FullName, type3.FullName));
         }
     }
 }
Пример #32
0
 public IQueryable GetQueryRootForResourceSet(ResourceSet container)
 {
     WebUtil.CheckArgumentNull <ResourceSet>(container, "container");
     return(this.GetResourceContainerInstance(container));
 }
Пример #33
0
 /// <summary>Adds a resource set reference property to the specified <paramref name="resourceType"/>.</summary>
 /// <param name="resourceType">The resource type to add the property to.</param>
 /// <param name="name">The name of the property to add.</param>
 /// <param name="targetResourceSet">The resource set the resource reference property points to.</param>
 /// <remarks>This creates a property pointing to multiple resources in the target resource set.</remarks>
 public void AddResourceSetReferenceProperty(ResourceType resourceType, string name, ResourceSet targetResourceSet)
 {
     AddReferenceProperty(resourceType, name, targetResourceSet, true);
 }
Пример #34
0
 internal int GetResourceSetPageSize(ResourceSet container)
 {
     int defaultPageSize;
     if (!this.pageSizes.TryGetValue(container.Name, out defaultPageSize))
     {
         defaultPageSize = this.defaultPageSize;
     }
     return defaultPageSize;
 }
Пример #35
0
 /// <summary>Returnes a resource set specified by its name.</summary>
 /// <param name="name">The name of the resource set find.</param>
 /// <param name="resourceSet">The resource set instance found.</param>
 /// <returns>true if the resource set was found or false otherwise.</returns>
 /// <remarks>The implementation of this method should be very fast as it will get called for almost every request. It should also be fast
 /// for non-existing resource sets to avoid possible DoS attacks on the service.</remarks>
 public bool TryResolveResourceSet(string name, out ResourceSet resourceSet)
 {
     return this.resourceSets.TryGetValue(name, out resourceSet); ;
 }
Пример #36
0
 internal EntitySetRights GetResourceSetRights(ResourceSet container)
 {
     EntitySetRights rightsForUnspecifiedResourceContainer;
     if (!this.resourceRights.TryGetValue(container.Name, out rightsForUnspecifiedResourceContainer))
     {
         rightsForUnspecifiedResourceContainer = this.rightsForUnspecifiedResourceContainer;
     }
     return rightsForUnspecifiedResourceContainer;
 }
 /// <summary>Returns a query which can be used to retrive resource from the specified resource set.</summary>
 /// <param name="resourceSet">The resource set to get the quqeyr for.</param>
 /// <returns>An <see cref="IQueryable"/> which will be used to get resources from the specified resource set.</returns>
 /// <remarks>The data service will use the LINQ to build the actual query required for the resource set. It's up to this provider
 /// to return an <see cref="IQueryable"/> which can handle such queries. If the resource set is not recognized by the provider it should return null.</remarks>
 public virtual IQueryable GetQueryRootForResourceSet(ResourceSet resourceSet)
 {
     return DSPLinqQueryProvider.CreateQuery(_dataSource.GetQueryable(resourceSet.Name), _expressionVisitor);
 }
Пример #38
0
 internal MethodInfo[] GetWriteAuthorizationMethods(ResourceSet resourceSet)
 {
     List<MethodInfo> list;
     if (this.writeAuthorizationMethods.TryGetValue(resourceSet.Name, out list))
     {
         return list.ToArray();
     }
     return null;
 }
Пример #39
0
 private void UpdateResourceSet(MongoContext context, ResourceSet resourceSet, BsonDocument document)
 {
     foreach (var element in document.Elements)
     {
         RegisterDocumentProperty(context, resourceSet.ResourceType, element);
     }
 }
Пример #40
0
 public IQueryable GetQueryRootForResourceSet(ResourceSet container)
 {
     WebUtil.CheckArgumentNull<ResourceSet>(container, "container");
     return this.GetResourceContainerInstance(container);
 }
Пример #41
0
 internal IEdmEntitySet FindEntitySet(ResourceSet resourceSet)
 {
     string name = resourceSet.EntityContainerName ?? this.metadataProvider.ContainerName;
     return this.FindExistingEntityContainer(name).FindEntitySet(MetadataProviderUtils.GetEntitySetName(resourceSet));
 }
Пример #42
0
 public ServiceOperation(string name, ServiceOperationResultKind resultKind, ResourceType resultType, ResourceSet resultSet, string method, IEnumerable <ServiceOperationParameter> parameters)
 {
     throw new NotImplementedException();
 }