Exemple #1
0
        internal MetadataProviderEdmModel(DataServiceProviderWrapper provider, DataServiceOperationContext operationContext, DataServiceStreamProviderWrapper streamProviderWrapper)
        {
            this.metadataProvider                            = provider;
            this.operationContext                            = operationContext;
            this.streamProviderWrapper                       = streamProviderWrapper;
            this.schemaTypeCache                             = new Dictionary <string, IEdmSchemaType>(StringComparer.Ordinal);
            this.resourceTypesPerNamespaceCache              = new Dictionary <string, HashSet <ResourceType> >(StringComparer.Ordinal);
            this.entityContainerCache                        = new Dictionary <string, MetadataProviderEdmEntityContainer>(StringComparer.Ordinal);
            this.primitiveOrComplexCollectionTypeCache       = new Dictionary <ResourceType, IEdmCollectionType>(EqualityComparer <ResourceType> .Default);
            this.entityPrimitiveOrComplexCollectionTypeCache = new Dictionary <ResourceType, IEdmCollectionType>(EqualityComparer <ResourceType> .Default);
            this.derivedTypeMappings                         = new Dictionary <IEdmStructuredType, List <IEdmStructuredType> >(EqualityComparer <IEdmStructuredType> .Default);
            this.associationSetByKeyCache                    = new Dictionary <string, string>(StringComparer.Ordinal);
            Version version = this.metadataProvider.Configuration.DataServiceBehavior.MaxProtocolVersion.ToVersion();

            this.SetDataServiceVersion(version);
            Version version2 = null;

            if (!MetadataProviderUtils.DataServiceEdmVersionMap.TryGetValue(version, out version2))
            {
                this.SetEdmVersion(Microsoft.Data.Edm.Library.EdmConstants.EdmVersionLatest);
            }
            else
            {
                this.SetEdmVersion(version2);
            }
        }
        private ResourcePropertyCache InitializeResourcePropertyCache(DataServiceProviderWrapper provider, System.Data.Services.Providers.ResourceType type)
        {
            ResourcePropertyCache cache;

            if (!this.resourcePropertyCache.TryGetValue(type, out cache))
            {
                cache = new ResourcePropertyCache {
                    Properties = new List <ResourceProperty>()
                };
                foreach (ResourceProperty property in type.Properties)
                {
                    if ((property.TypeKind != ResourceTypeKind.EntityType) || (provider.GetContainer(this, type, property) != null))
                    {
                        cache.Properties.Add(property);
                    }
                }
                cache.PropertiesDeclaredOnTheType = new List <ResourceProperty>();
                foreach (ResourceProperty property2 in type.PropertiesDeclaredOnThisType)
                {
                    if ((property2.TypeKind != ResourceTypeKind.EntityType) || (provider.GetContainer(this, type, property2) != null))
                    {
                        cache.PropertiesDeclaredOnTheType.Add(property2);
                    }
                }
                this.resourcePropertyCache.Add(type, cache);
            }
            return(cache);
        }
Exemple #3
0
 public void ApplyConfiguration(DataServiceConfiguration configuration, DataServiceProviderWrapper provider)
 {
     if (this.Kind == OperationKind.ServiceOperation)
     {
         this.serviceOperationRights = configuration.GetServiceOperationRights(this.ServiceOperation);
     }
     else
     {
         this.serviceActionRights = configuration.GetServiceActionRights(this.ServiceAction);
     }
     if (((this.Kind == OperationKind.ServiceOperation) && ((this.serviceOperationRights & ~System.Data.Services.ServiceOperationRights.OverrideEntitySetRights) != System.Data.Services.ServiceOperationRights.None)) || ((this.Kind == OperationKind.Action) && (this.serviceActionRights != System.Data.Services.ServiceActionRights.None)))
     {
         if (this.operation.ResourceSet != null)
         {
             this.resourceSet = provider.TryResolveResourceSet(this.operation.ResourceSet.Name);
             if (this.resourceSet == null)
             {
                 throw new InvalidOperationException(System.Data.Services.Strings.OperationWrapper_OperationResourceSetNotVisible(this.Name, this.operation.ResourceSet.Name));
             }
         }
         else if (this.ResultSetPathExpression != null)
         {
             this.ResultSetPathExpression.InitializePathSegments(provider);
         }
     }
 }
Exemple #4
0
        /// <summary>Whether the types contained in the set has mappings for friendly feeds are V1 compatible or not</summary>
        /// <param name="provider">Data service provider instance.</param>
        /// <returns>False if there's any type in this set which has friendly feed mappings with KeepInContent=false. True otherwise.</returns>
        internal bool EpmIsV1Compatible(DataServiceProviderWrapper provider)
        {
#if DEBUG
            Debug.Assert(provider != null, "provider != null");
            Debug.Assert(this.resourceSet != null, "this.resourceSet != null");
            Debug.Assert(this.isReadOnly, "EpmIsV1Compatible - entity set settings not initialized.");
#endif
            if (!this.epmIsV1Compatible.HasValue)
            {
                // Go through all types contained in the set. If any one type is EpmIsV1Compatible == false,
                // the whole set is EpmIsV1Compatible=false.
                ResourceType baseType       = this.resourceSet.ResourceType;
                bool         isV1Compatible = baseType.EpmIsV1Compatible;

                // If the base type is not epm v1 compatible or it has no derived type, we need not look any further.
                if (isV1Compatible && provider.HasDerivedTypes(baseType))
                {
                    foreach (ResourceType derivedType in provider.GetDerivedTypes(baseType))
                    {
                        if (!derivedType.EpmIsV1Compatible)
                        {
                            // We can stop as soon as we find the first type that is not epm v1 compatible.
                            isV1Compatible = false;
                            break;
                        }
                    }
                }

                this.epmIsV1Compatible = isV1Compatible;
            }

            return(this.epmIsV1Compatible.Value);
        }
Exemple #5
0
        internal ResourceSetWrapper GetTargetSet(DataServiceProviderWrapper provider, ResourceSetWrapper bindingSet)
        {
            ResourceSetWrapper sourceContainer = bindingSet;

            for (int i = 0; (sourceContainer != null) && (i < this.pathSegments.Length); i++)
            {
                PathSegment segment = this.pathSegments[i];
                if (segment.Property != null)
                {
                    sourceContainer = provider.GetContainer(sourceContainer, segment.SourceType, segment.Property);
                }
            }
            return(sourceContainer);
        }
Exemple #6
0
 public ResourceAssociationSetEnd(System.Data.Services.Providers.ResourceSet resourceSet, System.Data.Services.Providers.ResourceType resourceType, System.Data.Services.Providers.ResourceProperty resourceProperty)
 {
     WebUtil.CheckArgumentNull <System.Data.Services.Providers.ResourceSet>(resourceSet, "resourceSet");
     WebUtil.CheckArgumentNull <System.Data.Services.Providers.ResourceType>(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);
     }
     if ((resourceProperty != null) && (DataServiceProviderWrapper.GetDeclaringTypeForProperty(resourceType, resourceProperty, null) != resourceType))
     {
         throw new ArgumentException(Strings.ResourceAssociationSetEnd_ResourceTypeMustBeTheDeclaringType(resourceType.FullName, resourceProperty.Name));
     }
     this.resourceSet      = resourceSet;
     this.resourceType     = resourceType;
     this.resourceProperty = resourceProperty;
 }
Exemple #7
0
        public override ResourceAssociationSet GetResourceAssociationSet(ResourceSet resourceSet, ResourceType resourceType, ResourceProperty resourceProperty)
        {
            ResourceSet  set;
            ResourceType type;
            string       str;

            WebUtil.CheckArgumentNull <ResourceSet>(resourceSet, "resourceSet");
            WebUtil.CheckArgumentNull <ResourceType>(resourceType, "resourceType");
            WebUtil.CheckArgumentNull <ResourceProperty>(resourceProperty, "resourceProperty");
            if (!base.TryResolveResourceSet(resourceSet.Name, out set) || (set != resourceSet))
            {
                throw new InvalidOperationException(System.Data.Services.Strings.BadProvider_UnknownResourceSet(resourceSet.Name));
            }
            if (!base.TryResolveResourceType(resourceType.FullName, out type) || (type != resourceType))
            {
                throw new InvalidOperationException(System.Data.Services.Strings.BadProvider_UnknownResourceType(resourceType.FullName));
            }
            if (resourceType != DataServiceProviderWrapper.GetDeclaringTypeForProperty(resourceType, resourceProperty, null))
            {
                throw new InvalidOperationException(System.Data.Services.Strings.BadProvider_ResourceTypeMustBeDeclaringTypeForProperty(resourceType.FullName, resourceProperty.Name));
            }
            ResourceType type2 = resourceProperty.ResourceType;

            if (type2.ResourceTypeKind != ResourceTypeKind.EntityType)
            {
                throw new InvalidOperationException(System.Data.Services.Strings.BadProvider_PropertyMustBeNavigationPropertyOnType(resourceProperty.Name, resourceType.FullName));
            }
            ResourceSet containerForResourceType = InternalGetContainerForResourceType(type2.InstanceType, base.EntitySets.Values);

            if (base.Types.Count <ResourceType>(rt => (rt.Name == resourceType.Name)) > 1)
            {
                str = resourceType.FullName.Replace('.', '_') + '_' + resourceProperty.Name;
            }
            else
            {
                str = resourceType.Name + '_' + resourceProperty.Name;
            }
            ResourceAssociationSetEnd end = new ResourceAssociationSetEnd(resourceSet, resourceType, resourceProperty);

            return(new ResourceAssociationSet(str, end, new ResourceAssociationSetEnd(containerForResourceType, type2, null)));
        }
 private void CheckHierarchy(DataServiceProviderWrapper provider)
 {
     if (!this.epmMinDSPV.HasValue)
     {
         System.Data.Services.Providers.ResourceType resourceType = this.resourceSet.ResourceType;
         bool hasEntityPropertyMappings = resourceType.HasEntityPropertyMappings;
         DataServiceProtocolVersion epmMinimumDataServiceProtocolVersion = resourceType.EpmMinimumDataServiceProtocolVersion;
         bool    flag2           = false;
         bool    flag3           = this.GetEntitySerializableProperties(provider, resourceType).Any <ResourceProperty>(p => p.TypeKind == ResourceTypeKind.EntityType);
         bool    isOpenType      = resourceType.IsOpenType;
         Version metadataVersion = resourceType.MetadataVersion;
         if (provider.HasDerivedTypes(resourceType))
         {
             foreach (System.Data.Services.Providers.ResourceType type2 in provider.GetDerivedTypes(resourceType))
             {
                 if (type2.EpmMinimumDataServiceProtocolVersion > epmMinimumDataServiceProtocolVersion)
                 {
                     epmMinimumDataServiceProtocolVersion = type2.EpmMinimumDataServiceProtocolVersion;
                 }
                 hasEntityPropertyMappings |= type2.HasEntityPropertyMappings;
                 bool flag5 = this.GetEntitySerializablePropertiesDeclaredOnTheResourceType(provider, type2).Any <ResourceProperty>(p => p.TypeKind == ResourceTypeKind.EntityType);
                 flag3          |= flag5;
                 flag2          |= type2.HasNamedStreamsDeclaredOnThisType | flag5;
                 metadataVersion = WebUtil.RaiseVersion(metadataVersion, type2.MetadataVersion);
                 isOpenType     |= type2.IsOpenType;
                 if (((epmMinimumDataServiceProtocolVersion == DataServiceProtocolVersion.V3) && (metadataVersion == RequestDescription.Version3Dot0)) && (flag2 && isOpenType))
                 {
                     break;
                 }
             }
         }
         this.hasEntityPropertyMappings = hasEntityPropertyMappings;
         this.epmMinDSPV = new DataServiceProtocolVersion?(epmMinimumDataServiceProtocolVersion);
         this.hasNavigationPropertyOrNamedStreamOnDerivedTypes = flag2;
         this.hasAccessibleNavigationProperty = flag3;
         this.hasOpenTypes    = isOpenType;
         this.metadataVersion = metadataVersion;
     }
 }
Exemple #9
0
        internal ResourceSetWrapper GetResultSet(DataServiceProviderWrapper provider, ResourceSetWrapper bindingSet)
        {
            if (this.resourceSet != null)
            {
                return(this.resourceSet);
            }
            if (this.ResultSetPathExpression == null)
            {
                return(null);
            }
            if (bindingSet == null)
            {
                throw new InvalidOperationException(System.Data.Services.Strings.OperationWrapper_PathExpressionRequiresBindingSet(this.Name));
            }
            ResourceSetWrapper targetSet = this.ResultSetPathExpression.GetTargetSet(provider, bindingSet);

            if (targetSet == null)
            {
                throw new InvalidOperationException(System.Data.Services.Strings.OperationWrapper_TargetSetFromPathExpressionNotNotVisible(this.Name, this.ResultSetPathExpression.PathExpression, bindingSet.Name));
            }
            return(targetSet);
        }
        /// <summary>
        /// Apply the given configuration to the resource set.
        /// </summary>
        /// <param name="configuration">data service configuration instance.</param>
        /// <param name="provider">data service provider wrapper instance for accessibility validation.</param>
        public void ApplyConfiguration(DataServiceConfiguration configuration, DataServiceProviderWrapper provider)
        {
#if DEBUG
            Debug.Assert(!this.isReadOnly, "Can only apply the configuration once.");
#endif
            this.rights = configuration.GetServiceOperationRights(this.serviceOperation);

            if ((this.rights & ~ServiceOperationRights.OverrideEntitySetRights) != ServiceOperationRights.None)
            {
                if (this.serviceOperation.ResourceSet != null)
                {
                    // If the result type is an entity type, we need to make sure its entity set is visible.
                    // If the entity set is hidden, we need to make sure that we throw an exception.
                    this.resourceSet = provider.TryResolveResourceSet(this.serviceOperation.ResourceSet.Name);
                    if (this.resourceSet == null)
                    {
                        throw new InvalidOperationException(Strings.BaseServiceProvider_ServiceOperationTypeHasNoContainer(this.serviceOperation.Name, this.serviceOperation.ResultType.FullName));
                    }
                }
            }
#if DEBUG
            this.isReadOnly = true;
#endif
        }
Exemple #11
0
 internal void InitializePathSegments(DataServiceProviderWrapper provider)
 {
     if (this.pathSegments == null)
     {
         string[]     strArray      = this.pathExpression.Split(new char[] { '/' });
         ResourceType parameterType = this.bindingParameter.ParameterType;
         if (parameterType.ResourceTypeKind == ResourceTypeKind.EntityCollection)
         {
             parameterType = ((EntityCollectionResourceType)this.bindingParameter.ParameterType).ItemType;
         }
         List <PathSegment> list = new List <PathSegment>();
         PathSegment        item = new PathSegment {
             SourceType = parameterType
         };
         bool flag   = false;
         int  length = strArray.Length;
         if (length == 1)
         {
             list.Add(item);
         }
         else
         {
             for (int i = 1; i < length; i++)
             {
                 string str = strArray[i];
                 if (string.IsNullOrEmpty(str))
                 {
                     throw new InvalidOperationException(Strings.ResourceSetPathExpression_EmptySegment(this.pathExpression));
                 }
                 ResourceProperty property = item.SourceType.TryResolvePropertyName(str);
                 if (property == null)
                 {
                     bool         previousSegmentIsTypeSegment = flag;
                     ResourceType type2 = WebUtil.ResolveTypeIdentifier(provider, str, item.SourceType, previousSegmentIsTypeSegment);
                     if (type2 == null)
                     {
                         throw new InvalidOperationException(Strings.ResourceSetPathExpression_PropertyNotFound(this.pathExpression, str, item.SourceType.FullName));
                     }
                     item.SourceType = type2;
                     flag            = true;
                     if (i == (length - 1))
                     {
                         throw new InvalidOperationException(Strings.ResourceSetPathExpression_PathCannotEndWithTypeIdentifier(this.pathExpression, strArray[length - 1]));
                     }
                 }
                 else
                 {
                     flag          = false;
                     item.Property = property;
                     list.Add(item);
                     item = new PathSegment {
                         SourceType = property.ResourceType
                     };
                 }
                 if (item.SourceType.ResourceTypeKind != ResourceTypeKind.EntityType)
                 {
                     throw new InvalidOperationException(Strings.ResourceSetPathExpression_PropertyMustBeEntityType(this.pathExpression, str, item.SourceType.FullName));
                 }
             }
         }
         this.pathSegments = list.ToArray();
     }
 }
Exemple #12
0
 private static void AssertCacheNotPreloaded(DataServiceProviderWrapper wrapper)
 {
 }
        internal void ApplyWildcardsAndSort(DataServiceProviderWrapper provider)
        {
            Func <ProjectionNode, bool> predicate = null;

            if (this.projectSubtree)
            {
                for (int i = this.nodes.Count - 1; i >= 0; i--)
                {
                    ExpandedProjectionNode node = this.nodes[i] as ExpandedProjectionNode;
                    if (node != null)
                    {
                        node.projectSubtree = true;
                        node.ApplyWildcardsAndSort(provider);
                    }
                    else
                    {
                        this.nodes.RemoveAt(i);
                    }
                }
                this.projectAllImmediateProperties = false;
                this.projectAllImmediateOperations = false;
            }
            else
            {
                for (int j = this.nodes.Count - 1; j >= 0; j--)
                {
                    ExpandedProjectionNode node2 = this.nodes[j] as ExpandedProjectionNode;
                    if (this.ProjectAllImmediateProperties && (node2 == null))
                    {
                        this.nodes.RemoveAt(j);
                    }
                    else if (node2 != null)
                    {
                        node2.ApplyWildcardsAndSort(provider);
                    }
                }
                if (this.nodes.Count > 0)
                {
                    List <System.Data.Services.Providers.ResourceType> resourceTypesInMetadataOrder = new List <System.Data.Services.Providers.ResourceType> {
                        this.ResourceType
                    };
                    if (predicate == null)
                    {
                        predicate = n => !System.Data.Services.Providers.ResourceType.CompareReferences(n.TargetResourceType, this.ResourceType);
                    }
                    List <ProjectionNode> source = this.nodes.Where <ProjectionNode>(predicate).ToList <ProjectionNode>();
                    if (source.Count > 0)
                    {
                        using (IEnumerator <System.Data.Services.Providers.ResourceType> enumerator = provider.GetDerivedTypes(this.ResourceType).GetEnumerator())
                        {
                            Func <ProjectionNode, bool> func = null;
                            System.Data.Services.Providers.ResourceType rt;
                            while (enumerator.MoveNext())
                            {
                                rt = enumerator.Current;
                                if (func == null)
                                {
                                    func = node => node.TargetResourceType == rt;
                                }
                                if (source.FirstOrDefault <ProjectionNode>(func) != null)
                                {
                                    resourceTypesInMetadataOrder.Add(rt);
                                }
                            }
                        }
                    }
                    this.nodes = SortNodes(this.nodes, resourceTypesInMetadataOrder);
                }
            }
        }
        internal static ResourceSetWrapper CreateResourceSetWrapper(System.Data.Services.Providers.ResourceSet resourceSet, DataServiceProviderWrapper provider, Func <System.Data.Services.Providers.ResourceType, System.Data.Services.Providers.ResourceType> resourceTypeValidator)
        {
            if (!resourceSet.IsReadOnly)
            {
                throw new DataServiceException(500, System.Data.Services.Strings.DataServiceProviderWrapper_ResourceContainerNotReadonly(resourceSet.Name));
            }
            ResourceSetWrapper wrapper = new ResourceSetWrapper(resourceSet);

            wrapper.ApplyConfiguration(provider.Configuration);
            if (!wrapper.IsVisible)
            {
                return(null);
            }
            wrapper.resourceType = resourceTypeValidator(resourceSet.ResourceType);
            return(wrapper);
        }
 internal IEnumerable <ResourceProperty> GetEntitySerializableProperties(DataServiceProviderWrapper provider, System.Data.Services.Providers.ResourceType entityType)
 {
     return(this.InitializeResourcePropertyCache(provider, entityType).Properties);
 }
 private IEnumerable <ResourceProperty> GetEntitySerializablePropertiesDeclaredOnTheResourceType(DataServiceProviderWrapper provider, System.Data.Services.Providers.ResourceType entityType)
 {
     return(this.InitializeResourcePropertyCache(provider, entityType).PropertiesDeclaredOnTheType);
 }
 internal DataServiceProtocolVersion VerifyEpmProtocolVersion(DataServiceProviderWrapper provider)
 {
     this.CheckHierarchy(provider);
     return(this.epmMinDSPV.Value);
 }
 internal bool HasAccessibleNavigationProperty(DataServiceProviderWrapper provider)
 {
     this.CheckHierarchy(provider);
     return(this.hasAccessibleNavigationProperty);
 }
 internal bool HasNavigationPropertyOrNamedStreamsOnDerivedTypes(DataServiceProviderWrapper provider)
 {
     this.CheckHierarchy(provider);
     return(this.hasNavigationPropertyOrNamedStreamOnDerivedTypes);
 }
 internal bool HasEntityPropertyMappings(DataServiceProviderWrapper provider)
 {
     this.CheckHierarchy(provider);
     return(this.hasEntityPropertyMappings);
 }