rm api und xmlapi
This commit is contained in:
@@ -206,8 +206,6 @@
|
||||
<DependentUpon>Constants.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="ThemelizedIcons.cs" />
|
||||
<Compile Include="Utility\Api.cs" />
|
||||
<Compile Include="Utility\ApiEventHandler.cs" />
|
||||
<Compile Include="Utility\File.cs" />
|
||||
<Compile Include="Utility\Logger.cs" />
|
||||
<Compile Include="Utility\HttpRequest.cs" />
|
||||
@@ -221,7 +219,6 @@
|
||||
<Compile Include="Utility\Utilities.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Utility\XmlApi.cs" />
|
||||
<Compile Include="Utility\XmlManager.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -60,6 +60,17 @@ namespace CampusAppWP8.Model.Utility
|
||||
return this.key;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the token, which indicate that tha paramterlist started
|
||||
/// </summary>
|
||||
public string ParamToken
|
||||
{
|
||||
get
|
||||
{
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
@@ -1,144 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="Api.cs" company="BTU/IIT">
|
||||
// Company copyright tag.
|
||||
// </copyright>
|
||||
// <author>stubbfel</author>
|
||||
// <sience>19.06.2013</sience>
|
||||
//----------------------------------------------------------------------
|
||||
namespace CampusAppWP8.Utility
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using CampusAppWP8.Model.Utility;
|
||||
|
||||
/// <summary>
|
||||
/// This abstract Class is for API
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type for model of the API</typeparam>
|
||||
public abstract class Api<T> : HttpRequest
|
||||
{
|
||||
#region Members
|
||||
|
||||
/// <summary>
|
||||
/// EventHandler of the API
|
||||
/// </summary>
|
||||
private readonly ApiEventHandler eventHandler;
|
||||
|
||||
/// <summary>
|
||||
/// The model of the API
|
||||
/// </summary>
|
||||
private T model;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Api{T}" /> class.
|
||||
/// </summary>
|
||||
/// <param name="apiBaseAddress">BaseUrl of the API</param>
|
||||
public Api(Uri apiBaseAddress)
|
||||
: base(apiBaseAddress)
|
||||
{
|
||||
this.eventHandler = new ApiEventHandler();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Proberty
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets for the model of the API
|
||||
/// </summary>
|
||||
public T Model
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.model;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if ((value == null && this.model != null) || !value.Equals(this.model))
|
||||
{
|
||||
this.model = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets for the event-handler of the API
|
||||
/// </summary>
|
||||
public ApiEventHandler EventHandler
|
||||
{
|
||||
get { return this.eventHandler; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
#region public
|
||||
|
||||
/// <summary>
|
||||
/// Method send an HTTP-Get for an API
|
||||
/// </summary>
|
||||
/// <param name="parameters">list of GetParameter</param>
|
||||
public void ApiGet(List<UrlParamModel> parameters)
|
||||
{
|
||||
Uri getUrl = this.CreateGetUrl(parameters);
|
||||
this.HttpGet(getUrl, this.DownloadCompleted);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region protected
|
||||
|
||||
/// <summary>
|
||||
/// Method implement the deserialization a Xml-API
|
||||
/// </summary>
|
||||
/// <param name="xmlString">content of the API</param>
|
||||
protected abstract void Deserialization(string xmlString);
|
||||
|
||||
#endregion
|
||||
|
||||
#region private
|
||||
|
||||
/// <summary>
|
||||
/// Method create the model of the API
|
||||
/// </summary>
|
||||
/// <param name="resultString">content of the API</param>
|
||||
private void CreateModel(string resultString)
|
||||
{
|
||||
if (resultString == null || resultString == string.Empty)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.Deserialization(resultString);
|
||||
this.EventHandler.FireApiReadyevent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method will be execute if the download of the API is completed and create the model
|
||||
/// </summary>
|
||||
/// <param name="sender">Sender of the event</param>
|
||||
/// <param name="e">Arguments of the event</param>
|
||||
private void DownloadCompleted(object sender, DownloadStringCompletedEventArgs e)
|
||||
{
|
||||
Exception downloadError = e.Error;
|
||||
if (downloadError != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string downloadResult = e.Result;
|
||||
if (downloadResult != null && !downloadResult.Equals(string.Empty))
|
||||
{
|
||||
this.CreateModel(downloadResult);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="ApiEventHandler.cs" company="BTU/IIT">
|
||||
// Company copyright tag.
|
||||
// </copyright>
|
||||
// <author>stubbfel</author>
|
||||
// <sience>17.06.2013</sience>
|
||||
//----------------------------------------------------------------------
|
||||
namespace CampusAppWP8.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// This class handle the events of a API <see cref="RestApi{T}"/>
|
||||
/// </summary>
|
||||
public class ApiEventHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ApiEventHandler" /> class.
|
||||
/// </summary>
|
||||
public ApiEventHandler()
|
||||
{
|
||||
}
|
||||
|
||||
#region Delegate&Events
|
||||
/// <summary>
|
||||
/// Delegate for the ready event
|
||||
/// </summary>
|
||||
public delegate void ApiReadyHandler();
|
||||
|
||||
/// <summary>
|
||||
/// The ready event
|
||||
/// </summary>
|
||||
public event ApiReadyHandler ApiIsReadyEvent;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Method
|
||||
|
||||
/// <summary>
|
||||
/// Method fire a ready event
|
||||
/// </summary>
|
||||
public void FireApiReadyevent()
|
||||
{
|
||||
this.ApiIsReadyEvent();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -68,12 +68,18 @@ namespace CampusAppWP8.Utility
|
||||
public Uri CreateGetUrl(List<UrlParamModel> parameters)
|
||||
{
|
||||
string paramterStr = string.Empty;
|
||||
string seperator = string.Empty;
|
||||
foreach (UrlParamModel parameter in parameters)
|
||||
{
|
||||
if (string.Empty.Equals(seperator))
|
||||
{
|
||||
seperator = parameter.ParamToken;
|
||||
}
|
||||
|
||||
paramterStr += parameter.ToString();
|
||||
}
|
||||
|
||||
string getUrlStr = baseAddress + "?" + paramterStr;
|
||||
string getUrlStr = baseAddress + seperator + paramterStr;
|
||||
return new Uri(getUrlStr, UriKind.Absolute);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="XmlApi.cs" company="BTU/IIT">
|
||||
// Company copyright tag.
|
||||
// </copyright>
|
||||
// <author>stubbfel</author>
|
||||
// <sience>13.06.2013</sience>
|
||||
//----------------------------------------------------------------------
|
||||
namespace CampusAppWP8.Utility
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using CampusAppWP8.Model.Utility;
|
||||
using CampusAppWP8.Resources;
|
||||
|
||||
/// <summary>
|
||||
/// This abstract Class is for Xml-API
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type for model of the API</typeparam>
|
||||
public abstract class XmlApi<T> : Api<T>
|
||||
{
|
||||
#region Members
|
||||
|
||||
/// <summary>
|
||||
/// Variable for the name of the root-tag
|
||||
/// </summary>
|
||||
private string validRootName;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="XmlApi{T}" /> class.
|
||||
/// </summary>
|
||||
/// <param name="apiBaseAddress">BaseUrl of the API</param>
|
||||
public XmlApi(Uri apiBaseAddress)
|
||||
: base(apiBaseAddress)
|
||||
{
|
||||
this.validRootName = Constants.XMLRootElementName;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Proberty
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ValidRootName of the API
|
||||
/// </summary>
|
||||
protected string ValidRootName
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.validRootName;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value != this.validRootName)
|
||||
{
|
||||
this.validRootName = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Method implement the deserialization a Xml-API
|
||||
/// </summary>
|
||||
/// <param name="xmlString">content of the API</param>
|
||||
protected override void Deserialization(string xmlString)
|
||||
{
|
||||
T model = XmlManager.DeserializationToModel<T>(xmlString, this.ValidRootName);
|
||||
if (model != null)
|
||||
{
|
||||
this.Model = model;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user