예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ProgressableBlockContent"/> class.
        /// </summary>
        /// <param name="content">The block of content to upload.</param>
        /// <param name="bufferSize">The buffer size used for uploads.</param>
        /// <param name="progress">A monitor that will receive upload progress updates.</param>
        public ProgressableBlockContent(byte[] content, int bufferSize, UploadProgress progress)
        {
            if (bufferSize <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(bufferSize));
            }

            this.Content        = content ?? throw new ArgumentNullException(nameof(content));
            this.BufferSize     = bufferSize;
            this.UploadProgress = progress;
        }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProgressableBlockContent"/> class.
 /// </summary>
 /// <param name="content">The block of content to upload.</param>
 /// <param name="progress">A monitor that will receive upload progress updates.</param>
 public ProgressableBlockContent(byte[] content, UploadProgress progress)
     : this(content, DefaultBufferSize, progress)
 {
 }
        /// <summary>
        /// Executes a REST request against the GroupMe API using HTTP POST.
        /// Authentication parameteters are automatically included with the request.
        /// </summary>
        /// <param name="endPoint">The REST endpoint to connect to.</param>
        /// <param name="requestBody">The body of the request.</param>
        /// <param name="contentType">The content type of the request.</param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> to asychronously cancel the request.</param>
        /// <param name="uploadProgress">A monitor object to receive status updates about the asychronous upload progress.</param>
        /// <returns>The REST server response.</returns>
        internal Task <HttpResponseMessage> ExecuteRestRequestAsync(string endPoint, byte[] requestBody, string contentType, CancellationToken cancellationToken, UploadProgress uploadProgress)
        {
            var content = new ProgressableBlockContent(requestBody, uploadProgress);

            content.Headers.Add("X-Access-Token", this.AuthToken);
            content.Headers.ContentType   = new System.Net.Http.Headers.MediaTypeHeaderValue(contentType);
            content.Headers.ContentLength = requestBody.Length;

            return(this.HttpClient.PostAsync(new Uri(endPoint), content, cancellationToken));
        }