public void AddResourceProperty(string propertyName, string addToResourceType, string resourcePropertyKind, string propertyType, string containerName, bool isClrProperty) { DSP.ResourceProperty newProperty = null; DSP.ResourceType resourceType = GetResourceType(addToResourceType); DSP.ResourceSet assocResourceSet = GetResourceSet(containerName); if (assocResourceSet != null) { DSP.ResourceType assocResourceType = GetResourceType(propertyType); newProperty = new DSP.ResourceProperty( propertyName, ConvertResourcePropertyKind(resourcePropertyKind), assocResourceType); } else { DSP.ResourceType assocResourceType = GetResourceType(propertyType); if (assocResourceType == null) { Type t = Type.GetType(propertyType); assocResourceType = DSP.ResourceType.GetPrimitiveResourceType(t); } newProperty = new DSP.ResourceProperty( propertyName, ConvertResourcePropertyKind(resourcePropertyKind), assocResourceType); } newProperty.CanReflectOnInstanceTypeProperty = isClrProperty; resourceType.AddProperty(newProperty); }
public void ServiceActionParameterInvalidCasesTest() { ResourceType complexType = new ResourceType(typeof(object), ResourceTypeKind.ComplexType, null, "foo", "Address", false); ResourceType entityType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "foo", "Order", false); ResourceSet entitySet = new ResourceSet("Set", entityType); ResourceType collectionOfPrimitive = ResourceType.GetCollectionResourceType(ResourceType.GetPrimitiveResourceType(typeof(int))); ResourceType collectionOfComplex = ResourceType.GetCollectionResourceType(complexType); ResourceType collectionType = ResourceType.GetEntityCollectionResourceType(entityType); var parameterTypes = ResourceTypeUtils.GetPrimitiveResourceTypes() .Concat(new ResourceType[] { complexType, entityType, collectionOfPrimitive, collectionOfComplex, collectionType }); AstoriaTestNS.TestUtil.RunCombinations(parameterTypes, (parameterType) => { Exception e = AstoriaTestNS.TestUtil.RunCatching(() => new ServiceActionParameter("p", parameterType)); if (parameterType != ResourceType.GetPrimitiveResourceType(typeof(System.IO.Stream))) { Assert.IsNull(e, "Service op parameter should have succeeded."); } else { ExceptionUtils.IsExpectedException<ArgumentException>(e, "The service operation parameter 'p' of type 'Edm.Stream' is not supported.\r\nParameter name: parameterType"); } }); }
public void Init() { this.baseType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "Fake.NS", "BaseType", false) {CanReflectOnInstanceType = false}; this.baseType.AddProperty(new ResourceProperty("Id", ResourcePropertyKind.Key | ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(int))) { CanReflectOnInstanceTypeProperty = false }); this.baseType.SetReadOnly(); this.entityType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, this.baseType, "Fake.NS", "Type", false) {CanReflectOnInstanceType = false}; this.entityType.SetReadOnly(); this.derivedType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, this.entityType, "Fake.NS", "DerivedType", false) { CanReflectOnInstanceType = false }; this.derivedType.SetReadOnly(); var resourceSet = new ResourceSet("Set", this.entityType); resourceSet.SetReadOnly(); this.resourceSetWrapper = ResourceSetWrapper.CreateForTests(resourceSet); this.action = new ServiceAction("Fake", ResourceType.GetPrimitiveResourceType(typeof(int)), OperationParameterBindingKind.Sometimes, new[] {new ServiceActionParameter("p1", this.entityType)}, null); this.action.SetReadOnly(); this.actionWrapper = new OperationWrapper(action); this.derivedAction = new ServiceAction("Fake", ResourceType.GetPrimitiveResourceType(typeof(int)), OperationParameterBindingKind.Sometimes, new[] { new ServiceActionParameter("p1", this.derivedType) }, null); this.derivedAction.SetReadOnly(); this.derivedActionWrapper = new OperationWrapper(derivedAction); this.testSubject = new SelectedOperationsCache(); }
public void DataServiceProviderWrapperShouldFailOnMultipleActionsWithSameNameAndBindingType() { var entityType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "Fake.NS", "Type", false) { CanReflectOnInstanceType = false }; entityType.AddProperty(new ResourceProperty("Id", ResourcePropertyKind.Key | ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(int))) {CanReflectOnInstanceTypeProperty = false}); entityType.SetReadOnly(); var resourceSet = new ResourceSet("MyEntitySet", entityType); resourceSet.SetReadOnly(); ResourceType stringType = ResourceType.GetPrimitiveResourceType(typeof(string)); var duplicateAction1 = new ServiceAction("Duplicate", stringType, OperationParameterBindingKind.Always, new[] { new ServiceActionParameter("p1", entityType), new ServiceActionParameter("p2", stringType) }, null); duplicateAction1.SetReadOnly(); var duplicateAction2 = new ServiceAction("Duplicate", ResourceType.GetPrimitiveResourceType(typeof(int)), OperationParameterBindingKind.Sometimes, new[] { new ServiceActionParameter("p1", entityType) }, null); duplicateAction2.SetReadOnly(); var actionProvider = new TestActionProvider { GetServiceActionsCallback = ctx => new[] { duplicateAction1, duplicateAction2 } }; var providerWrapper = CreateProviderWrapper(actionProvider, p => p.AddResourceSet(resourceSet)); Action getVisibleOperations = () => providerWrapper.GetVisibleOperations().ToList(); getVisibleOperations.ShouldThrow<DataServiceException>() .WithMessage(ErrorStrings.DataServiceActionProviderWrapper_DuplicateAction("Duplicate")) .And.StatusCode.Should().Be(500); }
public void RemoveResourceSet(string name) { DSP.ResourceSet rc = GetResourceSet(name); if (rc != null) { containers.Remove(rc); } }
public EmptyOpenTypesContext() { this.resourceType = new ResourceType(typeof(StubTypeWithId), ResourceTypeKind.EntityType, null, "OpenTypes", "Entity", false); this.resourceType.CanReflectOnInstanceType = true; this.resourceType.IsOpenType = true; var idProperty = new ResourceProperty("Id", ResourcePropertyKind.Primitive | ResourcePropertyKind.Key, ResourceType.GetPrimitiveResourceType(typeof(int))); idProperty.CanReflectOnInstanceTypeProperty = true; this.resourceType.AddProperty(idProperty); this.resourceSet = new ResourceSet("Entities", this.resourceType); this.resourceSet.SetReadOnly(); }
} // GetResourceAssociationSet public bool TryResolveResourceSet(string name, out DSP.ResourceSet resourceSet) { if (this.ResourceSets != null) { resourceSet = this.ResourceSets.Where <DSP.ResourceSet>(c => c.Name == name).FirstOrDefault <DSP.ResourceSet>(); return(resourceSet != null); } resourceSet = null; return(false); } // TryResolveResourceSet
/// <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> private ResourceSetWrapper(ResourceSet resourceSet) { Debug.Assert(resourceSet != null, "resourceSet != null"); if (!resourceSet.IsReadOnly) { throw new DataServiceException(500, Strings.DataServiceProviderWrapper_ResourceContainerNotReadonly(resourceSet.Name)); } this.resourceSet = resourceSet; this.resourcePropertyCache = new Dictionary<ResourceType, ResourcePropertyCache>(ReferenceEqualityComparer<ResourceType>.Instance); }
public void MetadataProviderModelShouldGoDirectlyToProviderWhenLookingUpAnEntitySetFromThePath() { var metadataProvider = new DataServiceProviderSimulator(); var resourceSet = new ResourceSet("Some.Really.Var1.Name.<>+-.Something", CreateResourceTypeWithKeyProperties("Id")); resourceSet.SetReadOnly(); metadataProvider.AddResourceSet(resourceSet); var model = CreateMetadataProviderEdmModel(metadataProvider); var result = model.FindDeclaredEntitySet(resourceSet.Name); result.Should().NotBeNull(); result.Name.Should().Be(resourceSet.Name); }
/// <summary> /// Returns the list of QueryInterceptors for the given resource set /// </summary> /// <param name="resourceSet">resource set instance</param> /// <returns>List of QueryInterceptors for the resource set, null if there is none defined for the resource set.</returns> internal MethodInfo[] GetReadAuthorizationMethods(ResourceSet resourceSet) { Debug.Assert(resourceSet != null, "resourceSet != null"); List<MethodInfo> methods; if (this.readAuthorizationMethods.TryGetValue(resourceSet.Name, out methods)) { return methods.ToArray(); } return null; }
/// <summary> /// Gets the ResourceTypes associated with the particular ResourceSet /// </summary> /// <param name="set">Set to find the types</param> /// <returns>A List of ResourceTypes associated with the set</returns> public IList<ResourceType> GetResourceTypesOfResourceSet(ResourceSet set) { List<ResourceType> resourceTypes = new List<ResourceType>(); foreach (ResourceType rt in this.ResourceTypes) { if (this.IsKindOf(set.ResourceType, rt)) { resourceTypes.Add(rt); } } return resourceTypes; }
public void AddResourceSet(string name, string typeName) { DSP.ResourceType resourceType = GetResourceType(typeName); if (resourceType != null) { resourceType.SetReadOnly(); SetDerivedReadOnly(resourceType); DSP.ResourceSet newResourceSet = new DSP.ResourceSet(name, resourceType); newResourceSet.SetReadOnly(); addedContainers.Add(newResourceSet); } }
public void PropertiesValidationTest() { ResourceType entityType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "TestNS", "Customer", false); ResourceSet resourceSet = new ResourceSet("Customers", entityType); Assert.IsFalse(resourceSet.IsReadOnly, "ResourceSet should be created writable."); Assert.IsNull(resourceSet.CustomState, "No custom state should be present after creation."); Assert.AreEqual("Customers", resourceSet.Name, "The name of the resource set was not set correctly."); Assert.IsTrue(object.ReferenceEquals(entityType, resourceSet.ResourceType), "The element type of the resource set was not set correctly."); Assert.IsFalse(resourceSet.UseMetadataKeyOrder, "The default value for UseMetadataKeyOrder should be false."); resourceSet.UseMetadataKeyOrder = true; Assert.IsTrue(resourceSet.UseMetadataKeyOrder, "New value for UseMetadataKeyOrder was not set correctly."); }
public void InvalidCasesTest() { ResourceProperty id = new ResourceProperty("ID", ResourcePropertyKind.Primitive | ResourcePropertyKind.Key, ResourceType.GetPrimitiveResourceType(typeof(int))) { CanReflectOnInstanceTypeProperty = false }; ResourceType customerType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "Foo", "CustomerType", false); customerType.AddProperty(id); ResourceType orderType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "Foo", "OrderType", false); orderType.AddProperty(id); ResourceProperty customerOrders = new ResourceProperty("Orders", ResourcePropertyKind.ResourceSetReference, orderType); ResourceProperty orderCustomer = new ResourceProperty("Customer", ResourcePropertyKind.ResourceReference, customerType); customerType.AddProperty(customerOrders); orderType.AddProperty(orderCustomer); customerOrders.CanReflectOnInstanceTypeProperty = false; orderCustomer.CanReflectOnInstanceTypeProperty = false; customerType.SetReadOnly(); orderType.SetReadOnly(); ResourceSet customerSet = new ResourceSet("Customers", customerType); ResourceSet orderSet = new ResourceSet("Orders", orderType); ResourceAssociationSetEnd end1 = new ResourceAssociationSetEnd(customerSet, customerType, null); ResourceAssociationSetEnd end2 = new ResourceAssociationSetEnd(orderSet, orderType, null); ExceptionUtils.CheckInvalidConstructorParameters( typeof(ResourceAssociationSet), "Value cannot be null or empty.\r\nParameter name: name", null, end1, end2); ExceptionUtils.CheckInvalidConstructorParameters( typeof(ResourceAssociationSet), "Value cannot be null or empty.\r\nParameter name: name", string.Empty, end1, end2); ExceptionUtils.CheckInvalidConstructorParameters( typeof(ResourceAssociationSet), "Value cannot be null.\r\nParameter name: end1", "Customer_Order", null, end2); ExceptionUtils.CheckInvalidConstructorParameters( typeof(ResourceAssociationSet), "Value cannot be null.\r\nParameter name: end2", "Customer_Order", end1, null); ExceptionUtils.CheckInvalidConstructorParameters( typeof(ResourceAssociationSet), "The ResourceProperty of the ResourceAssociationEnds cannot both be null.", "Customer_Order", end1, end2); }
public void InvalidCasesTest() { ResourceProperty id = new ResourceProperty("ID", ResourcePropertyKind.Primitive | ResourcePropertyKind.Key, ResourceType.GetPrimitiveResourceType(typeof(int))) { CanReflectOnInstanceTypeProperty = false }; ResourceType customerType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "Foo", "CustomerType", false); customerType.AddProperty(id); ResourceType orderType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "Foo", "OrderType", false); orderType.AddProperty(id); ResourceProperty customerOrders = new ResourceProperty("Orders", ResourcePropertyKind.ResourceSetReference, orderType); ResourceProperty orderCustomer = new ResourceProperty("Customer", ResourcePropertyKind.ResourceReference, customerType); customerType.AddProperty(customerOrders); orderType.AddProperty(orderCustomer); customerOrders.CanReflectOnInstanceTypeProperty = false; orderCustomer.CanReflectOnInstanceTypeProperty = false; customerType.SetReadOnly(); orderType.SetReadOnly(); ResourceSet customerSet = new ResourceSet("Customers", customerType); ResourceSet orderSet = new ResourceSet("Orders", orderType); ExceptionUtils.CheckInvalidConstructorParameters( typeof(ResourceAssociationSetEnd), "Value cannot be null.\r\nParameter name: resourceSet", null, customerType, customerOrders); ExceptionUtils.CheckInvalidConstructorParameters( typeof(ResourceAssociationSetEnd), "Value cannot be null.\r\nParameter name: resourceType", customerSet, null, customerOrders); ExceptionUtils.CheckInvalidConstructorParameters( typeof(ResourceAssociationSetEnd), "The resourceProperty parameter must be a navigation property on the resource type specified by the resourceType parameter.", customerSet, customerType, id); ExceptionUtils.CheckInvalidConstructorParameters( typeof(ResourceAssociationSetEnd), "The resourceProperty parameter must be a navigation property on the resource type specified by the resourceType parameter.", customerSet, customerType, orderCustomer); ExceptionUtils.CheckInvalidConstructorParameters( typeof(ResourceAssociationSetEnd), "The resourceType parameter must be a type that is assignable to the resource set specified by the resourceSet parameter.", customerSet, orderType, orderCustomer); }
} // GetOpenPropertyValue public IQueryable GetQueryRootForResourceSet(DSP.ResourceSet container) { List <RowEntityType> list = EntitySetDictionary[container.Name]; IQueryable <RowEntityType> realQueryable = list.AsQueryable(); NonClrQueryProvider provider = new NonClrQueryProvider(realQueryable.Provider, this); NonClrQueryable <RowEntityType> queryable = new NonClrQueryable <RowEntityType>(realQueryable, provider); if (container.ResourceType.InstanceType == typeof(RowEntityType)) { return(queryable); } else { MethodInfo castMethod = typeof(Queryable).GetMethod("Cast", BindingFlags.Static | BindingFlags.Public); castMethod = castMethod.MakeGenericMethod(container.ResourceType.InstanceType); object newQueryable = castMethod.Invoke(null, new object[] { queryable }); return(newQueryable as IQueryable); } } // GetQueryRootForResourceSet
/// <summary>Creates a new instance of the <see cref="T:Microsoft.OData.Service.Providers.ResourceAssociationSetEnd" /> class.</summary> /// <param name="resourceSet">The resource set to which the <see cref="T:Microsoft.OData.Service.Providers.ResourceAssociationSetEnd" /> end belongs.</param> /// <param name="resourceType">The resource type to which the <see cref="T:Microsoft.OData.Service.Providers.ResourceAssociationSetEnd" /> end belongs.</param> /// <param name="resourceProperty">The resource property that returns the <see cref="T:Microsoft.OData.Service.Providers.ResourceAssociationSetEnd" /> 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; }
public void ResourceTypeMustBeDeclaringType_2() { ResourceType baseCustomerType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "Test", "Employee", true /*isAbstract*/); ResourceType customerType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, baseCustomerType, "Test", "Customer", false /*isAbstract*/); ResourceSet customerSet = new ResourceSet("CustomerSet", customerType); ResourceType orderType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "Test", "Employee", false /*isAbstract*/); ResourceProperty orderProperty = new ResourceProperty("Orders", ResourcePropertyKind.ResourceSetReference, orderType); baseCustomerType.AddProperty(orderProperty); try { new ResourceAssociationSetEnd(customerSet, customerType, orderProperty); Assert.Fail("Creating resource association set end should never have succeeded"); } catch (ArgumentException e) { Assert.AreEqual( DataServicesResourceUtil.GetString("ResourceAssociationSetEnd_ResourceTypeMustBeTheDeclaringType", customerType.FullName, orderProperty.Name), e.Message); } }
/// <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()); } }
public void Initialize() { this.host = new DataServiceHost2Simulator(); var context = new DataServiceOperationContext(this.host); this.dataServiceSimulator = new DataServiceSimulator { OperationContext = context }; var providerSimulator = new DataServiceProviderSimulator(); DataServiceStaticConfiguration staticConfiguration = new DataServiceStaticConfiguration(this.dataServiceSimulator.Instance.GetType(), providerSimulator); IDataServiceProviderBehavior providerBehavior = DataServiceProviderBehavior.CustomDataServiceProviderBehavior; var resourceType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "SelectTestNamespace", "Fake", false) { CanReflectOnInstanceType = false, IsOpenType = true }; resourceType.AddProperty(new ResourceProperty("Id", ResourcePropertyKind.Key | ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(int))) { CanReflectOnInstanceTypeProperty = false }); var resourceSet = new ResourceSet("FakeSet", resourceType); resourceSet.SetReadOnly(); providerSimulator.AddResourceSet(resourceSet); var configuration = new DataServiceConfiguration(providerSimulator); configuration.SetEntitySetAccessRule("*", EntitySetRights.All); var provider = new DataServiceProviderWrapper( new DataServiceCacheItem( configuration, staticConfiguration), providerSimulator, providerSimulator, this.dataServiceSimulator, false); this.dataServiceSimulator.ProcessingPipeline = new DataServiceProcessingPipeline(); this.dataServiceSimulator.Provider = provider; provider.ProviderBehavior = providerBehavior; this.dataServiceSimulator.Configuration = new DataServiceConfiguration(providerSimulator); this.dataServiceSimulator.Configuration.DataServiceBehavior.MaxProtocolVersion = ODataProtocolVersion.V4; this.responseMessageSimulator = new ODataResponseMessageSimulator(); }
/// <summary> /// Initializes a new <see cref="ServiceAction"/> instance. /// </summary> /// <param name="name">Name of the action.</param> /// <param name="returnType">Return type of the action.</param> /// <param name="resultSet">Result resource set of the action if the action returns an entity or a collection of entity; null otherwise.</param> /// <param name="resultSetPathExpression">Path expression to calculate the result resource set of the function if the action returns an entity or a collection of entity; null otherwise.</param> /// <param name="parameters">In-order parameters for this action; the first parameter is the binding parameter.</param> /// <param name="operationParameterBindingKind">the kind of the operation parameter binding (Never, Sometimes, Always).</param> /// <remarks>The value of <paramref name="operationParameterBindingKind"/> must be set to <see cref="OperationParameterBindingKind.Sometimes"/> or /// <see cref="OperationParameterBindingKind.Always"/> if the first parameter in <paramref name="parameters"/> is the binding parameter /// or <see cref="OperationParameterBindingKind.Never"/> if the first parameter is not a binding parameter. If the value of <paramref name="operationParameterBindingKind"/> /// is set to <see cref="OperationParameterBindingKind.Always"/> then the IDataServiceActionProvider.AdvertiseServiceAction method will not be called for the action /// and the action will be always advertised by the default convention.</remarks> private ServiceAction(string name, ResourceType returnType, ResourceSet resultSet, ResourceSetPathExpression resultSetPathExpression, IEnumerable<ServiceActionParameter> parameters, OperationParameterBindingKind operationParameterBindingKind) : base( name, Operation.GetResultKindFromReturnType(returnType, isComposable: false), returnType, resultSet, resultSetPathExpression, XmlConstants.HttpMethodPost, parameters, operationParameterBindingKind, OperationKind.Action) { Debug.Assert(this.OperationParameters != null, "this.OperationParameters != null"); if (this.OperationParameters == OperationParameter.EmptyOperationParameterCollection) { this.parameters = ServiceActionParameter.EmptyServiceActionParameterCollection; } else { this.parameters = new ReadOnlyCollection<ServiceActionParameter>(this.OperationParameters.Cast<ServiceActionParameter>().ToList()); } }
/// <summary>Gets the page size per entity set</summary> /// <param name="container">Entity set for which to get the page size</param> /// <returns>Page size for the <paramref name="container"/></returns> internal int GetResourceSetPageSize(ResourceSet container) { Debug.Assert(container != null, "container != null"); Debug.Assert(this.pageSizes != null, "this.pageSizes != null"); int pageSize; if (!this.pageSizes.TryGetValue(container.Name, out pageSize)) { pageSize = this.defaultPageSize; } return pageSize; }
/// <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);
/// <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 virtual bool TryResolveResourceSet(string name, out ResourceSet resourceSet) { return this.resourceSets.TryGetValue(name, out resourceSet); ; }
/// <summary>Gets the effective rights on the specified container.</summary> /// <param name="container">Container to get rights for.</param> /// <returns>The effective rights as per this configuration.</returns> internal EntitySetRights GetResourceSetRights(ResourceSet container) { Debug.Assert(container != null, "container != null"); Debug.Assert(this.resourceRights != null, "this.resourceRights != null"); EntitySetRights result; if (!this.resourceRights.TryGetValue(container.Name, out result)) { result = this.rightsForUnspecifiedResourceContainer; } return result; }
/// <summary> /// Returns 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> /// <returns>Service operation corresponding to give <paramref name="method"/>.</returns> private ServiceOperation GetServiceOperationForMethod(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"); bool hasSingleResult = BaseServiceProvider.MethodHasSingleResult(method); ServiceOperationResultKind resultKind; ResourceType resourceType = null; if (method.ReturnType == typeof(void)) { resultKind = ServiceOperationResultKind.Void; } 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; if (WebUtil.IsPrimitiveType(method.ReturnType)) { resultKind = ServiceOperationResultKind.DirectValue; resultType = method.ReturnType; resourceType = PrimitiveResourceTypeMap.TypeMap.GetPrimitive(resultType); } else { Type queryableElement = BaseServiceProvider.GetIQueryableElement(method.ReturnType); if (queryableElement != null) { resultKind = hasSingleResult ? ServiceOperationResultKind.QueryWithSingleResult : ServiceOperationResultKind.QueryWithMultipleResults; resultType = queryableElement; } else { Type enumerableElement = BaseServiceProvider.GetIEnumerableElement(method.ReturnType); if (enumerableElement != null) { resultKind = ServiceOperationResultKind.Enumeration; resultType = enumerableElement; } else { resultType = method.ReturnType; resultKind = ServiceOperationResultKind.DirectValue; } } Debug.Assert(resultType != null, "resultType != null"); resourceType = PrimitiveResourceTypeMap.TypeMap.GetPrimitive(resultType); if (resourceType == null) { resourceType = this.ResolveResourceType(resultType); } } if (resourceType == null) { throw new InvalidOperationException(Strings.BaseServiceProvider_UnsupportedReturnType(method, method.ReturnType)); } if (resultKind == ServiceOperationResultKind.Enumeration && hasSingleResult) { throw new InvalidOperationException(Strings.BaseServiceProvider_IEnumerableAlwaysMultiple(type, method)); } } 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 = PrimitiveResourceTypeMap.TypeMap.GetPrimitive(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 resourceSet = null; if (resourceType != null && resourceType.ResourceTypeKind == ResourceTypeKind.EntityType) { resourceSet = this.ResolveResourceSet(resourceType, method); if (resourceSet == null) { throw new InvalidOperationException( Strings.BaseServiceProvider_ServiceOperationMissingSingleEntitySet(method, resourceType.FullName)); } } ServiceOperation operation = new ServiceOperation(method.Name, resultKind, resourceType, resourceSet, protocolMethod, parameters); operation.CustomState = method; MimeTypeAttribute attribute = BaseServiceProvider.GetMimeTypeAttribute(method); if (attribute != null) { operation.MimeType = attribute.MimeType; } return(operation); }
public void GetQueryRootForResourceSet(DSP.ResourceSet resourceSet) { Add("GetQueryRootForResourceSet", Serialize(resourceSet)); }
/// <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="targetResourceType">The resource type the resource set 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, ResourceType targetResourceType, bool resourceSetReference) { PropertyInfo propertyInfo = resourceType.InstanceType.GetProperty(name); targetResourceType = targetResourceType ?? targetResourceSet.ResourceType; ResourceProperty property = AddResourceProperty( resourceType, name, resourceSetReference ? ResourcePropertyKind.ResourceSetReference : ResourcePropertyKind.ResourceReference, targetResourceType, propertyInfo); // We 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.GetAnnotation().ResourceAssociationSet = () => { ResourceSet sourceResourceSet = resourceType.GetAnnotation().ResourceSet; ResourceType baseResourceType = resourceType.BaseType; while (sourceResourceSet == null && baseResourceType != null) { sourceResourceSet = baseResourceType.GetAnnotation().ResourceSet; baseResourceType = baseResourceType.BaseType; } return new ResourceAssociationSet( resourceType.Name + "_" + name + "_" + targetResourceSet.Name, new ResourceAssociationSetEnd(sourceResourceSet, resourceType, property), new ResourceAssociationSetEnd(targetResourceSet, targetResourceType, null)); }; }
/// <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 abstract IQueryable GetQueryRootForResourceSet(ResourceSet container);
private string Serialize(DSP.ResourceSet set) { return(set.Name); }
/// <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 set reference property points to.</param> /// <param name="targetResourceType">The resource type the resource set reference property points to. /// Can be null in which case the base resource type of the resource set is used.</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, ResourceType targetResourceType) { AddReferenceProperty(resourceType, name, targetResourceSet, targetResourceType, true); }
public void GetTargetSetTestsSetBindingTypeShouldPerformCorrectValidation() { ResourceType actorEntityType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "foo", "Actor", false) { CanReflectOnInstanceType = false }; ResourceProperty idProperty = new ResourceProperty("ID", ResourcePropertyKind.Primitive | ResourcePropertyKind.Key, ResourceType.GetPrimitiveResourceType(typeof(int))) { CanReflectOnInstanceTypeProperty = false }; actorEntityType.AddProperty(idProperty); ResourceType addressComplexType = new ResourceType(typeof(object), ResourceTypeKind.ComplexType, null, "foo", "Address", false) { CanReflectOnInstanceType = false }; addressComplexType.AddProperty(new ResourceProperty("StreetAddress", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(string))) { CanReflectOnInstanceTypeProperty = false }); addressComplexType.AddProperty(new ResourceProperty("ZipCode", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(int))) { CanReflectOnInstanceTypeProperty = false }); actorEntityType.AddProperty(new ResourceProperty("PrimaryAddress", ResourcePropertyKind.ComplexType, addressComplexType) { CanReflectOnInstanceTypeProperty = false }); actorEntityType.AddProperty(new ResourceProperty("OtherAddresses", ResourcePropertyKind.Collection, ResourceType.GetCollectionResourceType(addressComplexType)) { CanReflectOnInstanceTypeProperty = false }); ResourceType movieEntityType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "foo", "Movie", false) { CanReflectOnInstanceType = false }; movieEntityType.AddProperty(idProperty); ResourceProperty moviesNavProp = new ResourceProperty("Movies", ResourcePropertyKind.ResourceSetReference, movieEntityType) { CanReflectOnInstanceTypeProperty = false }; actorEntityType.AddProperty(moviesNavProp); ResourceProperty actorsNavProp = new ResourceProperty("Actors", ResourcePropertyKind.ResourceSetReference, actorEntityType) { CanReflectOnInstanceTypeProperty = false }; movieEntityType.AddProperty(actorsNavProp); ResourceType derivedActorEntityType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, actorEntityType, "foo", "DerivedActor", false) { CanReflectOnInstanceType = false }; ResourceType derivedMovieEntityType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, movieEntityType, "foo", "DerivedMovie", false) { CanReflectOnInstanceType = false }; actorEntityType.SetReadOnly(); derivedActorEntityType.SetReadOnly(); movieEntityType.SetReadOnly(); derivedMovieEntityType.SetReadOnly(); addressComplexType.SetReadOnly(); DataServiceProviderSimulator providerSimulator = new DataServiceProviderSimulator(); providerSimulator.AddResourceType(actorEntityType); providerSimulator.AddResourceType(derivedActorEntityType); providerSimulator.AddResourceType(movieEntityType); providerSimulator.AddResourceType(derivedMovieEntityType); providerSimulator.AddResourceType(addressComplexType); ResourceSet actorSet = new ResourceSet("Actors", actorEntityType); ResourceSet movieSet = new ResourceSet("Movies", movieEntityType); actorSet.SetReadOnly(); movieSet.SetReadOnly(); providerSimulator.AddResourceSet(actorSet); providerSimulator.AddResourceSet(movieSet); providerSimulator.AddResourceAssociationSet(new ResourceAssociationSet("Actors_Movies", new ResourceAssociationSetEnd(actorSet, actorEntityType, moviesNavProp), new ResourceAssociationSetEnd(movieSet, movieEntityType, actorsNavProp))); DataServiceConfiguration config = new DataServiceConfiguration(providerSimulator); config.SetEntitySetAccessRule("*", EntitySetRights.All); config.DataServiceBehavior.MaxProtocolVersion = ODataProtocolVersion.V4; var dataService = new DataServiceSimulator() { OperationContext = new DataServiceOperationContext(new DataServiceHostSimulator()) }; dataService.ProcessingPipeline = new DataServiceProcessingPipeline(); DataServiceStaticConfiguration staticConfiguration = new DataServiceStaticConfiguration(dataService.Instance.GetType(), providerSimulator); IDataServiceProviderBehavior providerBehavior = DataServiceProviderBehavior.CustomDataServiceProviderBehavior; DataServiceProviderWrapper provider = new DataServiceProviderWrapper( new DataServiceCacheItem( config, staticConfiguration), providerSimulator, providerSimulator, dataService, false); dataService.Provider = provider; provider.ProviderBehavior = providerBehavior; var testCases = new[] { new { AppendParameterName = true, Path = "", BindingSet = ResourceSetWrapper.CreateResourceSetWrapper(actorSet, provider, set => set), TargetSet = ResourceSetWrapper.CreateResourceSetWrapper(actorSet, provider, set => set), ErrorMessage = default(string) }, new { AppendParameterName = true, Path = "/Movies", BindingSet = ResourceSetWrapper.CreateResourceSetWrapper(actorSet, provider, set => set), TargetSet = ResourceSetWrapper.CreateResourceSetWrapper(movieSet, provider, set => set), ErrorMessage = default(string) }, new { AppendParameterName = true, Path = "/Movies/Actors/Movies", BindingSet = ResourceSetWrapper.CreateResourceSetWrapper(actorSet, provider, set => set), TargetSet = ResourceSetWrapper.CreateResourceSetWrapper(movieSet, provider, set => set), ErrorMessage = default(string) }, new { AppendParameterName = true, Path = "/foo.DerivedActor/Movies/foo.DerivedMovie/Actors/foo.DerivedActor/Movies", BindingSet = ResourceSetWrapper.CreateResourceSetWrapper(actorSet, provider, set => set), TargetSet = ResourceSetWrapper.CreateResourceSetWrapper(movieSet, provider, set => set), ErrorMessage = default(string) }, new { AppendParameterName = true, Path = "/", BindingSet = ResourceSetWrapper.CreateResourceSetWrapper(actorSet, provider, set => set), TargetSet = default(ResourceSetWrapper), ErrorMessage = "The path expression '{0}/' is not a valid expression because it contains an empty segment or it ends with '/'." }, new { AppendParameterName = true, Path = "/Movies/", BindingSet = ResourceSetWrapper.CreateResourceSetWrapper(actorSet, provider, set => set), TargetSet = default(ResourceSetWrapper), ErrorMessage = "The path expression '{0}/Movies/' is not a valid expression because it contains an empty segment or it ends with '/'." }, new { AppendParameterName = true, Path = "/Movies//Actors", BindingSet = ResourceSetWrapper.CreateResourceSetWrapper(actorSet, provider, set => set), TargetSet = ResourceSetWrapper.CreateResourceSetWrapper(movieSet, provider, set => set), ErrorMessage = "The path expression '{0}/Movies//Actors' is not a valid expression because it contains an empty segment or it ends with '/'." }, new { AppendParameterName = true, Path = "/foo.DerivedActor", BindingSet = ResourceSetWrapper.CreateResourceSetWrapper(actorSet, provider, set => set), TargetSet = default(ResourceSetWrapper), ErrorMessage = "The path expression '{0}/foo.DerivedActor' is not a valid expression because it ends with the type identifier 'foo.DerivedActor'. A valid path expression must not end in a type identifier." }, new { AppendParameterName = true, Path = "/Movies/foo.DerivedMovie", BindingSet = ResourceSetWrapper.CreateResourceSetWrapper(actorSet, provider, set => set), TargetSet = default(ResourceSetWrapper), ErrorMessage = "The path expression '{0}/Movies/foo.DerivedMovie' is not a valid expression because it ends with the type identifier 'foo.DerivedMovie'. A valid path expression must not end in a type identifier." }, new { AppendParameterName = true, Path = "/Foo", BindingSet = ResourceSetWrapper.CreateResourceSetWrapper(actorSet, provider, set => set), TargetSet = default(ResourceSetWrapper), ErrorMessage = "The path expression '{0}/Foo' is not a valid expression because the segment 'Foo' is not a type identifier or a property on the resource type 'foo.Actor'." }, new { AppendParameterName = true, Path = "/ID", BindingSet = ResourceSetWrapper.CreateResourceSetWrapper(actorSet, provider, set => set), TargetSet = default(ResourceSetWrapper), ErrorMessage = "The path expression '{0}/ID' is not a valid expression because the segment 'ID' is a property of type 'Edm.Int32'. A valid path expression must only contain properties of entity type." }, new { AppendParameterName = true, Path = "/OtherAddresses", BindingSet = ResourceSetWrapper.CreateResourceSetWrapper(actorSet, provider, set => set), TargetSet = default(ResourceSetWrapper), ErrorMessage = "The path expression '{0}/OtherAddresses' is not a valid expression because the segment 'OtherAddresses' is a property of type 'Collection(foo.Address)'. A valid path expression must only contain properties of entity type." }, new { AppendParameterName = true, Path = "/Movies/Actors/PrimaryAddress", BindingSet = ResourceSetWrapper.CreateResourceSetWrapper(actorSet, provider, set => set), TargetSet = default(ResourceSetWrapper), ErrorMessage = "The path expression '{0}/Movies/Actors/PrimaryAddress' is not a valid expression because the segment 'PrimaryAddress' is a property of type 'foo.Address'. A valid path expression must only contain properties of entity type." }, new { AppendParameterName = false, Path = "foo", BindingSet = ResourceSetWrapper.CreateResourceSetWrapper(actorSet, provider, set => set), TargetSet = default(ResourceSetWrapper), ErrorMessage = "The path expression 'foo' is not a valid path expression. A valid path expression must start with the binding parameter name '{0}'." }, new { AppendParameterName = false, Path = "abc/pqr", BindingSet = ResourceSetWrapper.CreateResourceSetWrapper(actorSet, provider, set => set), TargetSet = default(ResourceSetWrapper), ErrorMessage = "The path expression 'abc/pqr' is not a valid path expression. A valid path expression must start with the binding parameter name '{0}'." }, new { AppendParameterName = false, Path = "actorParameter", BindingSet = ResourceSetWrapper.CreateResourceSetWrapper(actorSet, provider, set => set), TargetSet = default(ResourceSetWrapper), ErrorMessage = "The path expression 'actorParameter' is not a valid path expression. A valid path expression must start with the binding parameter name '{0}'." }, new { AppendParameterName = false, Path = "actorsParameter", BindingSet = ResourceSetWrapper.CreateResourceSetWrapper(actorSet, provider, set => set), TargetSet = default(ResourceSetWrapper), ErrorMessage = "The path expression 'actorsParameter' is not a valid path expression. A valid path expression must start with the binding parameter name '{0}'." }, }; ServiceActionParameter actorParameter = new ServiceActionParameter("actor", actorEntityType); ServiceActionParameter actorsParameter = new ServiceActionParameter("actors", ResourceType.GetEntityCollectionResourceType(actorEntityType)); var parameters = new ServiceActionParameter[] { actorParameter, actorsParameter }; foreach (var parameter in parameters) { foreach (var testCase in testCases) { string pathString = testCase.AppendParameterName ? parameter.Name + testCase.Path : testCase.Path; var path = new ResourceSetPathExpression(pathString); Assert.AreEqual(pathString, path.PathExpression); string expectedErrorMessage = testCase.ErrorMessage == null ? null : string.Format(testCase.ErrorMessage, parameter.Name); try { path.SetBindingParameter(parameter); path.InitializePathSegments(provider); var targetSet = path.GetTargetSet(provider, testCase.BindingSet); Assert.IsNull(expectedErrorMessage, "Expecting exception but received none."); Assert.AreEqual(targetSet.Name, testCase.TargetSet.Name); } catch (InvalidOperationException e) { Assert.AreEqual(expectedErrorMessage, e.Message); } } } }
/// <summary> /// Override the query root /// </summary> /// <param name="resourceSet"></param> /// <returns></returns> public override IQueryable GetQueryRootForResourceSet(ResourceSet resourceSet) { // First parameterize the expression tree, then fix the tree for Geo and Enum return EFParameterizedQueryProvider.CreateQuery(base.GetQueryRootForResourceSet(resourceSet)); }
private static IDataServiceMetadataProvider PopulateMetadata(object dataSourceInstance) { List<ResourceType> types = new List<ResourceType>(4); ResourceType customer = new ResourceType( typeof(RowEntityTypeWithIDAsKey), ResourceTypeKind.EntityType, null, /*baseType*/ "AstoriaUnitTests.Stubs", /*namespaceName*/ "Customer", false /*isAbstract*/); customer.CanReflectOnInstanceType = false; ResourceType order = new ResourceType( typeof(RowEntityTypeWithIDAsKey), ResourceTypeKind.EntityType, null, "AstoriaUnitTests.Stubs", "Order", false); order.CanReflectOnInstanceType = false; ResourceType region = new ResourceType( typeof(RowEntityTypeWithIDAsKey), ResourceTypeKind.EntityType, null, /*baseType*/ "AstoriaUnitTests.Stubs", /*namespaceName*/ "Region", false /*isAbstract*/); region.CanReflectOnInstanceType = false; ResourceType address = new ResourceType( typeof(RowComplexType), ResourceTypeKind.ComplexType, null, "AstoriaUnitTests.Stubs", "Address", false); address.CanReflectOnInstanceType = false; ResourceType product = new ResourceType( typeof(RowEntityTypeWithIDAsKey), ResourceTypeKind.EntityType, null, /*baseType*/ "AstoriaUnitTests.Stubs", /*namespaceName*/ "Product", false /*isAbstract*/); product.CanReflectOnInstanceType = false; ResourceType orderDetail = new ResourceType( typeof(RowEntityType), ResourceTypeKind.EntityType, null, /*baseType*/ "AstoriaUnitTests.Stubs", /*namespaceName*/ "OrderDetail", false /*isAbstract*/); orderDetail.CanReflectOnInstanceType = false; ResourceType currency = new ResourceType( typeof(RowComplexType), ResourceTypeKind.ComplexType, null, "AstoriaUnitTests.Stubs", "CurrencyAmount", false); ResourceType headquarter = new ResourceType( typeof(RowComplexType), ResourceTypeKind.ComplexType, null, "AstoriaUnitTests.Stubs", "Headquarter", false); headquarter.CanReflectOnInstanceType = false; ResourceSet customerEntitySet = new ResourceSet("Customers", customer); ResourceSet orderEntitySet = new ResourceSet("Orders", order); ResourceSet regionEntitySet = new ResourceSet("Regions", region); ResourceSet productEntitySet = new ResourceSet("Products", product); ResourceSet orderDetailEntitySet = new ResourceSet("OrderDetails", orderDetail); ResourceSet memberCustomerEntitySet = new ResourceSet("MemberCustomers", customer); ResourceSet memberOrderEntitySet = new ResourceSet("MemberOrders", order); ResourceSet memberRegionEntitySet = new ResourceSet("MemberRegions", region); ResourceSet memberProductEntitySet = new ResourceSet("MemberProducts", product); ResourceSet memberOrderDetailEntitySet = new ResourceSet("MemberOrderDetails", orderDetail); ResourceProperty keyProperty = new ResourceProperty( "ID", ResourcePropertyKind.Key | ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(int))); // populate customer properties customer.AddProperty(keyProperty); customer.AddProperty(CreateNonClrProperty("Name", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(String)))); customer.AddProperty(CreateNonClrProperty("BestFriend", ResourcePropertyKind.ResourceReference, customer)); customer.AddProperty(CreateNonClrProperty("Orders", ResourcePropertyKind.ResourceSetReference, order)); customer.AddProperty(CreateNonClrProperty("Region", ResourcePropertyKind.ResourceReference, region)); customer.AddProperty(CreateNonClrProperty("Address", ResourcePropertyKind.ComplexType, address)); customer.AddProperty(CreateNonClrProperty("GuidValue", ResourcePropertyKind.Primitive | ResourcePropertyKind.ETag, ResourceType.GetPrimitiveResourceType(typeof(Guid)))); ResourceProperty property = CreateNonClrProperty("NameAsHtml", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(string))); property.MimeType = "text/html"; customer.AddProperty(property); if (OpenWebDataServiceHelper.EnableBlobServer) { customer.IsMediaLinkEntry = true; } // create Customer With Birthday and populate its properties ResourceType customerWithBirthday = new ResourceType( typeof(RowEntityTypeWithIDAsKey), ResourceTypeKind.EntityType, customer, /*baseType*/ "AstoriaUnitTests.Stubs", /*namespaceName*/ "CustomerWithBirthday", false /*isAbstract*/); customerWithBirthday.AddProperty(CreateNonClrProperty("Birthday", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(DateTime)))); customerWithBirthday.CanReflectOnInstanceType = false; // populate order properties order.AddProperty(keyProperty); order.AddProperty(CreateNonClrProperty("DollarAmount", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(double)))); order.AddProperty(CreateNonClrProperty("OrderDetails", ResourcePropertyKind.ResourceSetReference, orderDetail)); order.AddProperty(CreateNonClrProperty("CurrencyAmount", ResourcePropertyKind.ComplexType, currency)); order.AddProperty(CreateNonClrProperty("Customer", ResourcePropertyKind.ResourceReference, customer)); // populate region properties region.AddProperty(keyProperty); region.AddProperty(CreateNonClrProperty("Name", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(string)))); region.AddProperty(CreateNonClrProperty("Headquarter", ResourcePropertyKind.ComplexType, headquarter)); //populate headquarter properties headquarter.AddProperty(CreateNonClrProperty("DrivingDirections", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(string)))); headquarter.AddProperty(CreateNonClrProperty("Address", ResourcePropertyKind.ComplexType, address)); //populate address properties address.AddProperty(CreateNonClrProperty("StreetAddress", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(string)))); address.AddProperty(CreateNonClrProperty("City", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(string)))); address.AddProperty(CreateNonClrProperty("State", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(string)))); address.AddProperty(CreateNonClrProperty("PostalCode", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(string)))); // create product type and its properties product.AddProperty(keyProperty); product.AddProperty(CreateNonClrProperty("ProductName", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(String)))); product.AddProperty(CreateNonClrProperty("Discontinued", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(bool)))); product.AddProperty(CreateNonClrProperty("OrderDetails", ResourcePropertyKind.ResourceSetReference, orderDetail)); // create order detail and its properties // DEVNOTE: it's very important that ProductID and OrderID are not in alphabetical order. There are tests relying on this. orderDetail.AddProperty(CreateNonClrProperty("ProductID", ResourcePropertyKind.Key | ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(int)))); orderDetail.AddProperty(CreateNonClrProperty("OrderID", ResourcePropertyKind.Key | ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(int)))); orderDetail.AddProperty(CreateNonClrProperty("UnitPrice", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(double)))); orderDetail.AddProperty(CreateNonClrProperty("Quantity", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(short)))); //populate currency amount properties currency.AddProperty(CreateNonClrProperty("Amount", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(decimal)))); currency.AddProperty(CreateNonClrProperty("CurrencyName", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(String)))); types.Add(customer); types.Add(customerWithBirthday); types.Add(order); types.Add(region); types.Add(address); types.Add(product); types.Add(orderDetail); types.Add(currency); types.Add(headquarter); List<ResourceSet> containers = new List<ResourceSet>(7); containers.Add(customerEntitySet); containers.Add(orderEntitySet); containers.Add(regionEntitySet); containers.Add(productEntitySet); containers.Add(orderDetailEntitySet); containers.Add(memberCustomerEntitySet); containers.Add(memberOrderEntitySet); containers.Add(memberRegionEntitySet); containers.Add(memberProductEntitySet); containers.Add(memberOrderDetailEntitySet); List<ServiceOperation> operations = new List<ServiceOperation>(1); operations.Add(new ServiceOperation("IntServiceOperation", ServiceOperationResultKind.DirectValue, ResourceType.GetPrimitiveResourceType(typeof(int)), null, "GET", null)); operations.Add(new ServiceOperation("InsertCustomer", ServiceOperationResultKind.DirectValue, customer, customerEntitySet, "POST", new ServiceOperationParameter[] { new ServiceOperationParameter("id", ResourceType.GetPrimitiveResourceType(typeof(int))), new ServiceOperationParameter("name", ResourceType.GetPrimitiveResourceType(typeof(string))) } )); operations.Add(new ServiceOperation("GetCustomerByCity", ServiceOperationResultKind.QueryWithMultipleResults, customer, customerEntitySet, "GET", new ServiceOperationParameter[] { new ServiceOperationParameter("city", ResourceType.GetPrimitiveResourceType(typeof(string))) })); operations.Add(new ServiceOperation("DoNothingOperation", ServiceOperationResultKind.Void, null, null, "POST", null)); operations.Add(new ServiceOperation("GetCustomerAddress", ServiceOperationResultKind.DirectValue, address, null, "GET", new ServiceOperationParameter[] { new ServiceOperationParameter("id", ResourceType.GetPrimitiveResourceType(typeof(int))) })); operations.Add(new ServiceOperation("GetOrderById", ServiceOperationResultKind.DirectValue, order, orderEntitySet, "GET", new ServiceOperationParameter[] { new ServiceOperationParameter("id", ResourceType.GetPrimitiveResourceType(typeof(int))) })); operations.Add(new ServiceOperation("GetRegionByName", ServiceOperationResultKind.QueryWithMultipleResults, region, regionEntitySet, "GET", new ServiceOperationParameter[] { new ServiceOperationParameter("name", ResourceType.GetPrimitiveResourceType(typeof(string))) })); operations.Add(new ServiceOperation("AddressServiceOperation", ServiceOperationResultKind.DirectValue, address, null, "GET", null)); operations.Add(new ServiceOperation("GetAllCustomersQueryable", ServiceOperationResultKind.QueryWithMultipleResults, customer, customerEntitySet, "GET", null)); operations.Add(new ServiceOperation("GetCustomerByIdQueryable", ServiceOperationResultKind.QueryWithSingleResult, customer, customerEntitySet, "GET", new ServiceOperationParameter[] { new ServiceOperationParameter("id", ResourceType.GetPrimitiveResourceType(typeof(int))) })); operations.Add(new ServiceOperation("GetAllCustomersEnumerable", ServiceOperationResultKind.Enumeration, customer, customerEntitySet, "GET", null)); operations.Add(new ServiceOperation("GetCustomerByIdDirectValue", ServiceOperationResultKind.DirectValue, customer, customerEntitySet, "GET", new ServiceOperationParameter[] { new ServiceOperationParameter("id", ResourceType.GetPrimitiveResourceType(typeof(int))) })); operations.Add(new ServiceOperation("GetAllOrdersQueryable", ServiceOperationResultKind.QueryWithMultipleResults, order, orderEntitySet, "GET", null)); operations.Add(new ServiceOperation("GetOrderByIdQueryable", ServiceOperationResultKind.QueryWithSingleResult, order, orderEntitySet, "GET", new ServiceOperationParameter[] { new ServiceOperationParameter("id", ResourceType.GetPrimitiveResourceType(typeof(int))) })); operations.Add(new ServiceOperation("GetAllOrdersEnumerable", ServiceOperationResultKind.Enumeration, order, orderEntitySet, "GET", null)); operations.Add(new ServiceOperation("GetOrderByIdDirectValue", ServiceOperationResultKind.DirectValue, order, orderEntitySet, "GET", new ServiceOperationParameter[] { new ServiceOperationParameter("id", ResourceType.GetPrimitiveResourceType(typeof(int))) })); List<ResourceAssociationSet> associationSets = new List<ResourceAssociationSet>(); ResourceAssociationSet customer_BestFriend = new ResourceAssociationSet( "Customers_BestFriend", new ResourceAssociationSetEnd(customerEntitySet, customer, customer.PropertiesDeclaredOnThisType.FirstOrDefault(p => p.Name == "BestFriend")), new ResourceAssociationSetEnd(customerEntitySet, customer, customer.PropertiesDeclaredOnThisType.FirstOrDefault(p => p.Name == "BestFriend"))); associationSets.Add(customer_BestFriend); ResourceAssociationSet customer_Order = new ResourceAssociationSet( "Customers_Orders", new ResourceAssociationSetEnd(customerEntitySet, customer, customer.PropertiesDeclaredOnThisType.FirstOrDefault(p => p.Name == "Orders")), new ResourceAssociationSetEnd(orderEntitySet, order, order.PropertiesDeclaredOnThisType.FirstOrDefault(p => p.Name == "Customer"))); associationSets.Add(customer_Order); ResourceAssociationSet customer_Region = new ResourceAssociationSet( "Customers_Regions", new ResourceAssociationSetEnd(customerEntitySet, customer, customer.PropertiesDeclaredOnThisType.FirstOrDefault(p => p.Name == "Region")), new ResourceAssociationSetEnd(regionEntitySet, region, region.PropertiesDeclaredOnThisType.FirstOrDefault(p => p.Name == "Customer"))); associationSets.Add(customer_Region); ResourceAssociationSet order_OrderDetails = new ResourceAssociationSet( "Orders_OrderDetails", new ResourceAssociationSetEnd(orderEntitySet, order, order.PropertiesDeclaredOnThisType.FirstOrDefault(p => p.Name == "OrderDetails")), new ResourceAssociationSetEnd(orderDetailEntitySet, orderDetail, null)); associationSets.Add(order_OrderDetails); ResourceAssociationSet product_OrderDetails = new ResourceAssociationSet( "Products_OrderDetails", new ResourceAssociationSetEnd(productEntitySet, product, product.PropertiesDeclaredOnThisType.FirstOrDefault(p => p.Name == "OrderDetails")), new ResourceAssociationSetEnd(orderDetailEntitySet, orderDetail, null)); associationSets.Add(product_OrderDetails); ResourceAssociationSet memberCustomer_BestFriend = new ResourceAssociationSet( "MemberCustomers_BestFriend", new ResourceAssociationSetEnd(memberCustomerEntitySet, customer, customer.PropertiesDeclaredOnThisType.FirstOrDefault(p => p.Name == "BestFriend")), new ResourceAssociationSetEnd(memberCustomerEntitySet, customer, null)); associationSets.Add(memberCustomer_BestFriend); ResourceAssociationSet memberCustomer_MemberOrder = new ResourceAssociationSet( "MemberCustomers_MemberOrders", new ResourceAssociationSetEnd(memberCustomerEntitySet, customer, customer.PropertiesDeclaredOnThisType.FirstOrDefault(p => p.Name == "Orders")), new ResourceAssociationSetEnd(memberOrderEntitySet, order, order.PropertiesDeclaredOnThisType.FirstOrDefault(p => p.Name == "Customer"))); associationSets.Add(memberCustomer_MemberOrder); ResourceAssociationSet memberCustomer_MemberRegion = new ResourceAssociationSet( "MemberCustomers_MemberRegions", new ResourceAssociationSetEnd(memberCustomerEntitySet, customer, customer.PropertiesDeclaredOnThisType.FirstOrDefault(p => p.Name == "Region")), new ResourceAssociationSetEnd(memberRegionEntitySet, region, region.PropertiesDeclaredOnThisType.FirstOrDefault(p => p.Name == "Customer"))); associationSets.Add(memberCustomer_MemberRegion); ResourceAssociationSet memberOrder_MemberOrderDetails = new ResourceAssociationSet( "MemberOrder_MemberOrderDetails", new ResourceAssociationSetEnd(memberOrderEntitySet, order, order.PropertiesDeclaredOnThisType.FirstOrDefault(p => p.Name == "OrderDetails")), new ResourceAssociationSetEnd(memberOrderDetailEntitySet, orderDetail, null)); associationSets.Add(memberOrder_MemberOrderDetails); ResourceAssociationSet memberProduct_MemberOrderDetails = new ResourceAssociationSet( "MemberProduct_MemberOrderDetails", new ResourceAssociationSetEnd(memberProductEntitySet, product, product.PropertiesDeclaredOnThisType.FirstOrDefault(p => p.Name == "OrderDetails")), new ResourceAssociationSetEnd(memberOrderDetailEntitySet, orderDetail, null)); associationSets.Add(memberProduct_MemberOrderDetails); return new CustomDataServiceProvider(containers, types, operations, associationSets, dataSourceInstance); }
public void GetResourceAssociationSet(DSP.ResourceSet resourceSet, DSP.ResourceType resourceType, DSP.ResourceProperty resourceProperty) { Add("GetResourceAssociationSet", Serialize(resourceSet), Serialize(resourceType), Serialize(resourceProperty)); }
/// <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; }
/// <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 virtual bool TryResolveResourceSet(string name, out ResourceSet resourceSet) { WebUtil.CheckStringArgumentNullOrEmpty(name, "name"); return(this.metadata.EntitySets.TryGetValue(name, out resourceSet)); }
/// <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; }
} // ServiceOperations public DSP.ResourceAssociationSet GetResourceAssociationSet(DSP.ResourceSet resourceSet, DSP.ResourceType resourceType, DSP.ResourceProperty resourceProperty) { if (associations == null) { associations = new Dictionary <string, DSP.ResourceAssociationSet>(); } DSP.ResourceType targetType = resourceProperty.ResourceType; DSP.ResourceSet targetSet = null; var targetContainers = this.containers.Where(c => IsAssignableFrom(c.ResourceType, targetType)); if (targetContainers.Count() == 1) { targetSet = targetContainers.First(); } else if (targetContainers.Count() > 1) { // MEST (uses naming convention) if (resourceSet.CustomState != null) { targetSet = targetContainers.Single(c => (string)c.CustomState == (string)resourceSet.CustomState); } else if (resourceProperty.CustomState != null) { targetSet = targetContainers.Single(c => (string)c.CustomState == (string)resourceProperty.CustomState); } else { throw new DataServiceException(500, "Cannot infer association set for MEST scenario"); } } string associationName = resourceSet.Name + "_" + resourceType.Name + '_' + resourceProperty.Name; if (associations.Keys.Contains(associationName)) { return(associations[associationName]); } else { DSP.ResourceProperty targetProperty = null; // Self links must be one-way if (resourceProperty.CustomState != null && (resourceSet != targetSet && resourceType != targetType)) { targetProperty = targetType.Properties.SingleOrDefault(p => p.CustomState != null && (string)p.CustomState == (string)resourceProperty.CustomState); } DSP.ResourceAssociationSetEnd sourceEnd = new DSP.ResourceAssociationSetEnd(resourceSet, resourceType, resourceProperty); DSP.ResourceAssociationSetEnd targetEnd = new DSP.ResourceAssociationSetEnd(targetSet, targetType, targetProperty); DSP.ResourceAssociationSet associationSet = new DSP.ResourceAssociationSet(associationName, sourceEnd, targetEnd); associations.Add(associationName, associationSet); // add to hash for target side if (targetProperty != null) { associationName = targetSet.Name + "_" + targetType.Name + '_' + targetProperty.Name; associations.Add(associationName, associationSet); } return(associationSet); } } // GetResourceAssociationSet
/// <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 virtual ResourceAssociationSet GetResourceAssociationSet(ResourceSet resourceSet, ResourceType resourceType, ResourceProperty resourceProperty) { ResourceAssociationSet resourceAssociationSet; if (this.associationSets.TryGetValue(resourceSet.Name + "_" + resourceType.FullName + "_" + resourceProperty.Name, out resourceAssociationSet)) { Debug.Assert(resourceAssociationSet != null, "resourceAssociationSet != null"); // Just few verification to show what is expected of the returned resource association set. Debug.Assert( (resourceAssociationSet.End1.ResourceSet == resourceSet && resourceAssociationSet.End1.ResourceType == resourceType && resourceAssociationSet.End1.ResourceProperty == resourceProperty) || (resourceAssociationSet.End2.ResourceSet == resourceSet && resourceAssociationSet.End2.ResourceType == resourceType && resourceAssociationSet.End2.ResourceProperty == resourceProperty), "The precreated resource association set doesn't match the specified resource set."); } else { // We have the resource association set precreated on the property annotation, so no need to compute anything in here Debug.Assert(resourceProperty.GetAnnotation().ResourceAssociationSet != null, "resourceProperty.GetAnnotation().ResourceAssociationSet != null"); 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; }
/// <summary> /// Override the GetQueryRootForResourceSet to fix the expression tree for Geo types and enum /// </summary> /// <param name="resourceSet"></param> /// <returns></returns> public override IQueryable GetQueryRootForResourceSet(ResourceSet resourceSet) { return L2OParameterizedQueryProvider.CreateQuery(base.GetQueryRootForResourceSet(resourceSet)); }
public object CreateResource(string containerName, string fullTypeName) { object resource = null; DSP.ResourceType type = this.Types.FirstOrDefault(t => t.FullName == fullTypeName); if (type == null) { throw new DataServiceException((int)Net.HttpStatusCode.BadRequest, "No type of name '" + fullTypeName + "' exists"); } if (type.IsAbstract) { throw new DataServiceException((int)Net.HttpStatusCode.BadRequest, "Cannot create an instance of abstract type '" + fullTypeName + "'"); } if (containerName == null) { return(new RowComplexType(fullTypeName)); } else { DSP.ResourceSet container = containers.FirstOrDefault(rc => rc.Name == containerName); if (container == null) { throw new DataServiceException((int)Net.HttpStatusCode.BadRequest, "No container of name '" + containerName + "' exists"); } bool belongsInContainer = false; DSP.ResourceType typeForContainerCheck = type; while (typeForContainerCheck != null && !belongsInContainer) { if (typeForContainerCheck == container.ResourceType) { belongsInContainer = true; } else { typeForContainerCheck = typeForContainerCheck.BaseType; } } if (!belongsInContainer) { throw new DataServiceException((int)Net.HttpStatusCode.BadRequest, "An entity of type '" + fullTypeName + "' cannot be added to '" + containerName + "'"); } if (type.InstanceType == typeof(RowEntityType)) { resource = new RowEntityType(containerName, fullTypeName); } else { ConstructorInfo constructor = type.InstanceType.GetConstructor(new Type[] { typeof(string) }); if (constructor != null) { resource = constructor.Invoke(new object[] { containerName }); } else { constructor = type.InstanceType.GetConstructor(new Type[] { }); resource = constructor.Invoke(new object[] { }); } } foreach (DSP.ResourceProperty property in type.Properties.Where(p => p.Kind == DSP.ResourcePropertyKind.ResourceSetReference)) { this.SetValue(resource, property.Name, new List <RowEntityType>()); } foreach (DSP.ResourceProperty property in type.Properties.Where(p => ServerGeneratedCustomState.Equals(p.CustomState))) { if (property.ResourceType.InstanceType != typeof(int)) { throw new DataServiceException(500, "Auto incrementing is not supported for non-int properties"); } int value; if (!autoIncremementingProperties.TryGetValue(property.Name, out value)) { value = 0; } this.SetValue(resource, property.Name, value); autoIncremementingProperties[property.Name] = value + 1; } this.PendingChanges.Add(new KeyValuePair <object, EntityState>(resource, EntityState.Added)); return(resource); } } // CreateResource
private static DataServiceProviderWrapper CreateProvider(out DataServiceConfiguration config, out DataServiceOperationContext operationContext) { var baseUri = new Uri("http://localhost"); var host = new DataServiceHostSimulator() { AbsoluteServiceUri = baseUri, AbsoluteRequestUri = new Uri(baseUri.AbsoluteUri + "/$metadata", UriKind.Absolute), RequestHttpMethod = "GET", RequestAccept = "application/xml+atom", RequestVersion = "4.0", RequestMaxVersion = "4.0", }; operationContext = new DataServiceOperationContext(host); var dataService = new DataServiceSimulator() { OperationContext = operationContext }; operationContext.InitializeAndCacheHeaders(dataService); DataServiceProviderSimulator providerSimulator = new DataServiceProviderSimulator(); providerSimulator.ContainerNamespace = "MyModel"; providerSimulator.ContainerName = "CustomersContainer"; ResourceType customerEntityType = new ResourceType( typeof(object), ResourceTypeKind.EntityType, null, "MyModel", "Customer", false) { CanReflectOnInstanceType = false }; ResourcePropertyKind idPropertyKind = ResourcePropertyKind.Primitive | ResourcePropertyKind.Key; ResourceProperty idProperty = new ResourceProperty( "Id", idPropertyKind, ResourceType.GetPrimitiveResourceType(typeof(int))) { CanReflectOnInstanceTypeProperty = false }; customerEntityType.AddProperty(idProperty); ResourcePropertyKind firstNamePropertyKind = ResourcePropertyKind.Primitive | ResourcePropertyKind.Key; ResourceProperty firstNameProperty = new ResourceProperty( "FirstName", firstNamePropertyKind, ResourceType.GetPrimitiveResourceType(typeof(string))) { CanReflectOnInstanceTypeProperty = false }; customerEntityType.AddProperty(firstNameProperty); customerEntityType.SetReadOnly(); providerSimulator.AddResourceType(customerEntityType); ResourceSet customerSet = new ResourceSet("Customers", customerEntityType); customerSet.SetReadOnly(); providerSimulator.AddResourceSet(customerSet); config = new DataServiceConfiguration(providerSimulator); config.SetEntitySetAccessRule("*", EntitySetRights.All); config.DataServiceBehavior.MaxProtocolVersion = ODataProtocolVersion.V4; IDataServiceProviderBehavior providerBehavior = DataServiceProviderBehavior.CustomDataServiceProviderBehavior; DataServiceStaticConfiguration staticConfig = new DataServiceStaticConfiguration(dataService.Instance.GetType(), providerSimulator); DataServiceProviderWrapper provider = new DataServiceProviderWrapper( new DataServiceCacheItem(config, staticConfig), providerSimulator, providerSimulator, dataService, false); dataService.ProcessingPipeline = new DataServiceProcessingPipeline(); dataService.Provider = provider; provider.ProviderBehavior = providerBehavior; dataService.ActionProvider = DataServiceActionProviderWrapper.Create(dataService); #if DEBUG dataService.ProcessingPipeline.SkipDebugAssert = true; #endif operationContext.RequestMessage.InitializeRequestVersionHeaders(VersionUtil.ToVersion(config.DataServiceBehavior.MaxProtocolVersion)); return provider; }
public bool TryResolveResourceSet(string name, out ResourceSet resourceSet) { Trace("TryResolveResourceSet - " + name); resourceSet = this.containers.Where<ResourceSet>(c => c.Name == name).FirstOrDefault<ResourceSet>(); return resourceSet != null; }