add restthhp method
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="Feed.cs" company="BTU/IIT">
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="RestApi.cs" company="BTU/IIT">
|
||||
// Company copyright tag.
|
||||
// </copyright>
|
||||
// <author>stubbfel</author>
|
||||
// <sience>03.05.2013</sience>
|
||||
// <sience>10.06.2013</sience>
|
||||
//----------------------------------------------------------------------using System;
|
||||
|
||||
namespace CampusAppWP8.Utility
|
||||
{
|
||||
using System;
|
||||
@@ -16,27 +14,172 @@ namespace CampusAppWP8.Utility
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
/// <summary>
|
||||
/// Class realize the access of restful RestAPI
|
||||
/// </summary>
|
||||
public class RestApi
|
||||
{
|
||||
#region Members
|
||||
WebClient client;
|
||||
|
||||
/// <summary>
|
||||
/// the WebClient, which send the requests
|
||||
/// </summary>
|
||||
private WebClient client;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RestApi" /> class.
|
||||
/// </summary>
|
||||
public RestApi()
|
||||
{
|
||||
client = new WebClient();
|
||||
this.client = new WebClient();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RestApi" /> class.
|
||||
/// </summary>
|
||||
/// <param name="apiBaseAddress">the url of the RestAPI base address</param>
|
||||
public RestApi(Uri apiBaseAddress)
|
||||
{
|
||||
this.client = new WebClient();
|
||||
this.client.BaseAddress = apiBaseAddress.AbsoluteUri;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
#region public
|
||||
public void HttpGet(Uri url, Action<object, DownloadStringCompletedEventArgs> action)
|
||||
|
||||
/// <summary>
|
||||
/// Method realize the http-get-method resource
|
||||
/// </summary>
|
||||
/// <param name="url">Url of the resource</param>
|
||||
/// <param name="action">callback method</param>
|
||||
public void HttpGet(Uri url, Action<object, DownloadStringCompletedEventArgs> action)
|
||||
{
|
||||
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(action);
|
||||
client.DownloadStringAsync(url);
|
||||
this.client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(action);
|
||||
this.client.DownloadStringAsync(url);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method realize the http-delete-method
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// is not supported by WebClient
|
||||
/// </remarks>
|
||||
/// <param name="url">Url of the resource</param>
|
||||
/// <param name="action">callback method</param>
|
||||
public void HttpDelete(Uri url, Action<object, DownloadStringCompletedEventArgs> action)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method realize the http-delete-method
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// is not supported by WebClient
|
||||
/// </remarks>
|
||||
/// <param name="url">Url of the resource</param>
|
||||
/// <param name="action">callback method</param>
|
||||
public void HttpHead(Uri url, Action<object, DownloadStringCompletedEventArgs> action)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method realize the http-delete-method
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// is not supported by WebClient
|
||||
/// </remarks>
|
||||
/// <param name="url">Url of the resource</param>
|
||||
/// <param name="action">callback method</param>
|
||||
public void HttpOptions(Uri url, Action<object, DownloadStringCompletedEventArgs> action)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method realize the http-delete-method
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// is not supported by WebClient
|
||||
/// </remarks>
|
||||
/// <param name="url">Url of the resource</param>
|
||||
/// <param name="action">callback method</param>
|
||||
public void HttpConnect(Uri url, Action<object, DownloadStringCompletedEventArgs> action)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method realize the http-delete-method
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// is not supported by WebClient
|
||||
/// </remarks>
|
||||
/// <param name="url">Url of the resource</param>
|
||||
/// <param name="action">callback method</param>
|
||||
public void HttpTrace(Uri url, Action<object, DownloadStringCompletedEventArgs> action)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method realize the http-post-method
|
||||
/// </summary>
|
||||
/// <param name="url">Url of the resource</param>
|
||||
/// <param name="action">callback method</param>
|
||||
/// <param name="postData">Data which are sending via post to the RestAPI</param>
|
||||
public void HttpPost(Uri url, Action<object, UploadStringCompletedEventArgs> action, string postData)
|
||||
{
|
||||
this.UploadData(url, action, "POST", postData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method realize the http-get-method
|
||||
/// </summary>
|
||||
/// <param name="url">Url of the resource</param>
|
||||
/// <param name="action">callback method</param>
|
||||
/// <param name="putData">Data which are sending via put to the RestAPI</param>
|
||||
public void HttpPut(Uri url, Action<object, UploadStringCompletedEventArgs> action, string putData)
|
||||
{
|
||||
this.UploadData(url, action, "PUT", putData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method realize the http-get-method
|
||||
/// </summary>
|
||||
/// <param name="url">Url of the resource</param>
|
||||
/// <param name="action">callback method</param>
|
||||
/// <param name="patchData">Data which are sending via patch to the RestAPI</param>
|
||||
public void HttpPatch(Uri url, Action<object, UploadStringCompletedEventArgs> action, string patchData)
|
||||
{
|
||||
this.UploadData(url, action, "PATCH", patchData);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region private
|
||||
|
||||
/// <summary>
|
||||
/// Method uploaded Data to the RestAPI
|
||||
/// </summary>
|
||||
/// <param name="url">Url of the resource</param>
|
||||
/// <param name="action">callback method</param>
|
||||
/// <param name="method">name of APIMethod, how the data will be uploaded</param>
|
||||
/// <param name="data">Data which are sending to the RestAPI</param>
|
||||
private void UploadData(Uri url, Action<object, UploadStringCompletedEventArgs> action, string method, string data)
|
||||
{
|
||||
this.client.UploadStringCompleted += new UploadStringCompletedEventHandler(action);
|
||||
this.client.UploadStringAsync(url, method, data);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,8 +119,6 @@ namespace CampusAppWP8.Utility
|
||||
/// </summary>
|
||||
public void LoadFeed()
|
||||
{
|
||||
this.DownloadFeed();
|
||||
return;
|
||||
if (this.IsModelUpToDate())
|
||||
{
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user