add api class
This commit is contained in:
@@ -172,6 +172,7 @@
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Constants.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Utility\Api.cs" />
|
||||
<Compile Include="Utility\ApiEventHandler.cs" />
|
||||
<Compile Include="Utility\Feed.cs" />
|
||||
<Compile Include="Utility\FeedEventHandler.cs" />
|
||||
|
||||
@@ -167,7 +167,7 @@ namespace CampusAppWP8.Pages.Lecture
|
||||
this.api.EventHandler.ApiIsReadyEvent += new ApiEventHandler.ApiReadyHandler(this.ApiIsReady);
|
||||
this.ProgressBar.Visibility = System.Windows.Visibility.Visible;
|
||||
List<UrlParamModel> parameterList = this.CreateUrlParameter();
|
||||
this.api.XMLHttpGet(parameterList);
|
||||
this.api.ApiGet(parameterList);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -133,6 +133,7 @@ namespace CampusAppWP8.Pages.Lecture
|
||||
private void ShowModulWebPage(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Button btn = (Button)sender;
|
||||
HideOptions((StackPanel)btn.Parent);
|
||||
Uri url = new Uri(Constants.PathLecture_ModulWebPage + "?" + Constants.ParamModelLecture_ModulNumber + "=" + btn.Tag, UriKind.Relative);
|
||||
NavigationService.Navigate(url);
|
||||
}
|
||||
@@ -145,6 +146,7 @@ namespace CampusAppWP8.Pages.Lecture
|
||||
private void ShowDetailPage(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Button btn = (Button)sender;
|
||||
HideOptions((StackPanel)btn.Parent);
|
||||
Uri url = new Uri(Constants.PathLecture_ResultDetailPage + "?" + Constants.ParamModelLecture_ActivityId + "=" + btn.Tag, UriKind.Relative);
|
||||
NavigationService.Navigate(url);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<Capability Name="ID_CAP_ISV_CAMERA" />
|
||||
</Capabilities>
|
||||
<Tasks>
|
||||
<DefaultTask Name="_default" NavigationPage="pages/StartPage.xaml" />
|
||||
<DefaultTask Name="_default" NavigationPage="pages/Lecture/LecturePage.xaml" />
|
||||
</Tasks>
|
||||
<Tokens>
|
||||
<PrimaryToken TokenID="CampusAppWP8Token" TaskName="_default">
|
||||
|
||||
140
CampusAppWP8/CampusAppWP8/Utility/Api.cs
Normal file
140
CampusAppWP8/CampusAppWP8/Utility/Api.cs
Normal file
@@ -0,0 +1,140 @@
|
||||
using CampusAppWP8.Model.Utility;
|
||||
//-----------------------------------------------------------------------
|
||||
// <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;
|
||||
|
||||
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="XmlApi{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
|
||||
}
|
||||
}
|
||||
@@ -17,24 +17,14 @@ namespace CampusAppWP8.Utility
|
||||
/// This abstract Class is for Xml-API
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type for model of the API</typeparam>
|
||||
public abstract class XmlApi<T> : HttpRequest
|
||||
public abstract class XmlApi<T> : Api<T>
|
||||
{
|
||||
#region Members
|
||||
|
||||
/// <summary>
|
||||
/// EventHandler of the API
|
||||
/// </summary>
|
||||
private readonly ApiEventHandler eventHandler;
|
||||
|
||||
/// <summary>
|
||||
/// The model of the API
|
||||
/// </summary>
|
||||
private T model;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Variable for the name of the root-tag
|
||||
/// </summary>
|
||||
private string validRootName = Constants.XMLRootElementName;
|
||||
private string validRootName;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -47,40 +37,13 @@ namespace CampusAppWP8.Utility
|
||||
public XmlApi(Uri apiBaseAddress)
|
||||
: base(apiBaseAddress)
|
||||
{
|
||||
this.eventHandler = new ApiEventHandler();
|
||||
this.validRootName = Constants.XMLRootElementName;
|
||||
}
|
||||
|
||||
#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; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ValidRootName of the API
|
||||
/// </summary>
|
||||
@@ -103,40 +66,12 @@ namespace CampusAppWP8.Utility
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
#region public
|
||||
|
||||
/// <summary>
|
||||
/// Method send an HTTP-Get for an Xml-API
|
||||
/// </summary>
|
||||
/// <param name="parameters">list of GetParameter</param>
|
||||
public void XMLHttpGet(List<UrlParamModel> parameters)
|
||||
{
|
||||
Uri getUrl = this.CreateGetUrl(parameters);
|
||||
this.HttpGet(getUrl, this.DownloadCompleted);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method create the model of the API
|
||||
/// </summary>
|
||||
/// <param name="xmlString">content of the API</param>
|
||||
private void CreateModel(string xmlString)
|
||||
{
|
||||
if (xmlString == null || xmlString == string.Empty)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.Deserialization(xmlString);
|
||||
this.EventHandler.FireApiReadyevent();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region private
|
||||
|
||||
/// <summary>
|
||||
/// Method implement the deserialization a Xml-API
|
||||
/// </summary>
|
||||
/// <param name="xmlString">content of the API</param>
|
||||
private void Deserialization(string xmlString)
|
||||
protected override void Deserialization(string xmlString)
|
||||
{
|
||||
T model = XmlManager.DeserializationToModel<T>(xmlString, ValidRootName);
|
||||
if (model != null)
|
||||
@@ -144,27 +79,6 @@ namespace CampusAppWP8.Utility
|
||||
this.Model = model;
|
||||
}
|
||||
}
|
||||
|
||||
/// <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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user