Пример #1
0
        /// <summary>Writes the ID and uri path information for the specified resource.</summary>
        /// <param name='resource'>Resource for which URI information should be written.</param>
        /// <param name="resourceType">type of the resource</param>
        /// <param name="uriPath">uri of the resource for which the metadata is getting written</param>
        /// <returns>The tag name for the resource that was written.</returns>
        private string WriteMetadataObject(object resource, ResourceType resourceType, Uri uriPath)
        {
            Debug.Assert(resource != null, "resource != null");
            Debug.Assert(resourceType != null, "resourceType != null");
            Debug.Assert(uriPath != null || resourceType.ResourceTypeKind == ResourceTypeKind.ComplexType, "uri can be null for complex types");

            this.writer.WriteName(XmlConstants.JsonMetadataString);
            this.writer.StartObjectScope();

            // Write uri value only for entity types
            if (resourceType.ResourceTypeKind == ResourceTypeKind.EntityType)
            {
                this.writer.WriteName(XmlConstants.JsonUriString);
                this.writer.WriteValue(uriPath.AbsoluteUri);

                // Write the etag property, if the type has etag properties
                string etag = this.GetETagValue(resource);
                if (etag != null)
                {
                    this.writer.WriteName(XmlConstants.JsonETagString);
                    this.writer.WriteValue(etag);
                }
            }

            this.writer.WriteName(XmlConstants.JsonTypeString);

            // For generic types, we need to remove the assembly qualified names for the argument types
            this.writer.WriteValue(resourceType.FullName);

            if (resourceType.IsMediaLinkEntry)
            {
                string editMediaUri = DataServiceStreamProviderWrapper.GetStreamEditMediaUri(uriPath.AbsoluteUri);

                string mediaETag;
                Uri    readStreamUri;
                string mediaContentType;
                this.Service.StreamProvider.GetStreamDescription(resource, this.Service.OperationContext, uriPath.AbsoluteUri, out mediaETag, out readStreamUri, out mediaContentType);

                this.writer.WriteName(XmlConstants.JsonEditMediaString);
                this.writer.WriteValue(editMediaUri);

                this.writer.WriteName(XmlConstants.JsonMediaSrcString);
                this.writer.WriteValue(readStreamUri.OriginalString);

                this.writer.WriteName(XmlConstants.JsonContentTypeString);
                this.writer.WriteValue(mediaContentType);

                if (!string.IsNullOrEmpty(mediaETag))
                {
                    this.writer.WriteName(XmlConstants.JsonMediaETagString);
                    this.writer.WriteValue(mediaETag);
                }
            }

            this.writer.EndScope();

            return(GetTagNameForType(resourceType));
        }
Пример #2
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);
     }
 }
        /// <summary>Constructs a <see cref="MetadataProviderEdmModel"/> which wraps the given <see cref="DataServiceProviderWrapper"/> instance.</summary>
        /// <param name="provider"><see cref="DataServiceProviderWrapper"/> instance.</param>
        /// <param name="streamProviderWrapper">The stream provider wrapper instance.</param>
        /// <param name="actionProviderWrapper">The action provider wrapper instance.</param>
        internal MetadataProviderEdmModel(DataServiceProviderWrapper provider, DataServiceStreamProviderWrapper streamProviderWrapper, DataServiceActionProviderWrapper actionProviderWrapper)
        {
            Debug.Assert(provider != null, "provider != null");

            this.metadataProvider = provider;
            this.streamProviderWrapper = streamProviderWrapper;
            this.actionProviderWrapper = actionProviderWrapper;
            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);
            this.operationsQualifiedNameCache = new Dictionary<string, List<MetadataProviderEdmOperation>>(StringComparer.Ordinal);
            this.operationWrapperOperationLookUp = new Dictionary<OperationWrapper, IEdmOperation>(EqualityComparer<OperationWrapper>.Default);

            // In the model, set the data service version and the edm version based on the MPV (this is the best estimate we have at this time). 
            // This helps to set the nullability facet correctly when resolving type references. Note that, when the model is serialized for $metadata requests 
            // in MetadataSerializer.WriteMetadataDocument, the DSV and the edm version on the model will be overwritten with the value computed by walking the 
            // resource model.
            Version odataVersion = this.metadataProvider.Configuration.DataServiceBehavior.MaxProtocolVersion.ToVersion();
            Version edmVersion = null;
            if (!MetadataProviderUtils.DataServiceEdmVersionMap.TryGetValue(odataVersion, out edmVersion))
            {
                this.SetEdmVersion(Microsoft.OData.Edm.Library.EdmConstants.EdmVersionLatest);
            }
            else
            {
                this.SetEdmVersion(edmVersion);
            }

            // Initialize the minimum Edm Metadata Version to 4.0.
            this.MinMetadataEdmSchemaVersion = Microsoft.OData.Edm.Library.EdmConstants.EdmVersion4;

            this.AnnotationsCache = new VocabularyAnnotationCache(this);
        }