Exemplo n.º 1
0
        public static DataServiceProtocolVersion CalculateEntityPropertyMappingProtocolVersion(this EntityType entityType, VersionCalculationType calculationType, string contentType, DataServiceProtocolVersion maxProtocolVersion, DataServiceProtocolVersion maxDataServiceVersion)
        {
            ExceptionUtilities.CheckArgumentNotNull(entityType, "entityType");
            ExceptionUtilities.CheckArgumentNotNull(contentType, "contentType");
#if !WINDOWS_PHONE
            ExceptionUtilities.Assert(calculationType == VersionCalculationType.Metadata || maxProtocolVersion != DataServiceProtocolVersion.Unspecified, "Max protocol version cannot be unspecified for non-metadata cases");
#endif

            return(DataServiceProtocolVersion.V4);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Calculates the data service protocol version of the EntityType
        /// </summary>
        /// <param name="entityType">EntityType to determine version of</param>
        /// <param name="contentType">The content type of the request/response</param>
        /// <param name="calculationType">The type of version calculation</param>
        /// <param name="maxProtocolVersion">The max protocol version of the service</param>
        /// <param name="maxDataServiceVersion">The max data service version header value</param>
        /// <returns>Version of EntityType</returns>
        internal static DataServiceProtocolVersion CalculateProtocolVersion(this EntityType entityType, string contentType, VersionCalculationType calculationType, DataServiceProtocolVersion maxProtocolVersion, DataServiceProtocolVersion maxDataServiceVersion)
        {
            ExceptionUtilities.CheckArgumentNotNull(entityType, "entityType");
            ExceptionUtilities.CheckArgumentNotNull(contentType, "contentType");

            DataServiceProtocolVersion expectedVersion = DataServiceProtocolVersion.V4;

            // for requests, the type does not actually cause a version bump. Only what is actually used in the uri or payload will cause it.
            if (calculationType == VersionCalculationType.Request)
            {
                return(expectedVersion);
            }

            // multivalue, stream, spatial and other data-type versioning is handled this way
            var versionFromProperties = DataTypes.EntityType.WithDefinition(entityType).CalculateDataTypeVersion();

            expectedVersion = expectedVersion.IncreaseVersionIfRequired(versionFromProperties);

            // If there are relationships and includeRels = true then at least v3
            if (entityType.AllNavigationProperties.Any())
            {
                bool?includeAssociationLinks = null;
                var  dataServiceBehavior     = entityType.Model.GetDefaultEntityContainer().GetDataServiceBehavior();
                if (dataServiceBehavior != null)
                {
                    includeAssociationLinks = dataServiceBehavior.IncludeAssociationLinksInResponse;
                }

                if (includeAssociationLinks == true)
                {
                    expectedVersion = VersionHelper.IncreaseVersionIfRequired(expectedVersion, DataServiceProtocolVersion.V4);
                }
            }

            // Calculate expected version based on type's feed mappings.
            expectedVersion = VersionHelper.IncreaseVersionIfRequired(expectedVersion, VersionHelper.CalculateEntityPropertyMappingProtocolVersion(entityType, calculationType, contentType, maxProtocolVersion, maxDataServiceVersion));

            // open types get aggressively versioned due to potentially higher-version property types being returned
            if (entityType.IsOpen)
            {
                expectedVersion = VersionHelper.IncreaseVersionIfRequired(expectedVersion, VersionHelper.GetMinimumVersion(maxProtocolVersion, maxDataServiceVersion));
            }

            return(expectedVersion);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Calculates the min entityPropertyMapping Version
        /// </summary>
        /// <param name="entitySet">Entity Set to get the min value from</param>
        /// <param name="calculationType">Calculation Type</param>
        /// <param name="contentType">Content Type of the request</param>
        /// <param name="maxProtocolVersion">Max Protocol Version</param>
        /// <param name="maxDataServiceVersion">Max Data Service Version</param>
        /// <returns>Min version</returns>
        public static DataServiceProtocolVersion CalculateMinEntityPropertyMappingVersion(this EntitySet entitySet, VersionCalculationType calculationType, string contentType, DataServiceProtocolVersion maxProtocolVersion, DataServiceProtocolVersion maxDataServiceVersion)
        {
            IEnumerable <EntityType> entityTypes = VersionHelper.GetEntityTypes(entitySet);

            return(VersionHelper.GetMaximumVersion(entityTypes.Select(et => et.CalculateEntityPropertyMappingProtocolVersion(calculationType, contentType, maxProtocolVersion, maxDataServiceVersion)).ToArray()));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Calculates the protocol version of the EntitySet
        /// </summary>
        /// <param name="entitySet">EntitySet to determine the version of</param>
        /// <param name="contentType">Content Type of the request being made</param>
        /// <param name="calculationType">Calculation type to use, response, request, or metadata</param>
        /// <param name="maxProtocolVersion">max Protocol version of the service</param>
        /// <param name="maxDataServiceVersion">The max data service version of the request</param>
        /// <returns>Data Service Protocol version of the EntitySet</returns>
        public static DataServiceProtocolVersion CalculateEntitySetProtocolVersion(this EntitySet entitySet, string contentType, VersionCalculationType calculationType, DataServiceProtocolVersion maxProtocolVersion, DataServiceProtocolVersion maxDataServiceVersion)
        {
            ExceptionUtilities.CheckArgumentNotNull(entitySet, "entitySet");
            ExceptionUtilities.CheckArgumentNotNull(contentType, "contentType");

            DataServiceProtocolVersion expectedVersion = DataServiceProtocolVersion.V4;
            List <EntityType>          entityTypes     = entitySet.Container.Model.EntityTypes.Where(et => et.GetRootType() == entitySet.EntityType).ToList();

            foreach (EntityType entityType in entityTypes)
            {
                expectedVersion = VersionHelper.IncreaseVersionIfRequired(expectedVersion, entityType.CalculateProtocolVersion(contentType, calculationType, maxProtocolVersion, maxDataServiceVersion));
            }

            return(expectedVersion);
        }