diff --git a/src/GlobalSuppressions.cs b/src/GlobalSuppressions.cs index 2a338a8..9316be8 100644 Binary files a/src/GlobalSuppressions.cs and b/src/GlobalSuppressions.cs differ diff --git a/src/Networking/HttpClient.cs b/src/Networking/HttpClient.cs new file mode 100644 index 0000000..60dec03 --- /dev/null +++ b/src/Networking/HttpClient.cs @@ -0,0 +1,253 @@ +using System; +using System.IO; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Threading; +using System.Threading.Tasks; + +namespace Rothko +{ + /// + /// Provides a base class for sending HTTP requests and receiving HTTP responses from a resource identified by a URI. + /// + public class HttpClient : IHttpClient + { + private readonly System.Net.Http.HttpClient innerHttpClient; + + /// + /// Initializes a new instance of the class. + /// + public HttpClient() + : this(new System.Net.Http.HttpClient()) + { + + } + + /// + /// Initializes a new instance of the class with a specific handler. + /// + /// The HTTP handler stack to use for sending requests. + public HttpClient(HttpMessageHandler handler) + : this(new System.Net.Http.HttpClient(handler)) + { + + } + + /// + /// Initializes a new instance of the class with a specific handler. + /// + /// The responsible for processing the HTTP response messages. + /// true if the inner handler should be disposed of by Dispose(),false if you intend to reuse the inner handler. + public HttpClient(HttpMessageHandler handler, bool disposeHandler) + : this(new System.Net.Http.HttpClient(handler, disposeHandler)) + { + + } + + protected HttpClient(System.Net.Http.HttpClient httpClient) + { + Guard.NotNull(httpClient, "httpClient"); + + innerHttpClient = httpClient; + } + + public Task GetStringAsync(string requestUri) + { + return innerHttpClient.GetStringAsync(requestUri); + } + + public Task GetStringAsync(Uri requestUri) + { + return innerHttpClient.GetStringAsync(requestUri); + } + + public Task GetByteArrayAsync(string requestUri) + { + return innerHttpClient.GetByteArrayAsync(requestUri); + } + + public Task GetByteArrayAsync(Uri requestUri) + { + return innerHttpClient.GetByteArrayAsync(requestUri); + } + + public Task GetStreamAsync(string requestUri) + { + return innerHttpClient.GetStreamAsync(requestUri); + } + + public Task GetStreamAsync(Uri requestUri) + { + return innerHttpClient.GetStreamAsync(requestUri); + } + + public Task GetAsync(string requestUri) + { + return innerHttpClient.GetAsync(requestUri); + } + + public Task GetAsync(Uri requestUri) + { + return innerHttpClient.GetAsync(requestUri); + } + + public Task GetAsync(string requestUri, HttpCompletionOption completionOption) + { + return innerHttpClient.GetAsync(requestUri, completionOption); + } + + public Task GetAsync(Uri requestUri, HttpCompletionOption completionOption) + { + return innerHttpClient.GetAsync(requestUri, completionOption); + } + + public Task GetAsync(string requestUri, CancellationToken cancellationToken) + { + return innerHttpClient.GetAsync(requestUri, cancellationToken); + } + + public Task GetAsync(Uri requestUri, CancellationToken cancellationToken) + { + return innerHttpClient.GetAsync(requestUri, cancellationToken); + } + + public Task GetAsync(string requestUri, HttpCompletionOption completionOption, CancellationToken cancellationToken) + { + return innerHttpClient.GetAsync(requestUri, completionOption, cancellationToken); + } + + public Task GetAsync(Uri requestUri, HttpCompletionOption completionOption, CancellationToken cancellationToken) + { + return innerHttpClient.GetAsync(requestUri, completionOption, cancellationToken); + } + + public Task PostAsync(string requestUri, HttpContent content) + { + return innerHttpClient.PostAsync(requestUri, content); + } + + public Task PostAsync(Uri requestUri, HttpContent content) + { + return innerHttpClient.PostAsync(requestUri, content); + } + + public Task PostAsync(string requestUri, HttpContent content, CancellationToken cancellationToken) + { + return innerHttpClient.PostAsync(requestUri, content, cancellationToken); + } + + public Task PostAsync(Uri requestUri, HttpContent content, CancellationToken cancellationToken) + { + return innerHttpClient.PostAsync(requestUri, content, cancellationToken); + } + + public Task PutAsync(string requestUri, HttpContent content) + { + return innerHttpClient.PutAsync(requestUri, content); + } + + public Task PutAsync(Uri requestUri, HttpContent content) + { + return innerHttpClient.PutAsync(requestUri, content); + } + + public Task PutAsync(string requestUri, HttpContent content, CancellationToken cancellationToken) + { + return innerHttpClient.PutAsync(requestUri, content, cancellationToken); + } + + public Task PutAsync(Uri requestUri, HttpContent content, CancellationToken cancellationToken) + { + return innerHttpClient.PutAsync(requestUri, content, cancellationToken); + } + + public Task DeleteAsync(string requestUri) + { + return innerHttpClient.DeleteAsync(requestUri); + } + + public Task DeleteAsync(Uri requestUri) + { + return innerHttpClient.DeleteAsync(requestUri); + } + + public Task DeleteAsync(string requestUri, CancellationToken cancellationToken) + { + return innerHttpClient.DeleteAsync(requestUri, cancellationToken); + } + + public Task DeleteAsync(Uri requestUri, CancellationToken cancellationToken) + { + return innerHttpClient.DeleteAsync(requestUri, cancellationToken); + } + + public Task SendAsync(HttpRequestMessage request) + { + return innerHttpClient.SendAsync(request); + } + + public Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) + { + return innerHttpClient.SendAsync(request, cancellationToken); + } + + public Task SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption) + { + return innerHttpClient.SendAsync(request, completionOption); + } + + public Task SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken) + { + return innerHttpClient.SendAsync(request, completionOption, cancellationToken); + } + + public void CancelPendingRequests() + { + innerHttpClient.CancelPendingRequests(); + } + + public HttpRequestHeaders DefaultRequestHeaders + { + get { return innerHttpClient.DefaultRequestHeaders; } + } + + public Uri BaseAddress + { + get { return innerHttpClient.BaseAddress; } + set { innerHttpClient.BaseAddress = value; } + } + + public TimeSpan Timeout + { + get { return innerHttpClient.Timeout; } + set { innerHttpClient.Timeout = value; } + } + + public long MaxResponseContentBufferSize + { + get { return innerHttpClient.MaxResponseContentBufferSize; } + set { innerHttpClient.MaxResponseContentBufferSize = value; } + } + + /// + /// Releases the unmanaged resources used by the and optionally disposes of the managed resources. + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (disposing) + { + System.Net.Http.HttpClient httpClient = innerHttpClient; + if (httpClient != null) + { + httpClient.Dispose(); + } + } + } + } +} diff --git a/src/Networking/IHttpClient.cs b/src/Networking/IHttpClient.cs new file mode 100644 index 0000000..468e914 --- /dev/null +++ b/src/Networking/IHttpClient.cs @@ -0,0 +1,359 @@ +using System; +using System.IO; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Runtime; +using System.Threading; +using System.Threading.Tasks; + +namespace Rothko +{ + public interface IHttpClient : IDisposable + { + /// + /// Send a GET request to the specified Uri and return the response body as a string in an asynchronous operation. + /// + /// + /// + /// Returns .The task object representing the asynchronous operation. + /// + /// The Uri the request is sent to.The was null. + Task GetStringAsync(string requestUri); + + /// + /// Send a GET request to the specified Uri and return the response body as a string in an asynchronous operation. + /// + /// + /// + /// Returns .The task object representing the asynchronous operation. + /// + /// The Uri the request is sent to.The was null. + Task GetStringAsync(Uri requestUri); + + /// + /// Send a GET request to the specified Uri and return the response body as a byte array in an asynchronous operation. + /// + /// + /// + /// Returns .The task object representing the asynchronous operation. + /// + /// The Uri the request is sent to.The was null. + Task GetByteArrayAsync(string requestUri); + + /// + /// Send a GET request to the specified Uri and return the response body as a byte array in an asynchronous operation. + /// + /// + /// + /// Returns .The task object representing the asynchronous operation. + /// + /// The Uri the request is sent to.The was null. + Task GetByteArrayAsync(Uri requestUri); + + /// + /// Send a GET request to the specified Uri and return the response body as a stream in an asynchronous operation. + /// + /// + /// + /// Returns .The task object representing the asynchronous operation. + /// + /// The Uri the request is sent to.The was null. + Task GetStreamAsync(string requestUri); + + /// + /// Send a GET request to the specified Uri and return the response body as a stream in an asynchronous operation. + /// + /// + /// + /// Returns .The task object representing the asynchronous operation. + /// + /// The Uri the request is sent to.The was null. + Task GetStreamAsync(Uri requestUri); + + /// + /// Send a GET request to the specified Uri as an asynchronous operation. + /// + /// + /// + /// Returns .The task object representing the asynchronous operation. + /// + /// The Uri the request is sent to.The was null. + Task GetAsync(string requestUri); + + /// + /// Send a GET request to the specified Uri as an asynchronous operation. + /// + /// + /// + /// Returns .The task object representing the asynchronous operation. + /// + /// The Uri the request is sent to.The was null. + [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] + Task GetAsync(Uri requestUri); + + /// + /// Send a GET request to the specified Uri with an HTTP completion option as an asynchronous operation. + /// + /// + /// + /// Returns . + /// + /// The Uri the request is sent to.An HTTP completion option value that indicates when the operation should be considered completed.The was null. + Task GetAsync(string requestUri, HttpCompletionOption completionOption); + + /// + /// Send a GET request to the specified Uri with an HTTP completion option as an asynchronous operation. + /// + /// + /// + /// Returns .The task object representing the asynchronous operation. + /// + /// The Uri the request is sent to.An HTTP completion option value that indicates when the operation should be considered completed.The was null. + Task GetAsync(Uri requestUri, HttpCompletionOption completionOption); + + /// + /// Send a GET request to the specified Uri with a cancellation token as an asynchronous operation. + /// + /// + /// + /// Returns . + /// + /// The Uri the request is sent to.A cancellation token that can be used by other objects or threads to receive notice of cancellation.The was null. + Task GetAsync(string requestUri, CancellationToken cancellationToken); + + /// + /// Send a GET request to the specified Uri with a cancellation token as an asynchronous operation. + /// + /// + /// + /// Returns .The task object representing the asynchronous operation. + /// + /// The Uri the request is sent to.A cancellation token that can be used by other objects or threads to receive notice of cancellation.The was null. + [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] + Task GetAsync(Uri requestUri, CancellationToken cancellationToken); + + /// + /// Send a GET request to the specified Uri with an HTTP completion option and a cancellation token as an asynchronous operation. + /// + /// + /// + /// Returns . + /// + /// The Uri the request is sent to.An HTTP completion option value that indicates when the operation should be considered completed.A cancellation token that can be used by other objects or threads to receive notice of cancellation.The was null. + Task GetAsync(string requestUri, HttpCompletionOption completionOption, CancellationToken cancellationToken); + + /// + /// Send a GET request to the specified Uri with an HTTP completion option and a cancellation token as an asynchronous operation. + /// + /// + /// + /// Returns .The task object representing the asynchronous operation. + /// + /// The Uri the request is sent to.An HTTP completion option value that indicates when the operation should be considered completed.A cancellation token that can be used by other objects or threads to receive notice of cancellation.The was null. + Task GetAsync(Uri requestUri, HttpCompletionOption completionOption, CancellationToken cancellationToken); + + /// + /// Send a POST request to the specified Uri as an asynchronous operation. + /// + /// + /// + /// Returns .The task object representing the asynchronous operation. + /// + /// The Uri the request is sent to.The HTTP request content sent to the server.The was null. + Task PostAsync(string requestUri, HttpContent content); + + /// + /// Send a POST request to the specified Uri as an asynchronous operation. + /// + /// + /// + /// Returns .The task object representing the asynchronous operation. + /// + /// The Uri the request is sent to.The HTTP request content sent to the server.The was null. + Task PostAsync(Uri requestUri, HttpContent content); + + /// + /// Send a POST request with a cancellation token as an asynchronous operation. + /// + /// + /// + /// Returns .The task object representing the asynchronous operation. + /// + /// The Uri the request is sent to.The HTTP request content sent to the server.A cancellation token that can be used by other objects or threads to receive notice of cancellation.The was null. + Task PostAsync(string requestUri, HttpContent content, CancellationToken cancellationToken); + + /// + /// Send a POST request with a cancellation token as an asynchronous operation. + /// + /// + /// + /// Returns .The task object representing the asynchronous operation. + /// + /// The Uri the request is sent to.The HTTP request content sent to the server.A cancellation token that can be used by other objects or threads to receive notice of cancellation.The was null. + Task PostAsync(Uri requestUri, HttpContent content, CancellationToken cancellationToken); + + /// + /// Send a PUT request to the specified Uri as an asynchronous operation. + /// + /// + /// + /// Returns .The task object representing the asynchronous operation. + /// + /// The Uri the request is sent to.The HTTP request content sent to the server.The was null. + Task PutAsync(string requestUri, HttpContent content); + + /// + /// Send a PUT request to the specified Uri as an asynchronous operation. + /// + /// + /// + /// Returns .The task object representing the asynchronous operation. + /// + /// The Uri the request is sent to.The HTTP request content sent to the server.The was null. + Task PutAsync(Uri requestUri, HttpContent content); + + /// + /// Send a PUT request with a cancellation token as an asynchronous operation. + /// + /// + /// + /// Returns .The task object representing the asynchronous operation. + /// + /// The Uri the request is sent to.The HTTP request content sent to the server.A cancellation token that can be used by other objects or threads to receive notice of cancellation.The was null. + Task PutAsync(string requestUri, HttpContent content, CancellationToken cancellationToken); + + /// + /// Send a PUT request with a cancellation token as an asynchronous operation. + /// + /// + /// + /// Returns .The task object representing the asynchronous operation. + /// + /// The Uri the request is sent to.The HTTP request content sent to the server.A cancellation token that can be used by other objects or threads to receive notice of cancellation.The was null. + Task PutAsync(Uri requestUri, HttpContent content, CancellationToken cancellationToken); + + /// + /// Send a DELETE request to the specified Uri as an asynchronous operation. + /// + /// + /// + /// Returns .The task object representing the asynchronous operation. + /// + /// The Uri the request is sent to.The was null.The request message was already sent by the instance. + Task DeleteAsync(string requestUri); + + /// + /// Send a DELETE request to the specified Uri as an asynchronous operation. + /// + /// + /// + /// Returns .The task object representing the asynchronous operation. + /// + /// The Uri the request is sent to.The was null.The request message was already sent by the instance. + Task DeleteAsync(Uri requestUri); + + /// + /// Send a DELETE request to the specified Uri with a cancellation token as an asynchronous operation. + /// + /// + /// + /// Returns .The task object representing the asynchronous operation. + /// + /// The Uri the request is sent to.A cancellation token that can be used by other objects or threads to receive notice of cancellation.The was null.The request message was already sent by the instance. + Task DeleteAsync(string requestUri, CancellationToken cancellationToken); + + /// + /// Send a DELETE request to the specified Uri with a cancellation token as an asynchronous operation. + /// + /// + /// + /// Returns .The task object representing the asynchronous operation. + /// + /// The Uri the request is sent to.A cancellation token that can be used by other objects or threads to receive notice of cancellation.The was null.The request message was already sent by the instance. + Task DeleteAsync(Uri requestUri, CancellationToken cancellationToken); + + /// + /// Send an HTTP request as an asynchronous operation. + /// + /// + /// + /// Returns .The task object representing the asynchronous operation. + /// + /// The HTTP request message to send.The was null.The request message was already sent by the instance. + Task SendAsync(HttpRequestMessage request); + + /// + /// Send an HTTP request as an asynchronous operation. + /// + /// + /// + /// Returns .The task object representing the asynchronous operation. + /// + /// The HTTP request message to send.The cancellation token to cancel operation.The was null.The request message was already sent by the instance. + [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] + Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken); + + /// + /// Send an HTTP request as an asynchronous operation. + /// + /// + /// + /// Returns .The task object representing the asynchronous operation. + /// + /// The HTTP request message to send.When the operation should complete (as soon as a response is available or after reading the whole response content).The was null.The request message was already sent by the instance. + Task SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption); + + /// + /// Send an HTTP request as an asynchronous operation. + /// + /// + /// + /// Returns .The task object representing the asynchronous operation. + /// + /// The HTTP request message to send.When the operation should complete (as soon as a response is available or after reading the whole response content).The cancellation token to cancel operation.The was null.The request message was already sent by the instance. + Task SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken); + + /// + /// Cancel all pending requests on this instance. + /// + void CancelPendingRequests(); + + /// + /// Gets the headers which should be sent with each request. + /// + /// + /// + /// Returns .The headers which should be sent with each request. + /// + HttpRequestHeaders DefaultRequestHeaders { get; } + + /// + /// Gets or sets the base address of Uniform Resource Identifier (URI) of the Internet resource used when sending requests. + /// + /// + /// + /// Returns .The base address of Uniform Resource Identifier (URI) of the Internet resource used when sending requests. + /// + Uri BaseAddress { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; set; } + + /// + /// Gets or sets the number of milliseconds to wait before the request times out. + /// + /// + /// + /// Returns .The number of milliseconds to wait before the request times out. + /// + /// The timeout specified is less than or equal to zero and is not .An operation has already been started on the current instance. The current instance has been disposed. + TimeSpan Timeout { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; set; } + + /// + /// Gets or sets the maximum number of bytes to buffer when reading the response content. + /// + /// + /// + /// Returns .The maximum number of bytes to buffer when reading the response content. The default value for this property is 2 gigabytes. + /// + /// The size specified is less than or equal to zero.An operation has already been started on the current instance. The current instance has been disposed. + long MaxResponseContentBufferSize { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; set; } + } +} \ No newline at end of file diff --git a/src/Networking/IWebClient.cs b/src/Networking/IWebClient.cs new file mode 100644 index 0000000..5c60c2e --- /dev/null +++ b/src/Networking/IWebClient.cs @@ -0,0 +1,401 @@ +using System; +using System.Collections.Specialized; +using System.ComponentModel; +using System.Net; +using System.Net.Cache; + +namespace Rothko +{ + public interface IWebClient : IDisposable + { + byte[] DownloadData(string address); + + /// + /// Downloads the resource as a array from the URI specified. + /// + /// + /// + /// A array containing the downloaded resource. + /// + /// The URI represented by the object, from which to download data. + /// The parameter is null. + byte[] DownloadData(Uri address); + + void DownloadFile(string address, string fileName); + void DownloadFile(Uri address, string fileName); + System.IO.Stream OpenRead(string address); + + /// + /// Opens a readable stream for the data downloaded from a resource with the URI specified as a + /// + /// + /// + /// A used to read data from a resource. + /// + /// The URI specified as a from which to download data. + /// The parameter is null. + /// The URI formed by combining , is invalid.-or- An error occurred while downloading data. + System.IO.Stream OpenRead(Uri address); + + System.IO.Stream OpenWrite(string address); + + /// + /// Opens a stream for writing data to the specified resource. + /// + /// + /// + /// A used to write data to the resource. + /// + /// The URI of the resource to receive the data. + /// The parameter is null. + /// The URI formed by combining , and is invalid.-or- An error occurred while opening the stream. + System.IO.Stream OpenWrite(Uri address); + + System.IO.Stream OpenWrite(string address, string method); + System.IO.Stream OpenWrite(Uri address, string method); + byte[] UploadData(string address, byte[] data); + byte[] UploadData(Uri address, byte[] data); + byte[] UploadData(string address, string method, byte[] data); + byte[] UploadData(Uri address, string method, byte[] data); + byte[] UploadFile(string address, string fileName); + byte[] UploadFile(Uri address, string fileName); + byte[] UploadFile(string address, string method, string fileName); + byte[] UploadFile(Uri address, string method, string fileName); + byte[] UploadValues(string address, NameValueCollection data); + + /// + /// Uploads the specified name/value collection to the resource identified by the specified URI. + /// + /// + /// + /// A array containing the body of the response from the resource. + /// + /// The URI of the resource to receive the collection. + /// The to send to the resource. + /// The parameter is null.-or-The parameter is null. + /// The URI formed by combining , and is invalid.-or- is null.-or- There was no response from the server hosting the resource.-or- An error occurred while opening the stream.-or- The Content-type header is not null or "application/x-www-form-urlencoded". + byte[] UploadValues(Uri address, NameValueCollection data); + + byte[] UploadValues(string address, string method, NameValueCollection data); + byte[] UploadValues(Uri address, string method, NameValueCollection data); + string UploadString(string address, string data); + string UploadString(Uri address, string data); + string UploadString(string address, string method, string data); + string UploadString(Uri address, string method, string data); + string DownloadString(string address); + + /// + /// Downloads the requested resource as a . The resource to download is specified as a . + /// + /// + /// + /// A containing the requested resource. + /// + /// A object containing the URI to download. + /// The parameter is null. + /// The URI formed by combining and is invalid.-or- An error occurred while downloading the resource. The method has been called simultaneously on multiple threads. + string DownloadString(Uri address); + + /// + /// Opens a readable stream containing the specified resource. This method does not block the calling thread. + /// + /// The URI of the resource to retrieve. + /// The parameter is null. + /// The URI formed by combining and address is invalid.-or- An error occurred while downloading the resource. -or- An error occurred while opening the stream. + void OpenReadAsync(Uri address); + + void OpenReadAsync(Uri address, object userToken); + + /// + /// Opens a stream for writing data to the specified resource. This method does not block the calling thread. + /// + /// The URI of the resource to receive the data. + /// The parameter is null. + void OpenWriteAsync(Uri address); + + void OpenWriteAsync(Uri address, string method); + void OpenWriteAsync(Uri address, string method, object userToken); + + /// + /// Downloads the resource specified as a . This method does not block the calling thread. + /// + /// A containing the URI to download. + /// The parameter is null. + /// The URI formed by combining and is invalid.-or- An error occurred while downloading the resource. + void DownloadStringAsync(Uri address); + + void DownloadStringAsync(Uri address, object userToken); + + /// + /// Downloads the resource as a array from the URI specified as an asynchronous operation. + /// + /// A containing the URI to download. + /// The parameter is null. + /// The URI formed by combining and is invalid.-or- An error occurred while downloading the resource. + void DownloadDataAsync(Uri address); + + void DownloadDataAsync(Uri address, object userToken); + void DownloadFileAsync(Uri address, string fileName); + void DownloadFileAsync(Uri address, string fileName, object userToken); + void UploadStringAsync(Uri address, string data); + void UploadStringAsync(Uri address, string method, string data); + void UploadStringAsync(Uri address, string method, string data, object userToken); + void UploadDataAsync(Uri address, byte[] data); + void UploadDataAsync(Uri address, string method, byte[] data); + void UploadDataAsync(Uri address, string method, byte[] data, object userToken); + void UploadFileAsync(Uri address, string fileName); + void UploadFileAsync(Uri address, string method, string fileName); + void UploadFileAsync(Uri address, string method, string fileName, object userToken); + + /// + /// Uploads the data in the specified name/value collection to the resource identified by the specified URI. This method does not block the calling thread. + /// + /// The URI of the resource to receive the collection. This URI must identify a resource that can accept a request sent with the default method. See remarks. + /// The to send to the resource. + /// The parameter is null.-or-The parameter is null.The URI formed by combining and is invalid.-or- There was no response from the server hosting the resource. + void UploadValuesAsync(Uri address, NameValueCollection data); + + void UploadValuesAsync(Uri address, string method, NameValueCollection data); + void UploadValuesAsync(Uri address, string method, NameValueCollection data, object userToken); + + /// + /// Cancels a pending asynchronous operation. + /// + /// + void CancelAsync(); + + System.Threading.Tasks.Task DownloadStringTaskAsync(string address); + + /// + /// Downloads the resource as a from the URI specified as an asynchronous operation using a task object. + /// + /// + /// + /// Returns .The task object representing the asynchronous operation. The property on the task object returns a array containing the downloaded resource. + /// + /// The URI of the resource to download. + /// The parameter is null. + /// The URI formed by combining and is invalid.-or- An error occurred while downloading the resource. + System.Threading.Tasks.Task DownloadStringTaskAsync(Uri address); + + System.Threading.Tasks.Task OpenReadTaskAsync(string address); + + /// + /// Opens a readable stream containing the specified resource as an asynchronous operation using a task object. + /// + /// + /// + /// Returns .The task object representing the asynchronous operation. The property on the task object returns a used to read data from a resource. + /// + /// The URI of the resource to retrieve.The parameter is null. The URI formed by combining and address is invalid.-or- An error occurred while downloading the resource. -or- An error occurred while opening the stream. + System.Threading.Tasks.Task OpenReadTaskAsync(Uri address); + + System.Threading.Tasks.Task OpenWriteTaskAsync(string address); + + /// + /// Opens a stream for writing data to the specified resource as an asynchronous operation using a task object. + /// + /// + /// + /// Returns .The task object representing the asynchronous operation. The property on the task object returns a used to write data to the resource. + /// + /// The URI of the resource to receive the data.The parameter is null. The URI formed by combining and is invalid.-or- An error occurred while opening the stream. + System.Threading.Tasks.Task OpenWriteTaskAsync(Uri address); + + System.Threading.Tasks.Task OpenWriteTaskAsync(string address, string method); + System.Threading.Tasks.Task OpenWriteTaskAsync(Uri address, string method); + System.Threading.Tasks.Task UploadStringTaskAsync(string address, string data); + System.Threading.Tasks.Task UploadStringTaskAsync(Uri address, string data); + System.Threading.Tasks.Task UploadStringTaskAsync(string address, string method, string data); + System.Threading.Tasks.Task UploadStringTaskAsync(Uri address, string method, string data); + System.Threading.Tasks.Task DownloadDataTaskAsync(string address); + + /// + /// Downloads the resource as a array from the URI specified as an asynchronous operation using a task object. + /// + /// + /// + /// Returns .The task object representing the asynchronous operation. The property on the task object returns a array containing the downloaded resource. + /// + /// The URI of the resource to download.The parameter is null. The URI formed by combining and is invalid.-or- An error occurred while downloading the resource. + System.Threading.Tasks.Task DownloadDataTaskAsync(Uri address); + + System.Threading.Tasks.Task DownloadFileTaskAsync(string address, string fileName); + System.Threading.Tasks.Task DownloadFileTaskAsync(Uri address, string fileName); + System.Threading.Tasks.Task UploadDataTaskAsync(string address, byte[] data); + System.Threading.Tasks.Task UploadDataTaskAsync(Uri address, byte[] data); + System.Threading.Tasks.Task UploadDataTaskAsync(string address, string method, byte[] data); + System.Threading.Tasks.Task UploadDataTaskAsync(Uri address, string method, byte[] data); + System.Threading.Tasks.Task UploadFileTaskAsync(string address, string fileName); + System.Threading.Tasks.Task UploadFileTaskAsync(Uri address, string fileName); + System.Threading.Tasks.Task UploadFileTaskAsync(string address, string method, string fileName); + System.Threading.Tasks.Task UploadFileTaskAsync(Uri address, string method, string fileName); + System.Threading.Tasks.Task UploadValuesTaskAsync(string address, NameValueCollection data); + System.Threading.Tasks.Task UploadValuesTaskAsync(string address, string method, NameValueCollection data); + + /// + /// Uploads the specified name/value collection to the resource identified by the specified URI as an asynchronous operation using a task object. + /// + /// + /// + /// Returns .The task object representing the asynchronous operation. The property on the task object returns a array containing the response sent by the server. + /// + /// The URI of the resource to receive the collection.The to send to the resource.The parameter is null.-or-The parameter is null.The URI formed by combining , and is invalid.-or- An error occurred while opening the stream.-or- There was no response from the server hosting the resource.-or- The Content-type header value is not null and is not application/x-www-form-urlencoded. + System.Threading.Tasks.Task UploadValuesTaskAsync(Uri address, NameValueCollection data); + + System.Threading.Tasks.Task UploadValuesTaskAsync(Uri address, string method, NameValueCollection data); + + /// + /// Gets and sets the used to upload and download strings. + /// + /// + /// + /// A that is used to encode strings. The default value of this property is the encoding returned by . + /// + System.Text.Encoding Encoding { get; set; } + + /// + /// Gets or sets the base URI for requests made by a . + /// + /// + /// + /// A containing the base URI for requests made by a or if no base address has been specified. + /// + /// is set to an invalid URI. The inner exception may contain information that will help you locate the error. + string BaseAddress { get; set; } + + /// + /// Gets or sets the network credentials that are sent to the host and used to authenticate the request. + /// + /// + /// + /// An containing the authentication credentials for the request. The default is null. + /// + /// + ICredentials Credentials { get; set; } + + /// + /// Gets or sets a value that controls whether the are sent with requests. + /// + /// + /// + /// true if the default credentials are used{ throw new NotImplementedException();} otherwise false. The default value is false. + /// + /// + bool UseDefaultCredentials { get; set; } + + /// + /// Gets or sets a collection of header name/value pairs associated with the request. + /// + /// + /// + /// A containing header name/value pairs associated with this request. + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + WebHeaderCollection Headers { get; set; } + + /// + /// Gets or sets a collection of query name/value pairs associated with the request. + /// + /// + /// + /// A that contains query name/value pairs associated with the request. If no pairs are associated with the request, the value is an empty . + /// + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + NameValueCollection QueryString { get; set; } + + /// + /// Gets a collection of header name/value pairs associated with the response. + /// + /// + /// + /// A containing header name/value pairs associated with the response, or null if no response has been received. + /// + /// + WebHeaderCollection ResponseHeaders { get; } + + /// + /// Gets or sets the proxy used by this object. + /// + /// + /// + /// An instance used to send requests. + /// + /// is set to null. + IWebProxy Proxy { get; set; } + + /// + /// Gets or sets the application's cache policy for any resources obtained by this WebClient instance using objects. + /// + /// + /// + /// A object that represents the application's caching requirements. + /// + RequestCachePolicy CachePolicy { get; set; } + + /// + /// Gets whether a Web request is in progress. + /// + /// + /// + /// true if the Web request is still in progress{ throw new NotImplementedException();} otherwise false. + /// + bool IsBusy { get; } + + /// + /// Occurs when an asynchronous operation to open a stream containing a resource completes. + /// + event OpenReadCompletedEventHandler OpenReadCompleted; + + /// + /// Occurs when an asynchronous operation to open a stream to write data to a resource completes. + /// + event OpenWriteCompletedEventHandler OpenWriteCompleted; + + /// + /// Occurs when an asynchronous resource-download operation completes. + /// + event DownloadStringCompletedEventHandler DownloadStringCompleted; + + /// + /// Occurs when an asynchronous data download operation completes. + /// + event DownloadDataCompletedEventHandler DownloadDataCompleted; + + /// + /// Occurs when an asynchronous file download operation completes. + /// + event AsyncCompletedEventHandler DownloadFileCompleted; + + /// + /// Occurs when an asynchronous string-upload operation completes. + /// + event UploadStringCompletedEventHandler UploadStringCompleted; + + /// + /// Occurs when an asynchronous data-upload operation completes. + /// + event UploadDataCompletedEventHandler UploadDataCompleted; + + /// + /// Occurs when an asynchronous file-upload operation completes. + /// + event UploadFileCompletedEventHandler UploadFileCompleted; + + /// + /// Occurs when an asynchronous upload of a name/value collection completes. + /// + event UploadValuesCompletedEventHandler UploadValuesCompleted; + + /// + /// Occurs when an asynchronous download operation successfully transfers some or all of the data. + /// + event DownloadProgressChangedEventHandler DownloadProgressChanged; + + /// + /// Occurs when an asynchronous upload operation successfully transfers some or all of the data. + /// + event UploadProgressChangedEventHandler UploadProgressChanged; + } +} \ No newline at end of file diff --git a/src/Networking/WebClient.cs b/src/Networking/WebClient.cs new file mode 100644 index 0000000..e16ea72 --- /dev/null +++ b/src/Networking/WebClient.cs @@ -0,0 +1,623 @@ +using System; +using System.Collections.Specialized; +using System.ComponentModel; +using System.Net; +using System.Net.Cache; +using System.Text; +using System.Threading.Tasks; + +namespace Rothko +{ + public class WebClient : IWebClient + { + private readonly System.Net.WebClient innerWebClient; + + public WebClient() + { + innerWebClient = new System.Net.WebClient(); + + HookEvents(); + } + + public byte[] DownloadData(string address) + { + return innerWebClient.DownloadData(address); + } + + public byte[] DownloadData(Uri address) + { + return innerWebClient.DownloadData(address); + } + + public void DownloadFile(string address, string fileName) + { + innerWebClient.DownloadFile(address, fileName); + } + + public void DownloadFile(Uri address, string fileName) + { + innerWebClient.DownloadFile(address, fileName); + } + + public System.IO.Stream OpenRead(string address) + { + return innerWebClient.OpenRead(address); + } + + public System.IO.Stream OpenRead(Uri address) + { + return innerWebClient.OpenRead(address); + } + + public System.IO.Stream OpenWrite(string address) + { + return innerWebClient.OpenWrite(address); + } + + public System.IO.Stream OpenWrite(Uri address) + { + return innerWebClient.OpenWrite(address); + } + + public System.IO.Stream OpenWrite(string address, string method) + { + return innerWebClient.OpenWrite(address, method); + } + + public System.IO.Stream OpenWrite(Uri address, string method) + { + return innerWebClient.OpenWrite(address, method); + } + + public byte[] UploadData(string address, byte[] data) + { + return innerWebClient.UploadData(address, data); + } + + public byte[] UploadData(Uri address, byte[] data) + { + return innerWebClient.UploadData(address, data); + } + + public byte[] UploadData(string address, string method, byte[] data) + { + return innerWebClient.UploadData(address, method, data); + } + + public byte[] UploadData(Uri address, string method, byte[] data) + { + return innerWebClient.UploadData(address, method, data); + } + + public byte[] UploadFile(string address, string fileName) + { + return innerWebClient.UploadFile(address, fileName); + } + + public byte[] UploadFile(Uri address, string fileName) + { + return innerWebClient.UploadFile(address, fileName); + } + + public byte[] UploadFile(string address, string method, string fileName) + { + return innerWebClient.UploadFile(address, method, fileName); + } + + public byte[] UploadFile(Uri address, string method, string fileName) + { + return innerWebClient.UploadFile(address, method, fileName); + } + + public byte[] UploadValues(string address, NameValueCollection data) + { + return innerWebClient.UploadValues(address, data); + } + + public byte[] UploadValues(Uri address, NameValueCollection data) + { + return innerWebClient.UploadValues(address, data); + } + + public byte[] UploadValues(string address, string method, NameValueCollection data) + { + return innerWebClient.UploadValues(address, method, data); + } + + public byte[] UploadValues(Uri address, string method, NameValueCollection data) + { + return innerWebClient.UploadValues(address, method, data); + } + + public string UploadString(string address, string data) + { + return innerWebClient.UploadString(address, data); + } + + public string UploadString(Uri address, string data) + { + return innerWebClient.UploadString(address, data); + } + + public string UploadString(string address, string method, string data) + { + return innerWebClient.UploadString(address, method, data); + } + + public string UploadString(Uri address, string method, string data) + { + return innerWebClient.UploadString(address, method, data); + } + + public string DownloadString(string address) + { + return innerWebClient.DownloadString(address); + } + + public string DownloadString(Uri address) + { + return innerWebClient.DownloadString(address); + } + + public void OpenReadAsync(Uri address) + { + innerWebClient.OpenReadAsync(address); + } + + public void OpenReadAsync(Uri address, object userToken) + { + innerWebClient.OpenReadAsync(address, userToken); + } + + public void OpenWriteAsync(Uri address) + { + innerWebClient.OpenWriteAsync(address); + } + + public void OpenWriteAsync(Uri address, string method) + { + innerWebClient.OpenWriteAsync(address, method); + } + + public void OpenWriteAsync(Uri address, string method, object userToken) + { + innerWebClient.OpenWriteAsync(address, method, userToken); + } + + public void DownloadStringAsync(Uri address) + { + innerWebClient.DownloadStringAsync(address); + } + + public void DownloadStringAsync(Uri address, object userToken) + { + innerWebClient.DownloadStringAsync(address, userToken); + } + + public void DownloadDataAsync(Uri address) + { + innerWebClient.DownloadDataAsync(address); + } + + public void DownloadDataAsync(Uri address, object userToken) + { + innerWebClient.DownloadDataAsync(address, userToken); + } + + public void DownloadFileAsync(Uri address, string fileName) + { + innerWebClient.DownloadFileAsync(address, fileName); + } + + public void DownloadFileAsync(Uri address, string fileName, object userToken) + { + innerWebClient.DownloadFileAsync(address, fileName, userToken); + } + + public void UploadStringAsync(Uri address, string data) + { + innerWebClient.UploadStringAsync(address, data); + } + + public void UploadStringAsync(Uri address, string method, string data) + { + innerWebClient.UploadStringAsync(address, method, data); + } + + public void UploadStringAsync(Uri address, string method, string data, object userToken) + { + innerWebClient.UploadStringAsync(address, method, data, userToken); + } + + public void UploadDataAsync(Uri address, byte[] data) + { + innerWebClient.UploadDataAsync(address, data); + } + + public void UploadDataAsync(Uri address, string method, byte[] data) + { + innerWebClient.UploadDataAsync(address, method, data); + } + + public void UploadDataAsync(Uri address, string method, byte[] data, object userToken) + { + innerWebClient.UploadDataAsync(address, method, data, userToken); + } + + public void UploadFileAsync(Uri address, string fileName) + { + innerWebClient.UploadFileAsync(address, fileName); + } + + public void UploadFileAsync(Uri address, string method, string fileName) + { + innerWebClient.UploadFileAsync(address, method, fileName); + } + + public void UploadFileAsync(Uri address, string method, string fileName, object userToken) + { + innerWebClient.UploadFileAsync(address, method, fileName, userToken); + } + + public void UploadValuesAsync(Uri address, NameValueCollection data) + { + innerWebClient.UploadValuesAsync(address, data); + } + + public void UploadValuesAsync(Uri address, string method, NameValueCollection data) + { + innerWebClient.UploadValuesAsync(address, method, data); + } + + public void UploadValuesAsync(Uri address, string method, NameValueCollection data, object userToken) + { + innerWebClient.UploadValuesAsync(address, method, data, userToken); + } + + public void CancelAsync() + { + innerWebClient.CancelAsync(); + } + + public Task DownloadStringTaskAsync(string address) + { + return innerWebClient.DownloadStringTaskAsync(address); + } + + public Task DownloadStringTaskAsync(Uri address) + { + return innerWebClient.DownloadStringTaskAsync(address); + } + + public Task OpenReadTaskAsync(string address) + { + return innerWebClient.OpenReadTaskAsync(address); + } + + public Task OpenReadTaskAsync(Uri address) + { + return innerWebClient.OpenReadTaskAsync(address); + } + + public Task OpenWriteTaskAsync(string address) + { + return innerWebClient.OpenWriteTaskAsync(address); + } + + public Task OpenWriteTaskAsync(Uri address) + { + return innerWebClient.OpenWriteTaskAsync(address); + } + + public Task OpenWriteTaskAsync(string address, string method) + { + return innerWebClient.OpenWriteTaskAsync(address, method); + } + + public Task OpenWriteTaskAsync(Uri address, string method) + { + return innerWebClient.OpenWriteTaskAsync(address, method); + } + + public Task UploadStringTaskAsync(string address, string data) + { + return innerWebClient.UploadStringTaskAsync(address, data); + } + + public Task UploadStringTaskAsync(Uri address, string data) + { + return innerWebClient.UploadStringTaskAsync(address, data); + } + + public Task UploadStringTaskAsync(string address, string method, string data) + { + return innerWebClient.UploadStringTaskAsync(address, method, data); + } + + public Task UploadStringTaskAsync(Uri address, string method, string data) + { + return innerWebClient.UploadStringTaskAsync(address, method, data); + } + + public Task DownloadDataTaskAsync(string address) + { + return innerWebClient.DownloadDataTaskAsync(address); + } + + public Task DownloadDataTaskAsync(Uri address) + { + return innerWebClient.DownloadDataTaskAsync(address); + } + + public Task DownloadFileTaskAsync(string address, string fileName) + { + return innerWebClient.DownloadFileTaskAsync(address, fileName); + } + + public Task DownloadFileTaskAsync(Uri address, string fileName) + { + return innerWebClient.DownloadFileTaskAsync(address, fileName); + } + + public Task UploadDataTaskAsync(string address, byte[] data) + { + return innerWebClient.UploadDataTaskAsync(address, data); + } + + public Task UploadDataTaskAsync(Uri address, byte[] data) + { + return innerWebClient.UploadDataTaskAsync(address, data); + } + + public Task UploadDataTaskAsync(string address, string method, byte[] data) + { + return innerWebClient.UploadDataTaskAsync(address, method, data); + } + + public Task UploadDataTaskAsync(Uri address, string method, byte[] data) + { + return innerWebClient.UploadDataTaskAsync(address, method, data); + } + + public Task UploadFileTaskAsync(string address, string fileName) + { + return innerWebClient.UploadFileTaskAsync(address, fileName); + } + + public Task UploadFileTaskAsync(Uri address, string fileName) + { + return innerWebClient.UploadFileTaskAsync(address, fileName); + } + + public Task UploadFileTaskAsync(string address, string method, string fileName) + { + return innerWebClient.UploadFileTaskAsync(address, method, fileName); + } + + public Task UploadFileTaskAsync(Uri address, string method, string fileName) + { + return innerWebClient.UploadFileTaskAsync(address, method, fileName); + } + + public Task UploadValuesTaskAsync(string address, NameValueCollection data) + { + return innerWebClient.UploadValuesTaskAsync(address, data); + } + + public Task UploadValuesTaskAsync(string address, string method, NameValueCollection data) + { + return innerWebClient.UploadValuesTaskAsync(address, method, data); + } + + public Task UploadValuesTaskAsync(Uri address, NameValueCollection data) + { + return innerWebClient.UploadValuesTaskAsync(address, data); + } + public Task UploadValuesTaskAsync(Uri address, string method, NameValueCollection data) + { + return innerWebClient.UploadValuesTaskAsync(address, method, data); + } + + public Encoding Encoding + { + get { return innerWebClient.Encoding; } + set { innerWebClient.Encoding = value; } + } + + public string BaseAddress + { + get { return innerWebClient.BaseAddress; } + set { innerWebClient.BaseAddress = value; } + } + + public ICredentials Credentials + { + get { return innerWebClient.Credentials; } + set { innerWebClient.Credentials = value; } + } + + public bool UseDefaultCredentials + { + get { return innerWebClient.UseDefaultCredentials; } + set { innerWebClient.UseDefaultCredentials = value; } + } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public WebHeaderCollection Headers + { + get { return innerWebClient.Headers; } + set { innerWebClient.Headers = value; } + } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public NameValueCollection QueryString + { + get { return innerWebClient.QueryString; } + set { innerWebClient.QueryString = value; } + } + + public WebHeaderCollection ResponseHeaders + { + get { return innerWebClient.ResponseHeaders; } + } + + public IWebProxy Proxy + { + get { return innerWebClient.Proxy; } + set { innerWebClient.Proxy = value; } + } + + public RequestCachePolicy CachePolicy + { + get { return innerWebClient.CachePolicy; } + set { innerWebClient.CachePolicy = value; } + } + + public bool IsBusy + { + get { return innerWebClient.IsBusy; } + } + + private void HookEvents() + { + innerWebClient.OpenReadCompleted += OnOpenReadCompleted; + innerWebClient.OpenWriteCompleted += OnOpenWriteCompleted; + + innerWebClient.DownloadDataCompleted += DownloadDataCompleted; + innerWebClient.DownloadFileCompleted += DownloadFileCompleted; + innerWebClient.DownloadStringCompleted += DownloadStringCompleted; + innerWebClient.UploadDataCompleted += UploadDataCompleted; + innerWebClient.UploadFileCompleted += UploadFileCompleted; + innerWebClient.UploadStringCompleted += UploadStringCompleted; + innerWebClient.UploadValuesCompleted += UploadValuesCompleted; + + innerWebClient.DownloadProgressChanged += DownloadProgressChanged; + innerWebClient.UploadProgressChanged += UploadProgressChanged; + } + + private void UnhookEvents() + { + innerWebClient.OpenReadCompleted -= OnOpenReadCompleted; + innerWebClient.OpenWriteCompleted -= OnOpenWriteCompleted; + + innerWebClient.DownloadDataCompleted -= DownloadDataCompleted; + innerWebClient.DownloadFileCompleted -= DownloadFileCompleted; + innerWebClient.DownloadStringCompleted -= DownloadStringCompleted; + innerWebClient.UploadDataCompleted -= UploadDataCompleted; + innerWebClient.UploadFileCompleted -= UploadFileCompleted; + innerWebClient.UploadStringCompleted -= UploadStringCompleted; + innerWebClient.UploadValuesCompleted -= UploadValuesCompleted; + + innerWebClient.DownloadProgressChanged -= DownloadProgressChanged; + innerWebClient.UploadProgressChanged -= UploadProgressChanged; + } + + public event OpenReadCompletedEventHandler OpenReadCompleted; + public event OpenWriteCompletedEventHandler OpenWriteCompleted; + public event DownloadStringCompletedEventHandler DownloadStringCompleted; + public event DownloadDataCompletedEventHandler DownloadDataCompleted; + public event DownloadProgressChangedEventHandler DownloadProgressChanged; + public event AsyncCompletedEventHandler DownloadFileCompleted; + public event UploadStringCompletedEventHandler UploadStringCompleted; + public event UploadDataCompletedEventHandler UploadDataCompleted; + public event UploadFileCompletedEventHandler UploadFileCompleted; + public event UploadValuesCompletedEventHandler UploadValuesCompleted; + public event UploadProgressChangedEventHandler UploadProgressChanged; + + #region Event Invocators + protected virtual void OnOpenReadCompleted(object sender, OpenReadCompletedEventArgs e) + { + OpenReadCompletedEventHandler handler = OpenReadCompleted; + if (handler != null) handler(this, e); + } + + protected virtual void OnOpenWriteCompleted(object sender, OpenWriteCompletedEventArgs e) + { + OpenWriteCompletedEventHandler handler = OpenWriteCompleted; + if (handler != null) handler(this, e); + } + + protected virtual void OnDownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) + { + DownloadStringCompletedEventHandler handler = DownloadStringCompleted; + if (handler != null) handler(this, e); + } + + protected virtual void OnDownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e) + { + DownloadDataCompletedEventHandler handler = DownloadDataCompleted; + if (handler != null) handler(this, e); + } + + protected virtual void OnDownloadFileCompleted(object sender, AsyncCompletedEventArgs e) + { + AsyncCompletedEventHandler handler = DownloadFileCompleted; + if (handler != null) handler(this, e); + } + + protected virtual void OnUploadStringCompleted(object sender, UploadStringCompletedEventArgs e) + { + UploadStringCompletedEventHandler handler = UploadStringCompleted; + if (handler != null) handler(this, e); + } + + protected virtual void OnUploadDataCompleted(object sender, UploadDataCompletedEventArgs e) + { + UploadDataCompletedEventHandler handler = UploadDataCompleted; + if (handler != null) handler(this, e); + } + + protected virtual void OnUploadFileCompleted(object sender, UploadFileCompletedEventArgs e) + { + UploadFileCompletedEventHandler handler = UploadFileCompleted; + if (handler != null) handler(this, e); + } + + protected virtual void OnUploadValuesCompleted(object sender, UploadValuesCompletedEventArgs e) + { + UploadValuesCompletedEventHandler handler = UploadValuesCompleted; + if (handler != null) handler(this, e); + } + + protected virtual void OnDownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) + { + DownloadProgressChangedEventHandler handler = DownloadProgressChanged; + if (handler != null) handler(this, e); + } + + protected virtual void OnUploadProgressChanged(object sender, UploadProgressChangedEventArgs e) + { + UploadProgressChangedEventHandler handler = UploadProgressChanged; + if (handler != null) handler(this, e); + } + #endregion + + /// + /// Releases all resources used by the . + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + /// + /// Releases the unmanaged resources used by the and + /// optionally releases the managed resources. + /// + /// + /// true to release both managed and unmanaged resources; false to release only unmanaged resources. + /// + protected virtual void Dispose(bool disposing) + { + if (disposing) + { + if (innerWebClient != null) + { + UnhookEvents(); + innerWebClient.Dispose(); + } + } + } + } +} diff --git a/src/Rothko.csproj b/src/Rothko.csproj index 2c23100..0ad64f3 100644 --- a/src/Rothko.csproj +++ b/src/Rothko.csproj @@ -52,6 +52,7 @@ + @@ -70,6 +71,7 @@ + @@ -91,6 +93,10 @@ + + + +