예제 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MimeBodyPart"/> class.
 /// </summary>
 /// <param name="streamProvider">The stream provider.</param>
 /// <param name="maxBodyPartHeaderSize">The max length of the MIME header within each MIME body part.</param>
 public MimeBodyPart(IMultipartStreamProvider streamProvider, int maxBodyPartHeaderSize)
 {
     Contract.Assert(streamProvider != null, "Stream provider cannot be null.");
     _streamProvider = streamProvider;
     Segments        = new ArrayList(2);
     _headers        = FormattingUtilities.CreateEmptyContentHeaders();
     HeaderParser    = new InternetMessageFormatHeaderParser(_headers, maxBodyPartHeaderSize);
 }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MimeBodyPart"/> class.
 /// </summary>
 /// <param name="streamProvider">The stream provider.</param>
 /// <param name="maxBodyPartHeaderSize">The max length of the MIME header within each MIME body part.</param>
 public MimeBodyPart(IMultipartStreamProvider streamProvider, int maxBodyPartHeaderSize)
 {
     Contract.Assert(streamProvider != null, "Stream provider cannot be null.");
     _streamProvider = streamProvider;
     Segments = new ArrayList(2);
     _headers = FormattingUtilities.CreateEmptyContentHeaders();
     HeaderParser = new InternetMessageFormatHeaderParser(_headers, maxBodyPartHeaderSize);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="MimeMultipartBodyPartParser"/> class.
        /// </summary>
        /// <param name="content">An existing <see cref="HttpContent"/> instance to use for the object's content.</param>
        /// <param name="streamProvider">A stream provider providing output streams for where to write body parts as they are parsed.</param>
        /// <param name="maxMessageSize">The max length of the entire MIME multipart message.</param>
        /// <param name="maxBodyPartHeaderSize">The max length of the MIME header within each MIME body part.</param>
        public MimeMultipartBodyPartParser(
            HttpContent content,
            IMultipartStreamProvider streamProvider,
            long maxMessageSize,
            int maxBodyPartHeaderSize)
        {
            Contract.Assert(content != null, "content cannot be null.");
            Contract.Assert(streamProvider != null, "streamProvider cannot be null.");

            string boundary = ValidateArguments(content, maxMessageSize, true);

            _mimeParser = new MimeMultipartParser(boundary, maxMessageSize);
            _currentBodyPart = new MimeBodyPart(streamProvider, maxBodyPartHeaderSize);

            _maxBodyPartHeaderSize = maxBodyPartHeaderSize;

            _streamProvider = streamProvider;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MimeMultipartBodyPartParser"/> class.
        /// </summary>
        /// <param name="content">An existing <see cref="HttpContent"/> instance to use for the object's content.</param>
        /// <param name="streamProvider">A stream provider providing output streams for where to write body parts as they are parsed.</param>
        /// <param name="maxMessageSize">The max length of the entire MIME multipart message.</param>
        /// <param name="maxBodyPartHeaderSize">The max length of the MIME header within each MIME body part.</param>
        public MimeMultipartBodyPartParser(
            HttpContent content,
            IMultipartStreamProvider streamProvider,
            long maxMessageSize,
            int maxBodyPartHeaderSize)
        {
            Contract.Assert(content != null, "content cannot be null.");
            Contract.Assert(streamProvider != null, "streamProvider cannot be null.");

            string boundary = ValidateArguments(content, maxMessageSize, true);

            _mimeParser      = new MimeMultipartParser(boundary, maxMessageSize);
            _currentBodyPart = new MimeBodyPart(streamProvider, maxBodyPartHeaderSize);

            _maxBodyPartHeaderSize = maxBodyPartHeaderSize;

            _streamProvider = streamProvider;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="MimeMultipartBodyPartParser"/> class.
 /// </summary>
 /// <param name="content">An existing <see cref="HttpContent"/> instance to use for the object's content.</param>
 /// <param name="streamProvider">A stream provider providing output streams for where to write body parts as they are parsed.</param>
 public MimeMultipartBodyPartParser(HttpContent content, IMultipartStreamProvider streamProvider)
     : this(content, streamProvider, DefaultMaxMessageSize, DefaultMaxBodyPartHeaderSize)
 {
 }
 public static Task<IEnumerable<HttpContent>> ReadAsMultipartAsync(this HttpContent content, IMultipartStreamProvider streamProvider)
 {
     return ReadAsMultipartAsync(content, streamProvider, DefaultBufferSize);
 }
        public static Task<IEnumerable<HttpContent>> ReadAsMultipartAsync(this HttpContent content, IMultipartStreamProvider streamProvider, int bufferSize)
        {
            if (content == null)
            {
                throw new ArgumentNullException("content");
            }

            if (streamProvider == null)
            {
                throw new ArgumentNullException("streamProvider");
            }

            if (bufferSize < MinBufferSize)
            {
                throw new ArgumentOutOfRangeException("bufferSize", bufferSize, RS.Format(Properties.Resources.ArgumentMustBeGreaterThanOrEqualTo, MinBufferSize));
            }

            return content.ReadAsStreamAsync().Then(stream =>
            {
                TaskCompletionSource<IEnumerable<HttpContent>> taskCompletionSource = new TaskCompletionSource<IEnumerable<HttpContent>>();
                MimeMultipartBodyPartParser parser = new MimeMultipartBodyPartParser(content, streamProvider);
                byte[] data = new byte[bufferSize];
                MultipartAsyncContext context = new MultipartAsyncContext(stream, taskCompletionSource, parser, data);

                // Start async read/write loop
                MultipartReadAsync(context);

                // Return task and complete later
                return taskCompletionSource.Task;
            });
        }
예제 #8
0
 public static Task <IEnumerable <HttpContent> > ReadAsMultipartAsync(this HttpContent content, IMultipartStreamProvider streamProvider)
 {
     return(ReadAsMultipartAsync(content, streamProvider, DefaultBufferSize));
 }
예제 #9
0
        public static Task <IEnumerable <HttpContent> > ReadAsMultipartAsync(this HttpContent content, IMultipartStreamProvider streamProvider, int bufferSize)
        {
            if (content == null)
            {
                throw new ArgumentNullException("content");
            }

            if (streamProvider == null)
            {
                throw new ArgumentNullException("streamProvider");
            }

            if (bufferSize < MinBufferSize)
            {
                throw new ArgumentOutOfRangeException("bufferSize", bufferSize, RS.Format(Properties.Resources.ArgumentMustBeGreaterThanOrEqualTo, MinBufferSize));
            }

            return(content.ReadAsStreamAsync().Then(stream =>
            {
                TaskCompletionSource <IEnumerable <HttpContent> > taskCompletionSource = new TaskCompletionSource <IEnumerable <HttpContent> >();
                MimeMultipartBodyPartParser parser = new MimeMultipartBodyPartParser(content, streamProvider);
                byte[] data = new byte[bufferSize];
                MultipartAsyncContext context = new MultipartAsyncContext(stream, taskCompletionSource, parser, data);

                // Start async read/write loop
                MultipartReadAsync(context);

                // Return task and complete later
                return taskCompletionSource.Task;
            }));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="MimeMultipartBodyPartParser"/> class.
 /// </summary>
 /// <param name="content">An existing <see cref="HttpContent"/> instance to use for the object's content.</param>
 /// <param name="streamProvider">A stream provider providing output streams for where to write body parts as they are parsed.</param>
 public MimeMultipartBodyPartParser(HttpContent content, IMultipartStreamProvider streamProvider)
     : this(content, streamProvider, DefaultMaxMessageSize, DefaultMaxBodyPartHeaderSize)
 {
 }