Пример #1
0
        private ODataStreamReferenceValue GetMediaResource(object element, ResourceType entityResourceType, string title, Uri relativeUri)
        {
            ODataStreamReferenceValue value2 = null;

            if (entityResourceType.IsMediaLinkEntry)
            {
                string str;
                Uri    uri;
                string str2;
                base.Service.StreamProvider.GetStreamDescription(element, null, base.Service.OperationContext, out str, out uri, out str2);
                Uri uri2 = RequestUriProcessor.AppendEscapedSegment(relativeUri, "$value");
                value2 = new ODataStreamReferenceValue {
                    EditLink    = uri2,
                    ContentType = str2,
                    ReadLink    = uri ?? uri2
                };
                AtomStreamReferenceMetadata metadata2 = new AtomStreamReferenceMetadata();
                AtomLinkMetadata            metadata3 = new AtomLinkMetadata {
                    Title = title
                };
                metadata2.EditLink = metadata3;
                AtomStreamReferenceMetadata annotation = metadata2;
                value2.SetAnnotation <AtomStreamReferenceMetadata>(annotation);
                if (!string.IsNullOrEmpty(str))
                {
                    value2.ETag = str;
                }
            }
            return(value2);
        }
Пример #2
0
        private static ODataAssociationLink GetAssociationLink(Uri relativeUri, ResourceProperty navigationProperty)
        {
            Uri uri = RequestUriProcessor.AppendUnescapedSegment(RequestUriProcessor.AppendEscapedSegment(relativeUri, "$links"), navigationProperty.Name);

            return(new ODataAssociationLink {
                Name = navigationProperty.Name, Url = uri
            });
        }
Пример #3
0
 /// <summary>
 /// Constructs a new instance of DataServiceOperationContext object
 /// </summary>
 /// <param name="host">RequestMessage instance for the current operation context.</param>
 internal DataServiceOperationContext(IDataServiceHost host)
 {
     Debug.Assert(host != null, "host != null");
     this.hostInterface   = host;
     this.lazyMetadataUri = new SimpleLazy <Uri>(() =>
     {
         Debug.Assert(this.AbsoluteServiceUri != null, "Cannot get the metadata uri if the absolute service uri is not initialized");
         return(RequestUriProcessor.AppendEscapedSegment(this.AbsoluteServiceUri, XmlConstants.UriMetadataSegment));
     });
 }
Пример #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LazySerializedEntityKey"/> class which uses the same syntax for identity and edit link.
        /// </summary>
        /// <param name="lazyRelativeIdentity">The identity as a lazy string relative to the service URI.</param>
        /// <param name="absoluteServiceUri">The absolute service URI.</param>
        /// <param name="editLinkSuffix">The optional suffix to append to the edit link. Null means nothing will be appended.</param>
        internal LazySerializedEntityKey(SimpleLazy <string> lazyRelativeIdentity, Uri absoluteServiceUri, string editLinkSuffix)
        {
            Debug.Assert(absoluteServiceUri != null && absoluteServiceUri.IsAbsoluteUri, "absoluteServiceUri != null && absoluteServiceUri.IsAbsoluteUri");

            this.lazyAbsoluteEditLinkWithoutSuffix = new SimpleLazy <Uri>(() => RequestUriProcessor.AppendEscapedSegment(absoluteServiceUri, lazyRelativeIdentity.Value));
            this.lazyIdentity         = new SimpleLazy <Uri>(() => this.lazyAbsoluteEditLinkWithoutSuffix.Value, false);
            this.lazyAbsoluteEditLink = AppendLazilyIfNeeded(this.lazyAbsoluteEditLinkWithoutSuffix, editLinkSuffix);

            SimpleLazy <Uri> relativeEdit = new SimpleLazy <Uri>(() => new Uri(lazyRelativeIdentity.Value, UriKind.Relative), false);

            this.lazyRelativeEditLink = AppendLazilyIfNeeded(relativeEdit, editLinkSuffix);
        }
Пример #5
0
        internal static Uri GetIdAndEditLink(object resource, ResourceType resourceType, DataServiceProviderWrapper provider, ResourceSetWrapper container, Uri absoluteServiceUri, out Uri id)
        {
            string segmentIdentifier = GetObjectKey(resource, resourceType, provider, container.Name);
            Uri    uri = RequestUriProcessor.AppendEscapedSegment(absoluteServiceUri, segmentIdentifier);

            id = uri;
            if (container.HasNavigationPropertyOrNamedStreamsOnDerivedTypes(provider))
            {
                uri = RequestUriProcessor.AppendUnescapedSegment(uri, resourceType.FullName);
            }
            return(uri);
        }
Пример #6
0
        /// <summary>
        /// Get the stream reference value for media resource (the default stream of an entity).
        /// </summary>
        /// <param name="entityToSerialize">Entity that is currently being serialized.</param>
        /// <param name="title">The title for the element being written.</param>
        /// <returns>
        /// An instance of ODataStreamReferenceValue containing the metadata about the media resource.
        /// </returns>
        private ODataStreamReferenceValue GetMediaResource(EntityToSerialize entityToSerialize, string title)
        {
            Debug.Assert(entityToSerialize.Entity != null, "element != null");
            Debug.Assert(entityToSerialize.ResourceType != null && entityToSerialize.ResourceType.ResourceTypeKind == ResourceTypeKind.EntityType, "type != null && type.ResourceTypeKind == ResourceTypeKind.EntityType");
            Debug.Assert(!string.IsNullOrEmpty(title), "!string.IsNullOrEmpty(title)");

            ODataStreamReferenceValue mediaResource = null;

            // Handle MLE
            if (entityToSerialize.ResourceType.IsMediaLinkEntry)
            {
                string mediaETag;
                Uri    readStreamUri;
                string mediaContentType;

                Debug.Assert(entityToSerialize.ResourceType.ResourceTypeKind == ResourceTypeKind.EntityType, "type.ResourceTypeKind == ResourceTypeKind.EntityType");
                this.Service.StreamProvider.GetStreamDescription(entityToSerialize.Entity, null /*null for MLE*/, this.Service.OperationContext, out mediaETag, out readStreamUri, out mediaContentType);
                Debug.Assert(WebUtil.IsETagValueValid(mediaETag, true), "WebUtil.IsETagValueValid(mediaETag, true)");
                Debug.Assert(!string.IsNullOrEmpty(mediaContentType), "!string.IsNullOrEmpty(mediaContentType)");

                mediaResource = new ODataStreamReferenceValue();

                // build the stream's edit link lazily to avoid creating the entity's edit link if it is not needed.
                SimpleLazy <Uri> lazyStreamEditLink = new SimpleLazy <Uri>(() => RequestUriProcessor.AppendEscapedSegment(entityToSerialize.SerializedKey.RelativeEditLink, XmlConstants.UriValueSegment));

                this.PayloadMetadataPropertyManager.SetEditLink(mediaResource, () => lazyStreamEditLink.Value);

                this.PayloadMetadataPropertyManager.SetContentType(mediaResource, mediaContentType);

                // If the stream provider did not provider a read link, then we should use the edit link as the read link.
                this.PayloadMetadataPropertyManager.SetReadLink(mediaResource, () => readStreamUri ?? lazyStreamEditLink.Value);
#pragma warning disable 618
                if (this.contentFormat == ODataFormat.Atom)
#pragma warning restore 618
                {
                    AtomStreamReferenceMetadata mediaResourceAtom = new AtomStreamReferenceMetadata()
                    {
                        EditLink = new AtomLinkMetadata {
                            Title = title
                        }
                    };
                    mediaResource.SetAnnotation(mediaResourceAtom);
                }

                if (!string.IsNullOrEmpty(mediaETag))
                {
                    this.PayloadMetadataPropertyManager.SetETag(mediaResource, mediaETag);
                }
            }

            return(mediaResource);
        }
Пример #7
0
        /// <summary>
        /// Gets the association link URL.
        /// </summary>
        /// <param name="entityToSerialize">The entity to serialize.</param>
        /// <param name="navigationProperty">The navigation property.</param>
        /// <returns>The association link url.</returns>
        private static Uri GetAssociationLinkUrl(EntityToSerialize entityToSerialize, ResourceProperty navigationProperty)
        {
            Uri associationLinkUri = RequestUriProcessor.AppendUnescapedSegment(entityToSerialize.SerializedKey.RelativeEditLink, navigationProperty.Name);

            return(RequestUriProcessor.AppendEscapedSegment(associationLinkUri, XmlConstants.UriLinkSegment));
        }
Пример #8
0
        internal Uri GetODataOperationMetadata(Uri serviceBaseUri, string operationTitle)
        {
            string segmentIdentifier = string.Format(CultureInfo.InvariantCulture, "{0}#{1}.{2}", new object[] { "$metadata", Uri.EscapeDataString(this.Service.Provider.ContainerName), Uri.EscapeDataString(operationTitle) });

            return(RequestUriProcessor.AppendEscapedSegment(serviceBaseUri, segmentIdentifier));
        }