示例#1
0
        /// <summary>Whether the types contained in the set have named streams or not</summary>
        /// <param name="provider">Data service provider instance.</param>
        private void CheckHierarchy(DataServiceProviderWrapper provider)
        {
#if DEBUG
            Debug.Assert(provider != null, "provider != null");
            Debug.Assert(this.resourceSet != null, "this.resourceSet != null");
            Debug.Assert(this.isReadOnly, "this.isReadOnly - entity set settings not initialized.");
#endif

            // Go through all types contained in the set.
            //  Find the maximum of minimum DSPVs required for resource types.
            //  If any one type has collection properties, the whole set has them.
            //  If any one type has named streams, the whole set has them.
            ResourceType baseType = this.resourceSet.ResourceType;
            bool         hasNavigationPropertyOrNamedStreamOnDerivedType = false;
            bool         hasNavigationProperty = this.GetEntitySerializableProperties(provider, baseType).Any(p => p.TypeKind == ResourceTypeKind.EntityType);
            bool         hasOpenType           = baseType.IsOpenType;
            this.hasDerivedTypes = provider.HasDerivedTypes(baseType);
            Version resourceSetVersion = baseType.MetadataVersion;

            // If we have all the V3 features or no derived types then we do not need to look any further
            if (this.hasDerivedTypes)
            {
                foreach (ResourceType derivedType in provider.GetDerivedTypes(baseType))
                {
                    bool hasNavigationPropertyOnDerivedType = this.GetEntitySerializablePropertiesDeclaredOnTheResourceType(provider, derivedType).Any(p => p.TypeKind == ResourceTypeKind.EntityType);
                    hasNavigationProperty |= hasNavigationPropertyOnDerivedType;
                    hasNavigationPropertyOrNamedStreamOnDerivedType |= derivedType.HasNamedStreamsDeclaredOnThisType | hasNavigationPropertyOnDerivedType;

                    resourceSetVersion = VersionUtil.RaiseVersion(resourceSetVersion, derivedType.MetadataVersion);

                    hasOpenType |= derivedType.IsOpenType;

                    // If we have all the V3(latest) features we do not need to look any further
                    if (resourceSetVersion == VersionUtil.Version4Dot0 &&
                        hasNavigationPropertyOrNamedStreamOnDerivedType &&
                        hasOpenType)
                    {
                        break;
                    }
                }
            }

            this.hasAccessibleNavigationProperty = hasNavigationProperty;
            this.hasOpenTypes    = hasOpenType;
            this.metadataVersion = resourceSetVersion;
        }
示例#2
0
 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;
     }
 }
示例#3
0
 internal static bool HasMediaLinkEntryInHierarchy(ResourceType baseType, DataServiceProviderWrapper provider)
 {
     return(baseType.IsMediaLinkEntry || provider.GetDerivedTypes(baseType).Any <ResourceType>(derivedType => derivedType.IsMediaLinkEntry));
 }
        /// <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;
        }
示例#5
0
 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);
         }
     }
 }
        /// <summary>Removes duplicates from the tree caused by wildcards and sorts the projected properties.</summary>
        /// <param name="provider">underlying provider instance.</param>
        /// <remarks>
        /// Examples
        /// $select=Orders, Orders/ID           - get rid of the Orders/ID
        /// $select=Orders, Orders/*            - get rid of the Orders/*
        /// $select=Orders/*, Orders/ID         - get rid of the Orders/ID
        /// $select=Orders/*, Orders/OrderItems&amp;$expand=Orders - get rid of the Orders/OrderItems (it's redundant to *)
        /// $select=Orders/*, Orders/OrderItems&amp;$expand=Orders/OrderItems - leave as is, the Orders/OrderItems are expanded
        /// 
        /// The sorting order is the same as the order in which the properties are enumerated on the owning type.
        /// This is to preserve the same order as if no projections occured.
        /// </remarks>
        internal void ApplyWildcardsAndSort(DataServiceProviderWrapper provider)
        {
            // If this segment was marked to include entire subtree
            // simply remove all children which are not expanded
            // and propagate the information to all expanded children.
            if (this.projectSubtree)
            {
                for (int j = this.nodes.Count - 1; j >= 0; j--)
                {
                    ExpandedProjectionNode expandedNode = this.nodes[j] as ExpandedProjectionNode;
                    if (expandedNode != null)
                    {
                        expandedNode.projectSubtree = true;
                        expandedNode.ApplyWildcardsAndSort(provider);
                    }
                }

                this.projectAllImmediateProperties = false;
                this.projectAllImmediateOperations = false;
                return;
            }

            for (int j = this.nodes.Count - 1; j >= 0; j--)
            {
                ExpandedProjectionNode expandedNode = this.nodes[j] as ExpandedProjectionNode;

                // If this node was marked to include all immediate properties, 
                //   remove all children which are not expanded.
                //   That means they are either simple properties or nav. properties which
                //   are not going to be expanded anyway.
                if (this.ProjectAllImmediateProperties && expandedNode == null)
                {
                    this.nodes.RemoveAt(j);
                }
                else if (expandedNode != null)
                {
                    expandedNode.ApplyWildcardsAndSort(provider);
                }
            }

            if (this.nodes.Count > 0)
            {
                // Sort the subsegments such that they have the same order as the properties
                //   on the owning resource type.

                // build the list of existing resource types that this query touches
                List<ResourceType> resourceTypes = new List<ResourceType>();
                resourceTypes.Add(this.ResourceType);

                // If we have one or more derived properties to expand or project,
                // we need to sort it based on the order in which the derived types
                // are return.
                List<ProjectionNode> derivedProjectionNodes = this.nodes.Where(n => !ResourceType.CompareReferences(n.TargetResourceType, this.ResourceType)).ToList();
                if (derivedProjectionNodes.Count > 0)
                {
                    foreach (ResourceType rt in provider.GetDerivedTypes(this.ResourceType))
                    {
                        if (derivedProjectionNodes.FirstOrDefault(node => node.TargetResourceType == rt) != null)
                        {
                            resourceTypes.Add(rt);
                        }
                    }
                }

#if DEBUG
                int count = this.nodes.Count;
#endif
                this.nodes = ExpandedProjectionNode.SortNodes(this.nodes, resourceTypes);
#if DEBUG
                Debug.Assert(this.nodes.Count == count, "We didn't sort all the properties.");
#endif
            }
        }
        /// <summary>Removes duplicates from the tree caused by wildcards and sorts the projected properties.</summary>
        /// <param name="provider">underlying provider instance.</param>
        /// <remarks>
        /// Examples
        /// $select=Orders, Orders/ID           - get rid of the Orders/ID
        /// $select=Orders, Orders/*            - get rid of the Orders/*
        /// $select=Orders/*, Orders/ID         - get rid of the Orders/ID
        /// $select=Orders/*, Orders/OrderItems&amp;$expand=Orders - get rid of the Orders/OrderItems (it's redundant to *)
        /// $select=Orders/*, Orders/OrderItems&amp;$expand=Orders/OrderItems - leave as is, the Orders/OrderItems are expanded
        ///
        /// The sorting order is the same as the order in which the properties are enumerated on the owning type.
        /// This is to preserve the same order as if no projections occured.
        /// </remarks>
        internal void ApplyWildcardsAndSort(DataServiceProviderWrapper provider)
        {
            // If this segment was marked to include entire subtree
            // simply remove all children which are not expanded
            // and propagate the information to all expanded children.
            if (this.projectSubtree)
            {
                for (int j = this.nodes.Count - 1; j >= 0; j--)
                {
                    ExpandedProjectionNode expandedNode = this.nodes[j] as ExpandedProjectionNode;
                    if (expandedNode != null)
                    {
                        expandedNode.projectSubtree = true;
                        expandedNode.ApplyWildcardsAndSort(provider);
                    }
                }

                this.projectAllImmediateProperties = false;
                this.projectAllImmediateOperations = false;
                return;
            }

            for (int j = this.nodes.Count - 1; j >= 0; j--)
            {
                ExpandedProjectionNode expandedNode = this.nodes[j] as ExpandedProjectionNode;

                // If this node was marked to include all immediate properties,
                //   remove all children which are not expanded.
                //   That means they are either simple properties or nav. properties which
                //   are not going to be expanded anyway.
                if (this.ProjectAllImmediateProperties && expandedNode == null)
                {
                    this.nodes.RemoveAt(j);
                }
                else if (expandedNode != null)
                {
                    expandedNode.ApplyWildcardsAndSort(provider);
                }
            }

            if (this.nodes.Count > 0)
            {
                // Sort the subsegments such that they have the same order as the properties
                //   on the owning resource type.

                // build the list of existing resource types that this query touches
                List <ResourceType> resourceTypes = new List <ResourceType>();
                resourceTypes.Add(this.ResourceType);

                // If we have one or more derived properties to expand or project,
                // we need to sort it based on the order in which the derived types
                // are return.
                List <ProjectionNode> derivedProjectionNodes = this.nodes.Where(n => !ResourceType.CompareReferences(n.TargetResourceType, this.ResourceType)).ToList();
                if (derivedProjectionNodes.Count > 0)
                {
                    foreach (ResourceType rt in provider.GetDerivedTypes(this.ResourceType))
                    {
                        if (derivedProjectionNodes.FirstOrDefault(node => node.TargetResourceType == rt) != null)
                        {
                            resourceTypes.Add(rt);
                        }
                    }
                }

#if DEBUG
                int count = this.nodes.Count;
#endif
                this.nodes = ExpandedProjectionNode.SortNodes(this.nodes, resourceTypes);
#if DEBUG
                Debug.Assert(this.nodes.Count == count, "We didn't sort all the properties.");
#endif
            }
        }
示例#8
0
        /// <summary>Whether the types contained in the set have named streams or not</summary>
        /// <param name="provider">Data service provider instance.</param>
        private void CheckHierarchy(DataServiceProviderWrapper provider)
        {
#if DEBUG
            Debug.Assert(provider != null, "provider != null");
            Debug.Assert(this.resourceSet != null, "this.resourceSet != null");
            Debug.Assert(this.isReadOnly, "this.isReadOnly - entity set settings not initialized.");
#endif

            // Go through all types contained in the set.
            //  Find the maximum of minimum DSPVs required for resource types.
            //  If any one type has collection properties, the whole set has them.
            //  If any one type has named streams, the whole set has them.
            ResourceType baseType = this.resourceSet.ResourceType;
            bool hasNavigationPropertyOrNamedStreamOnDerivedType = false;
            bool hasNavigationProperty = this.GetEntitySerializableProperties(provider, baseType).Any(p => p.TypeKind == ResourceTypeKind.EntityType);
            bool hasOpenType = baseType.IsOpenType;
            this.hasDerivedTypes = provider.HasDerivedTypes(baseType);
            Version resourceSetVersion = baseType.MetadataVersion;

            // If we have all the V3 features or no derived types then we do not need to look any further
            if (this.hasDerivedTypes)
            {
                foreach (ResourceType derivedType in provider.GetDerivedTypes(baseType))
                {
                    bool hasNavigationPropertyOnDerivedType = this.GetEntitySerializablePropertiesDeclaredOnTheResourceType(provider, derivedType).Any(p => p.TypeKind == ResourceTypeKind.EntityType);
                    hasNavigationProperty |= hasNavigationPropertyOnDerivedType;
                    hasNavigationPropertyOrNamedStreamOnDerivedType |= derivedType.HasNamedStreamsDeclaredOnThisType | hasNavigationPropertyOnDerivedType;

                    resourceSetVersion = VersionUtil.RaiseVersion(resourceSetVersion, derivedType.MetadataVersion);

                    hasOpenType |= derivedType.IsOpenType;

                    // If we have all the V3(latest) features we do not need to look any further
                    if (resourceSetVersion == VersionUtil.Version4Dot0 &&
                        hasNavigationPropertyOrNamedStreamOnDerivedType &&
                        hasOpenType)
                    {
                        break;
                    }
                }
            }

            this.hasAccessibleNavigationProperty = hasNavigationProperty;
            this.hasOpenTypes = hasOpenType;
            this.metadataVersion = resourceSetVersion;
        }