/// <summary>Gets the appropriate DataServiceVersion string for the metadata in the specified <paramref name="types"/>.</summary> /// <param name="types">Types to get version information for.</param> /// <param name="metadataEdmSchemaVersion">EDM schema version for metadata document.</param> /// <returns>The DataServiceVersion string for the metadata, possibly null.</returns> /// <remarks> /// This method should really hinge on the IDataServiceMetadataProvider, but this provides a convenient /// way of ensuring way enumerate types a single time, by allowing callers to cache /// the Types enumeration request. /// </remarks> internal static string GetVersionsForMetadata(IEnumerable<ResourceType> types, ref MetadataEdmSchemaVersion metadataEdmSchemaVersion) { Debug.Assert(types != null, "types != null"); String dataServiceVersion = XmlConstants.DataServiceVersion1Dot0; foreach (ResourceType type in types) { Debug.Assert(type.EpmInfoInitialized, "type.EpmInfoInitialized -- otherwise the call is too soon to determine version."); if (!type.EpmIsV1Compatible) { dataServiceVersion = XmlConstants.DataServiceVersion2Dot0; } // Open types force schema version to be 1.2. if (type.IsOpenType) { if (metadataEdmSchemaVersion < MetadataEdmSchemaVersion.Version1Dot2) { metadataEdmSchemaVersion = MetadataEdmSchemaVersion.Version1Dot2; } // Since we have set both versions to their max values, we can leave the function immediately. if (dataServiceVersion == XmlConstants.DataServiceVersion2Dot0) { break; } Debug.Assert(dataServiceVersion == XmlConstants.DataServiceVersion1Dot0, "Version is either 1.0 or 2.0 for DataService"); } } return dataServiceVersion; }
/// <summary>Updates the EDM schema version if it is currently lower than <paramref name="newVersion"/>.</summary> /// <param name="newVersion">New version for EDM schema.</param> private void UpdateEdmSchemaVersion(MetadataEdmSchemaVersion newVersion) { if (this.metadata.EdmSchemaVersion < newVersion) { this.metadata.EdmSchemaVersion = newVersion; } }
private ResourceType(Type type, ResourceType baseType, string namespaceName, string name, bool isAbstract) { this.lockPropertiesLoad = new object(); this.propertyInfosDeclaredOnThisType = new Dictionary<ResourceProperty, ResourcePropertyInfo>(ReferenceEqualityComparer<ResourceProperty>.Instance); this.schemaVersion = ~MetadataEdmSchemaVersion.Version1Dot0; WebUtil.CheckArgumentNull<Type>(type, "type"); WebUtil.CheckArgumentNull<string>(name, "name"); this.name = name; this.namespaceName = namespaceName ?? string.Empty; if ((name == "String") && object.ReferenceEquals(namespaceName, "Edm")) { this.fullName = "Edm.String"; } else { this.fullName = string.IsNullOrEmpty(namespaceName) ? name : (namespaceName + "." + name); } this.type = type; this.abstractType = isAbstract; this.canReflectOnInstanceType = true; if (baseType != null) { this.baseType = baseType; } }
private ResourceType(Type type, ResourceType baseType, string namespaceName, string name, bool isAbstract) { this.lockPropertiesLoad = new object(); this.propertyInfosDeclaredOnThisType = new Dictionary <ResourceProperty, ResourcePropertyInfo>(ReferenceEqualityComparer <ResourceProperty> .Instance); this.schemaVersion = ~MetadataEdmSchemaVersion.Version1Dot0; WebUtil.CheckArgumentNull <Type>(type, "type"); WebUtil.CheckArgumentNull <string>(name, "name"); this.name = name; this.namespaceName = namespaceName ?? string.Empty; if ((name == "String") && object.ReferenceEquals(namespaceName, "Edm")) { this.fullName = "Edm.String"; } else { this.fullName = string.IsNullOrEmpty(namespaceName) ? name : (namespaceName + "." + name); } this.type = type; this.abstractType = isAbstract; this.canReflectOnInstanceType = true; if (baseType != null) { this.baseType = baseType; } }
internal static MetadataEdmSchemaVersion RaiseVersion(MetadataEdmSchemaVersion versionToRaise, MetadataEdmSchemaVersion targetVersion) { if (targetVersion <= versionToRaise) { return(versionToRaise); } return(targetVersion); }
internal MetadataEdmSchemaVersion GetMetadataEdmSchemaVersion(DataServiceOperationContext operationContext) { this.GetMetadataVersion(operationContext); ObjectContextServiceProvider metadataProvider = this.metadataProvider as ObjectContextServiceProvider; if (metadataProvider != null) { this.edmSchemaVersion = WebUtil.RaiseMetadataEdmSchemaVersion(this.edmSchemaVersion, metadataProvider.EdmSchemaVersion); } return(this.edmSchemaVersion); }
internal Version GetMetadataVersion(DataServiceOperationContext operationContext) { if (this.responseMetadataVersion == null) { RequestDescription.UpdateMetadataVersion(this, operationContext, out this.responseMetadataVersion, out this.edmSchemaVersion); } this.responseMetadataVersion = WebUtil.RaiseVersion(this.responseMetadataVersion, operationContext.Host.RequestMinVersion); if (this.responseMetadataVersion == RequestDescription.Version3Dot0) { this.edmSchemaVersion = WebUtil.RaiseMetadataEdmSchemaVersion(this.edmSchemaVersion, MetadataEdmSchemaVersion.Version3Dot0); } return(this.responseMetadataVersion); }
internal DataServiceProviderWrapper(DataServiceCacheItem cacheItem, IDataServiceMetadataProvider metadataProvider, IDataServiceQueryProvider queryProvider, IDataService dataService) { this.metadata = cacheItem; this.metadataProvider = metadataProvider; this.queryProvider = queryProvider; this.dataService = dataService; this.operationWrapperCache = new Dictionary <string, OperationWrapper>(EqualityComparer <string> .Default); this.metadataProviderEdmModels = new Dictionary <DataServiceOperationContext, MetadataProviderEdmModel>(EqualityComparer <DataServiceOperationContext> .Default); this.models = new Dictionary <DataServiceOperationContext, IEdmModel>(EqualityComparer <DataServiceOperationContext> .Default); this.edmSchemaVersion = MetadataEdmSchemaVersion.Version1Dot0; this.containerNameCache = null; this.containerNamespaceCache = null; }
private void InitializeMetadataAndSchemaVersionForComplexOrEntityType() { MetadataEdmSchemaVersion version3; Version versionToRaise = RequestDescription.Version1Dot0; MetadataEdmSchemaVersion schemaVersion = MetadataEdmSchemaVersion.Version1Dot0; if (this.baseType != null) { versionToRaise = this.baseType.MetadataVersion; schemaVersion = this.baseType.SchemaVersion; } versionToRaise = WebUtil.RaiseVersion(versionToRaise, this.ComputeMetadataAndSchemaVersionForPropertyCollection(this.PropertiesDeclaredOnThisType, null, out version3)); schemaVersion = WebUtil.RaiseVersion(schemaVersion, version3); this.metadataVersion = versionToRaise; this.schemaVersion = schemaVersion; }
private void InitializeMetadataAndSchemaVersionForPrimitiveType() { if (this.type == typeof(Stream)) { this.metadataVersion = RequestDescription.Version3Dot0; this.schemaVersion = MetadataEdmSchemaVersion.Version3Dot0; } else if (typeof(ISpatial).IsAssignableFrom(this.type)) { this.metadataVersion = RequestDescription.Version3Dot0; this.schemaVersion = MetadataEdmSchemaVersion.Version3Dot0; } else { this.metadataVersion = RequestDescription.Version1Dot0; this.schemaVersion = MetadataEdmSchemaVersion.Version1Dot0; } }
internal static Version ToVersion(this MetadataEdmSchemaVersion schemaVersion) { switch (schemaVersion) { case MetadataEdmSchemaVersion.Version1Dot0: return(Version1Dot0); case MetadataEdmSchemaVersion.Version1Dot1: return(Version1Dot1); case MetadataEdmSchemaVersion.Version1Dot2: return(Version1Dot2); case MetadataEdmSchemaVersion.Version2Dot0: return(Version2Dot0); case MetadataEdmSchemaVersion.Version3Dot0: return(Version3Dot0); } return(Version3Dot0); }
private void InitializeMetadataAndSchemaVersionForEntityCollectionType() { this.metadataVersion = RequestDescription.Version1Dot0; this.schemaVersion = MetadataEdmSchemaVersion.Version1Dot0; }
private Version ComputeMetadataAndSchemaVersionForPropertyCollection(IEnumerable<ResourceProperty> propertyCollection, HashSet<ResourceType> visitedComplexTypes, out MetadataEdmSchemaVersion propertySchemaVersion) { Version versionToRaise = RequestDescription.Version1Dot0; propertySchemaVersion = MetadataEdmSchemaVersion.Version1Dot0; foreach (ResourceProperty property in propertyCollection) { if (property.IsOfKind(ResourcePropertyKind.ComplexType)) { MetadataEdmSchemaVersion version2; if (visitedComplexTypes == null) { visitedComplexTypes = new HashSet<ResourceType>(ReferenceEqualityComparer<ResourceType>.Instance); } else if (visitedComplexTypes.Contains(property.ResourceType)) { continue; } visitedComplexTypes.Add(property.ResourceType); versionToRaise = WebUtil.RaiseVersion(versionToRaise, this.ComputeMetadataAndSchemaVersionForPropertyCollection(property.ResourceType.PropertiesDeclaredOnThisType, visitedComplexTypes, out version2)); propertySchemaVersion = WebUtil.RaiseVersion(propertySchemaVersion, version2); } else if ((property.IsOfKind(ResourcePropertyKind.Primitive) || property.IsOfKind(ResourcePropertyKind.Collection)) || property.IsOfKind(ResourcePropertyKind.Stream)) { versionToRaise = WebUtil.RaiseVersion(versionToRaise, property.ResourceType.MetadataVersion); propertySchemaVersion = WebUtil.RaiseVersion(propertySchemaVersion, property.ResourceType.SchemaVersion); } } return versionToRaise; }
/// <summary> /// Initialize metadata and schema version for this primitive resource type. /// </summary> private void InitializeMetadataAndSchemaVersionForPrimitiveType() { Debug.Assert(this.resourceTypeKind == ResourceTypeKind.Primitive, "This method only works on primitive types."); Debug.Assert(this.metadataVersion == null, "this.metadataVersion == null"); Debug.Assert(this.schemaVersion == (MetadataEdmSchemaVersion)(-1), "this.schemaVersion == (MetadataEdmSchemaVersion)(-1)"); this.metadataVersion = VersionUtil.Version4Dot0; this.schemaVersion = MetadataEdmSchemaVersion.Version4Dot0; }
internal static void UpdateMetadataVersion(DataServiceProviderWrapper provider, DataServiceOperationContext operationContext, out Version metadataVersion, out MetadataEdmSchemaVersion edmSchemaVersion) { metadataVersion = Version1Dot0; edmSchemaVersion = MetadataEdmSchemaVersion.Version1Dot0; if (!provider.IsV1Provider) { edmSchemaVersion = WebUtil.RaiseMetadataEdmSchemaVersion(edmSchemaVersion, MetadataEdmSchemaVersion.Version1Dot1); } foreach (ResourceType type in provider.GetVisibleTypes(operationContext)) { UpdateMetadataVersionForResourceType(type, ref metadataVersion, ref edmSchemaVersion); } if (provider.HasAnnotations(operationContext)) { edmSchemaVersion = WebUtil.RaiseMetadataEdmSchemaVersion(edmSchemaVersion, MetadataEdmSchemaVersion.Version3Dot0); } foreach (OperationWrapper wrapper in provider.GetVisibleOperations(operationContext)) { if (wrapper.Kind == OperationKind.Action) { edmSchemaVersion = WebUtil.RaiseMetadataEdmSchemaVersion(edmSchemaVersion, MetadataEdmSchemaVersion.Version3Dot0); metadataVersion = WebUtil.RaiseVersion(metadataVersion, Version3Dot0); break; } if (((wrapper.ResultKind == ServiceOperationResultKind.Void) || (wrapper.ResultKind == ServiceOperationResultKind.QueryWithSingleResult)) || (((wrapper.ResultKind == ServiceOperationResultKind.DirectValue) || (wrapper.ResultType.ResourceTypeKind == ResourceTypeKind.ComplexType)) || (wrapper.ResultType.ResourceTypeKind == ResourceTypeKind.Primitive))) { edmSchemaVersion = WebUtil.RaiseMetadataEdmSchemaVersion(edmSchemaVersion, MetadataEdmSchemaVersion.Version1Dot1); break; } } }
/// <summary> /// If necessary raises version to the version requested by the user. /// </summary> /// <param name="versionToRaise">Version to raise.</param> /// <param name="targetVersion">New version to raise to.</param> /// <returns>New version if the requested version is greater than the existing version.</returns> internal static MetadataEdmSchemaVersion RaiseVersion(MetadataEdmSchemaVersion versionToRaise, MetadataEdmSchemaVersion targetVersion) { return targetVersion > versionToRaise ? targetVersion : versionToRaise; }
/// <summary> /// Update the various versions based on the metadata of the given resource type /// </summary> /// <param name="resourceType">resource type whose metadata needs to be looked at.</param> /// <param name="metadataVersion">Reference to the metadata version to be updated.</param> /// <param name="edmSchemaVersion">Reference to the edm schema version to be updated.</param> private static void UpdateMetadataVersionForResourceType(ResourceType resourceType, ref Version metadataVersion, ref MetadataEdmSchemaVersion edmSchemaVersion) { // Raise the metadata version to the resource type metadata version. metadataVersion = RaiseVersion(metadataVersion, resourceType.MetadataVersion); // Raise the schema version to the resource type schema version. edmSchemaVersion = RaiseVersion(edmSchemaVersion, resourceType.SchemaVersion); }
/// <summary> /// Computes metadata and schema version for the given property collection. /// </summary> /// <param name="propertyCollection">List of resource properties whose metadata version needs to be calculated.</param> /// <param name="visitedComplexTypes">List of complex types visited.</param> /// <param name="propertySchemaVersion">Returns the schema version of the resource property collection.</param> /// <returns>The metadata version of the resource property collection.</returns> private Version ComputeMetadataAndSchemaVersionForPropertyCollection(IEnumerable<ResourceProperty> propertyCollection, HashSet<ResourceType> visitedComplexTypes, out MetadataEdmSchemaVersion propertySchemaVersion) { Version propertyMetadataVersion = VersionUtil.Version4Dot0; propertySchemaVersion = MetadataEdmSchemaVersion.Version4Dot0; foreach (ResourceProperty property in propertyCollection) { if (property.IsOfKind(ResourcePropertyKind.ComplexType)) { if (visitedComplexTypes == null) { visitedComplexTypes = new HashSet<ResourceType>(ReferenceEqualityComparer<ResourceType>.Instance); } else if (visitedComplexTypes.Contains(property.ResourceType)) { continue; } visitedComplexTypes.Add(property.ResourceType); // If the property is complex type property, raise the version to the version of complex type // To avoid endless loops in complex types, instead of calling Version property on complex type // we call this method which recursively walks through the tree and gets the max version for the // tree. Since the version is cached at the entity level, for every entity, we compute this once. // But this is not cached for complex type until the Version property on complex type is called // which happens when the request uri target is complex type. MetadataEdmSchemaVersion complexTypeSchemaVersion; propertyMetadataVersion = VersionUtil.RaiseVersion( propertyMetadataVersion, this.ComputeMetadataAndSchemaVersionForPropertyCollection(property.ResourceType.PropertiesDeclaredOnThisType, visitedComplexTypes, out complexTypeSchemaVersion)); propertySchemaVersion = VersionUtil.RaiseVersion(propertySchemaVersion, complexTypeSchemaVersion); } else if (property.IsOfKind(ResourcePropertyKind.Primitive) || property.IsOfKind(ResourcePropertyKind.Collection) || property.IsOfKind(ResourcePropertyKind.Stream)) { propertyMetadataVersion = VersionUtil.RaiseVersion(propertyMetadataVersion, property.ResourceType.MetadataVersion); propertySchemaVersion = VersionUtil.RaiseVersion(propertySchemaVersion, property.ResourceType.SchemaVersion); } } return propertyMetadataVersion; }
/// <summary> /// Initialize metadata and schema version for this resource type. /// </summary> private void InitializeMetadataAndSchemaVersionForComplexOrEntityType() { Debug.Assert(this.metadataVersion == null, "this.metadataVersion == null"); Debug.Assert(this.schemaVersion == (MetadataEdmSchemaVersion)(-1), "this.schemaVersion == (MetadataEdmSchemaVersion)(-1)"); Debug.Assert( this.resourceTypeKind == ResourceTypeKind.ComplexType || this.resourceTypeKind == ResourceTypeKind.EntityType, "This method only works on complex or entity types."); Version resourceTypeMetadataVersion = VersionUtil.Version4Dot0; MetadataEdmSchemaVersion resourceTypeSchemaVersion = MetadataEdmSchemaVersion.Version4Dot0; if (this.baseType != null) { resourceTypeMetadataVersion = this.baseType.MetadataVersion; resourceTypeSchemaVersion = this.baseType.SchemaVersion; } MetadataEdmSchemaVersion propertySchemaVersion; resourceTypeMetadataVersion = VersionUtil.RaiseVersion( resourceTypeMetadataVersion, this.ComputeMetadataAndSchemaVersionForPropertyCollection(this.PropertiesDeclaredOnThisType, null, out propertySchemaVersion)); resourceTypeSchemaVersion = VersionUtil.RaiseVersion(resourceTypeSchemaVersion, propertySchemaVersion); this.metadataVersion = resourceTypeMetadataVersion; this.schemaVersion = resourceTypeSchemaVersion; }
/// <summary> /// Initialize metadata and schema version for this entity collection resource type. /// </summary> private void InitializeMetadataAndSchemaVersionForEntityCollectionType() { Debug.Assert(this.resourceTypeKind == ResourceTypeKind.EntityCollection, "This method only works on entity collection types."); Debug.Assert(this.metadataVersion == null, "this.metadataVersion == null"); Debug.Assert(this.schemaVersion == (MetadataEdmSchemaVersion)(-1), "this.schemaVersion == (MetadataEdmSchemaVersion)(-1)"); this.metadataVersion = VersionUtil.Version4Dot0; this.schemaVersion = MetadataEdmSchemaVersion.Version4Dot0; }
/// <summary> /// Initialize metadata and schema version for this collection resource type. /// </summary> private void InitializeMetadataAndSchemaVersionForCollectionType() { Debug.Assert(this.resourceTypeKind == ResourceTypeKind.Collection, "This method only works on collection types."); Debug.Assert(this.metadataVersion == null, "this.metadataVersion == null"); Debug.Assert(this.schemaVersion == (MetadataEdmSchemaVersion)(-1), "this.schemaVersion == (MetadataEdmSchemaVersion)(-1)"); // Bump up the metadata version to 4.0 and schema version to 4.0 this.metadataVersion = VersionUtil.Version4Dot0; this.schemaVersion = MetadataEdmSchemaVersion.Version4Dot0; }
/// <summary> /// Writes the lop level schema element /// </summary> /// <param name="writer">xml writer into which the schema node definition is written to</param> /// <param name="schemaNamespace">namespace of the schema</param> /// <param name="metadataEdmSchemaVersion">Version of metadata schema.</param> internal static void WriteSchemaElement(XmlWriter writer, string schemaNamespace, MetadataEdmSchemaVersion metadataEdmSchemaVersion) { writer.WriteStartElement(XmlConstants.Schema, GetSchemaNamespace(metadataEdmSchemaVersion)); writer.WriteAttributeString(XmlConstants.Namespace, schemaNamespace); writer.WriteAttributeString(XmlConstants.XmlnsNamespacePrefix, XmlConstants.DataWebNamespacePrefix, null, XmlConstants.DataWebNamespace); writer.WriteAttributeString(XmlConstants.XmlnsNamespacePrefix, XmlConstants.DataWebMetadataNamespacePrefix, null, XmlConstants.DataWebMetadataNamespace); }
private Version ComputeMetadataAndSchemaVersionForPropertyCollection(IEnumerable <ResourceProperty> propertyCollection, HashSet <ResourceType> visitedComplexTypes, out MetadataEdmSchemaVersion propertySchemaVersion) { Version versionToRaise = RequestDescription.Version1Dot0; propertySchemaVersion = MetadataEdmSchemaVersion.Version1Dot0; foreach (ResourceProperty property in propertyCollection) { if (property.IsOfKind(ResourcePropertyKind.ComplexType)) { MetadataEdmSchemaVersion version2; if (visitedComplexTypes == null) { visitedComplexTypes = new HashSet <ResourceType>(ReferenceEqualityComparer <ResourceType> .Instance); } else if (visitedComplexTypes.Contains(property.ResourceType)) { continue; } visitedComplexTypes.Add(property.ResourceType); versionToRaise = WebUtil.RaiseVersion(versionToRaise, this.ComputeMetadataAndSchemaVersionForPropertyCollection(property.ResourceType.PropertiesDeclaredOnThisType, visitedComplexTypes, out version2)); propertySchemaVersion = WebUtil.RaiseVersion(propertySchemaVersion, version2); } else if ((property.IsOfKind(ResourcePropertyKind.Primitive) || property.IsOfKind(ResourcePropertyKind.Collection)) || property.IsOfKind(ResourcePropertyKind.Stream)) { versionToRaise = WebUtil.RaiseVersion(versionToRaise, property.ResourceType.MetadataVersion); propertySchemaVersion = WebUtil.RaiseVersion(propertySchemaVersion, property.ResourceType.SchemaVersion); } } return(versionToRaise); }
/// <summary>Gets the metadata document for this provider.</summary> /// <param name="metadataEdmSchemaVersion">EDM schema version.</param> /// <param name="service">Data service instance.</param> internal void GenerateMetadata(MetadataEdmSchemaVersion metadataEdmSchemaVersion, IDataService service) { Debug.Assert(this.Writer != null, "this.Writer != null"); Debug.Assert(this.Provider != null, "this.Provider != null"); MetadataManager metadataManager = new MetadataManager(this.Provider, service); string dataServiceVersion = MetadataSerializer.GetVersionsForMetadata(metadataManager.ResourceTypes, ref metadataEdmSchemaVersion); MetadataSerializer.WriteTopLevelSchemaElements(this.Writer, dataServiceVersion); HashSet<ResourceType> typesInEntityContainerNamespace = null; // Write the schema Element for every namespace foreach (KeyValuePair<string, HashSet<ResourceType>> namespaceAlongWithTypes in metadataManager.NamespaceAlongWithTypes) { Debug.Assert(!string.IsNullOrEmpty(namespaceAlongWithTypes.Key), "!string.IsNullOrEmpty(namespaceAlongWithTypes.Key)"); // If the types live in the same namespace as that of entity container and types that don't live in any namespace, // should be written out in the service namespace. If the service type also doesn't have a namespace, we will use // the service name as the namespace. See code below for that. if (namespaceAlongWithTypes.Key == metadataManager.GetContainerNamespace()) { typesInEntityContainerNamespace = namespaceAlongWithTypes.Value; } else { Dictionary<string, ResourceAssociationType> associationsInThisNamespace = metadataManager.GetAssociationTypesForNamespace(namespaceAlongWithTypes.Key); MetadataSerializer.WriteSchemaElement(this.Writer, namespaceAlongWithTypes.Key, metadataEdmSchemaVersion); WriteTypes(this.Writer, namespaceAlongWithTypes.Value, associationsInThisNamespace, metadataManager); WriteAssociationTypes(this.Writer, new HashSet<ResourceAssociationType>(associationsInThisNamespace.Values, EqualityComparer<ResourceAssociationType>.Default)); this.Writer.WriteEndElement(); } } // Write the entity container definition. Also if there are types in the same namespace, // we need to write them out too. string typeNamespace = metadataManager.GetContainerNamespace(); MetadataSerializer.WriteSchemaElement(this.Writer, typeNamespace, metadataEdmSchemaVersion); if (typesInEntityContainerNamespace != null) { Dictionary<string, ResourceAssociationType> associationsInThisNamespace = metadataManager.GetAssociationTypesForNamespace(typeNamespace); WriteTypes(this.Writer, typesInEntityContainerNamespace, associationsInThisNamespace, metadataManager); WriteAssociationTypes(this.Writer, new HashSet<ResourceAssociationType>(associationsInThisNamespace.Values, EqualityComparer<ResourceAssociationType>.Default)); } this.WriteEntityContainer(this.Writer, XmlConvert.EncodeName(this.Provider.ContainerName), metadataManager.ResourceSets, metadataManager.ResourceAssociationSets); this.Writer.WriteEndElement(); // These end elements balance the elements written out in WriteTopLevelSchemaElements this.Writer.WriteEndElement(); this.Writer.WriteEndElement(); this.Writer.Flush(); }
private static void UpdateMetadataVersionForResourceType(ResourceType resourceType, ref Version metadataVersion, ref MetadataEdmSchemaVersion edmSchemaVersion) { if (resourceType.IsOpenType) { edmSchemaVersion = WebUtil.RaiseMetadataEdmSchemaVersion(edmSchemaVersion, MetadataEdmSchemaVersion.Version1Dot2); } if (resourceType.EpmMinimumDataServiceProtocolVersion.ToVersion() > metadataVersion) { metadataVersion = WebUtil.RaiseVersion(metadataVersion, resourceType.EpmMinimumDataServiceProtocolVersion.ToVersion()); } metadataVersion = WebUtil.RaiseVersion(metadataVersion, resourceType.MetadataVersion); edmSchemaVersion = WebUtil.RaiseVersion(edmSchemaVersion, resourceType.SchemaVersion); }
/// <summary>Returns the schema namespace given the schema version.</summary> /// <param name="schemaVersion">EDM schema version.</param> /// <returns>Namespace corresponding to the schema version.</returns> private static string GetSchemaNamespace(MetadataEdmSchemaVersion schemaVersion) { switch (schemaVersion) { case MetadataEdmSchemaVersion.Version1Dot0: return XmlConstants.EdmV1Namespace; case MetadataEdmSchemaVersion.Version1Dot1: return XmlConstants.EdmV1dot1Namespace; case MetadataEdmSchemaVersion.Version1Dot2: return XmlConstants.EdmV1dot2Namespace; default: Debug.Assert(schemaVersion == MetadataEdmSchemaVersion.Version2Dot0, "Schema version must be 2.0."); return XmlConstants.EdmV2Namespace; } }
/// <summary> /// Goes through all visible types in the provider and determine the metadata version. /// </summary> /// <param name="provider">Provider wrapper instance.</param> /// <param name="metadataVersion">Returns the metadata version.</param> /// <param name="edmSchemaVersion">Returns the edm schema version.</param> internal static void UpdateMetadataVersion(DataServiceProviderWrapper provider, out Version metadataVersion, out MetadataEdmSchemaVersion edmSchemaVersion) { Debug.Assert(provider != null, "provider != null"); metadataVersion = Version4Dot0; edmSchemaVersion = MetadataEdmSchemaVersion.Version4Dot0; // Metadata versioning should only be impacted by visible types. A resource type is visible only when it is reachable from // a resource set with EntitySetRights != 'None' or a service op with ServiceOperationRights != None or it is a complex type // made visible through DataServiceConfiguration.EnableAccess(). foreach (ResourceType resourceType in provider.GetVisibleTypes()) { UpdateMetadataVersionForResourceType(resourceType, ref metadataVersion, ref edmSchemaVersion); } #if DEBUG // If there are multiple versions in future, add code here to do version-specific things foreach (OperationWrapper so in provider.GetVisibleOperations()) { Debug.Assert( so.ResultKind == ServiceOperationResultKind.DirectValue || so.ResultKind == ServiceOperationResultKind.Enumeration || so.ResultKind == ServiceOperationResultKind.QueryWithMultipleResults || so.ResultKind == ServiceOperationResultKind.QueryWithSingleResult || so.ResultKind == ServiceOperationResultKind.Void, "Otherwise we have introduced a new value for ServiceOperationResultKind, we might need to update the 'if' statement below."); } #endif }
/// <summary> /// If necessary raises version to the version requested by the user. /// </summary> /// <param name="versionToRaise">Version to raise.</param> /// <param name="targetVersion">New version to raise to.</param> /// <returns>New version if the requested version is greater than the existing version.</returns> internal static MetadataEdmSchemaVersion RaiseVersion(MetadataEdmSchemaVersion versionToRaise, MetadataEdmSchemaVersion targetVersion) { return(targetVersion > versionToRaise ? targetVersion : versionToRaise); }