Merge branch 'release/r#48' into develmaster

This commit is contained in:
stubbfel
2013-06-19 10:37:41 +02:00
5 changed files with 155 additions and 94 deletions

View File

@@ -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" />

View File

@@ -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>

View File

@@ -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);
}

View File

@@ -0,0 +1,144 @@
//-----------------------------------------------------------------------
// <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
}
}

View File

@@ -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,68 +66,19 @@ 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);
T model = XmlManager.DeserializationToModel<T>(xmlString, this.ValidRootName);
if (model != null)
{
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
}
}