Beispiel #1
0
        private void EnsureODataFormatAndContentType()
        {
            string header = null;

            if (!this.settings.UseFormat.HasValue)
            {
                header = this.message.GetHeader("Content-Type");
                header = (header == null) ? null : header.Trim();
            }
            if (!string.IsNullOrEmpty(header))
            {
                ODataPayloadKind kind;
                MediaType        type;
                this.format = MediaTypeUtils.GetFormatFromContentType(header, new ODataPayloadKind[] { this.writerPayloadKind }, MediaTypeResolver.DefaultMediaTypeResolver, out type, out this.encoding, out kind, out this.batchBoundary);
            }
            else
            {
                MediaType type2;
                this.format = MediaTypeUtils.GetContentTypeFromSettings(this.settings, this.writerPayloadKind, MediaTypeResolver.DefaultMediaTypeResolver, out type2, out this.encoding);
                if (this.writerPayloadKind == ODataPayloadKind.Batch)
                {
                    this.batchBoundary = ODataBatchWriterUtils.CreateBatchBoundary(this.writingResponse);
                    header             = ODataBatchWriterUtils.CreateMultipartMixedContentType(this.batchBoundary);
                }
                else
                {
                    this.batchBoundary = null;
                    header             = HttpUtils.BuildContentType(type2, this.encoding);
                }
                this.message.SetHeader("Content-Type", header);
            }
        }
        private void DetermineChangesetBoundaryAndEncoding(string contentType)
        {
            MediaType        type;
            ODataPayloadKind kind;

            MediaTypeUtils.GetFormatFromContentType(contentType, new ODataPayloadKind[] { ODataPayloadKind.Batch }, MediaTypeResolver.DefaultMediaTypeResolver, out type, out this.changesetEncoding, out kind, out this.changesetBoundary);
        }
        private void ProcessContentType(params ODataPayloadKind[] payloadKinds)
        {
            MediaType type;
            string    contentTypeHeader = this.GetContentTypeHeader();

            this.format = MediaTypeUtils.GetFormatFromContentType(contentTypeHeader, payloadKinds, this.MediaTypeResolver, out type, out this.encoding, out this.readerPayloadKind, out this.batchBoundary);
        }
        /// <summary>
        /// Parse the content type header value to retrieve the boundary and encoding of a changeset.
        /// </summary>
        /// <param name="contentType">The content type to parse.</param>
        private void DetermineChangesetBoundaryAndEncoding(string contentType)
        {
            Debug.Assert(!string.IsNullOrEmpty(contentType), "Should have validated that non-null, non-empty content type header exists.");

            MediaType        mediaType;
            ODataPayloadKind readerPayloadKind;

            MediaTypeUtils.GetFormatFromContentType(
                contentType,
                new ODataPayloadKind[] { ODataPayloadKind.Batch },
                MediaTypeResolver.DefaultMediaTypeResolver,
                out mediaType,
                out this.changesetEncoding,
                out readerPayloadKind,
                out this.changesetBoundary);
            Debug.Assert(readerPayloadKind == ODataPayloadKind.Batch, "Must find batch payload kind.");
            Debug.Assert(this.changesetBoundary != null && this.changesetBoundary.Length > 0, "Boundary string should have been validated by now.");
            Debug.Assert(HttpUtils.CompareMediaTypeNames(MimeConstants.MimeMultipartMixed, mediaType.FullTypeName), "Must be multipart/mixed media type.");
        }