add doku + refactor to lectur and api #33

This commit is contained in:
stubbfel
2013-06-17 13:48:10 +02:00
parent a2463795f9
commit 5dbcc01dd2
15 changed files with 301 additions and 150 deletions

View File

@@ -1,5 +1,5 @@
//-----------------------------------------------------------------------
// <copyright file="LectureFeed.cs" company="BTU/IIT">
// <copyright file="LectureApi.cs" company="BTU/IIT">
// Company copyright tag.
// </copyright>
// <author>stubbfel</author>
@@ -9,8 +9,8 @@ namespace CampusAppWP8.Feed.Lecture
{
using System;
using CampusAppWP8.Model.Lecture;
using CampusAppWP8.Utility;
using CampusAppWP8.Resources;
using CampusAppWP8.Utility;
/// <summary>
/// Class for the feed of the Lecture
@@ -23,11 +23,10 @@ namespace CampusAppWP8.Feed.Lecture
/// <summary>
/// Initializes a new instance of the <see cref="LectureApi" /> class.
/// </summary>
/// <param name="url">the RequestUrl</param>
public LectureApi()
: base(new Uri(Constants.UrlLectureApiBaseAddr))
: base(new Uri(Constants.UrlLecture_ApiBaseAddr))
{
this.validRootName = "lsf_auszug";
this.ValidRootName = Constants.LectureXmlValidRootName;
}
}
}

View File

@@ -90,7 +90,7 @@ namespace CampusAppWP8.Model.Lecture
/// </summary>
private void CreateUrl()
{
this.url = new Uri(Constants.UrlLectureModulBaseAddr + this.number.ToString());
this.url = new Uri(Constants.UrlLecture_ModulBaseAddr + this.number.ToString());
}
#endregion

View File

@@ -22,12 +22,11 @@
</Grid.RowDefinitions>
<!--TitlePanel enthält den Namen der Anwendung und den Seitentitel-->
<ProgressBar Name="ProgressBar" Visibility="Collapsed" IsIndeterminate="True"/>
<StackPanel Grid.Row="0" Margin="12,17,0,28">
<Border BorderBrush="{StaticResource PhoneBorderBrush}" BorderThickness="0,0,0,2" >
<TextBlock Text="{Binding Path=LocalizedResources.LectureApp_Title, Source={StaticResource LocalizedStrings}}"/>
</Border>
<ProgressBar Name="ProgressBar" Visibility="Collapsed" IsIndeterminate="True"/>
</Border>
</StackPanel>

View File

@@ -24,7 +24,7 @@ namespace CampusAppWP8.Pages.Lecture
public partial class LecturePage : PhoneApplicationPage
{
/// <summary>
/// actual LectureFeed
/// actual LectureAPI
/// </summary>
private LectureApi api;
@@ -149,6 +149,10 @@ namespace CampusAppWP8.Pages.Lecture
this.api.XMLHttpGet(parameterList);
}
/// <summary>
/// Method read the values from the inputs and put them in a list of parameters
/// </summary>
/// <returns>a list of parameters</returns>
private List<UrlParamModel> CreateUrlParameter()
{
ListPickerItemModel semester = (ListPickerItemModel)this.Semester.SelectedItem;
@@ -158,22 +162,22 @@ namespace CampusAppWP8.Pages.Lecture
ListPickerItemModel to = (ListPickerItemModel)this.To.SelectedItem;
List<UrlParamModel> parameterList = new List<UrlParamModel>();
parameterList.Add(new UrlParamModel("Semester",semester.Value));
parameterList.Add(new UrlParamModel("Abschluss", degree.Value));
parameterList.Add(new UrlParamModel("Studiengang", course.Value));
parameterList.Add(new UrlParamModel("Von", from.Value));
parameterList.Add(new UrlParamModel("Bis", to.Value));
parameterList.Add(new UrlParamModel(Constants.ParamGetLecture_Semester, semester.Value));
parameterList.Add(new UrlParamModel(Constants.ParamGetLecture_Degree, degree.Value));
parameterList.Add(new UrlParamModel(Constants.ParamGetLecture_Course, course.Value));
parameterList.Add(new UrlParamModel(Constants.ParamGetLecture_From, from.Value));
parameterList.Add(new UrlParamModel(Constants.ParamGetLecture_To, to.Value));
return parameterList;
}
/// <summary>
/// Method will be execute if the feed is ready
/// </summary>
private void ApiIsReady()
{
App.SaveToIsolatedStorage<LectureList>(Constants.IsolatedStorageLectureModel, this.api.Model);
App.SaveToIsolatedStorage<LectureList>(Constants.IsolatedStorage_LectureModel, this.api.Model);
this.ProgressBar.Visibility = System.Windows.Visibility.Collapsed;
Uri url = new Uri(Constants.PathResultPage, UriKind.Relative);
Uri url = new Uri(Constants.PathLecture_ResultPage, UriKind.Relative);
NavigationService.Navigate(url);
}
}

View File

@@ -13,7 +13,7 @@ namespace CampusAppWP8.Pages.Lecture
using Microsoft.Phone.Controls;
/// <summary>
/// Class for the page which shows Webpages from the BaseAddress <see cref="Constants.UrlLectureModulBaseAddr" />
/// Class for the page which shows Webpages from the BaseAddress <see cref="Constants.UrlLecture_ModulBaseAddr" />
/// </summary>
public partial class ModulWebPage : PhoneApplicationPage
{
@@ -31,10 +31,10 @@ namespace CampusAppWP8.Pages.Lecture
/// <param name="e">Arguments of navigation</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (NavigationContext.QueryString.ContainsKey(Constants.ParamLectureModulNumber))
if (NavigationContext.QueryString.ContainsKey(Constants.ParamModelLecture_ModulNumber))
{
string number = NavigationContext.QueryString[Constants.ParamLectureModulNumber];
this.WebmailBrowser.Navigate(new Uri(Constants.UrlLectureModulBaseAddr + number, UriKind.Absolute));
string number = NavigationContext.QueryString[Constants.ParamModelLecture_ModulNumber];
this.WebmailBrowser.Navigate(new Uri(Constants.UrlLecture_ModulBaseAddr + number, UriKind.Absolute));
}
base.OnNavigatedTo(e);

View File

@@ -31,9 +31,9 @@ namespace CampusAppWP8.Pages.Lecture
/// <param name="e">Arguments of navigation</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (NavigationContext.QueryString.ContainsKey(Constants.ParamLectureActivityId))
if (NavigationContext.QueryString.ContainsKey(Constants.ParamModelLecture_ActivityId))
{
string activityId = NavigationContext.QueryString[Constants.ParamLectureActivityId];
string activityId = NavigationContext.QueryString[Constants.ParamModelLecture_ActivityId];
this.LoadActivity(int.Parse(activityId));
}
@@ -46,7 +46,7 @@ namespace CampusAppWP8.Pages.Lecture
/// <param name="activityId">id of the activity</param>
private void LoadActivity(int activityId)
{
LectureList list = App.LoadFromIsolatedStorage<LectureList>(Constants.IsolatedStorageLectureModel);
LectureList list = App.LoadFromIsolatedStorage<LectureList>(Constants.IsolatedStorage_LectureModel);
if (list != null)
{
LectureActivity activity = list.GetActivity(activityId);

View File

@@ -39,7 +39,7 @@ namespace CampusAppWP8.Pages.Lecture
/// <param name="e">Arguments of navigation</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
LectureList list = App.LoadFromIsolatedStorage<LectureList>(Constants.IsolatedStorageLectureModel);
LectureList list = App.LoadFromIsolatedStorage<LectureList>(Constants.IsolatedStorage_LectureModel);
this.ResultList.ItemsSource = list.Activities;
base.OnNavigatedTo(e);
}
@@ -132,7 +132,7 @@ namespace CampusAppWP8.Pages.Lecture
private void ShowModulWebPage(object sender, RoutedEventArgs e)
{
Button btn = (Button)sender;
Uri url = new Uri(Constants.PathLectureModulWebPage + "?" + Constants.ParamLectureModulNumber + "=" + btn.Tag, UriKind.Relative);
Uri url = new Uri(Constants.PathLecture_ModulWebPage + "?" + Constants.ParamModelLecture_ModulNumber + "=" + btn.Tag, UriKind.Relative);
NavigationService.Navigate(url);
}
@@ -144,7 +144,7 @@ namespace CampusAppWP8.Pages.Lecture
private void ShowDetailPage(object sender, RoutedEventArgs e)
{
Button btn = (Button)sender;
Uri url = new Uri(Constants.PathResultDetailPage + "?" + Constants.ParamLectureActivityId + "=" + btn.Tag, UriKind.Relative);
Uri url = new Uri(Constants.PathLecture_ResultDetailPage + "?" + Constants.ParamModelLecture_ActivityId + "=" + btn.Tag, UriKind.Relative);
NavigationService.Navigate(url);
}
}

View File

@@ -30,7 +30,7 @@ namespace CampusAppWP8.Pages.Webmail
/// </summary>
private void LoadWebmailPage()
{
this.WebmailBrowser.Navigate(new Uri(Constants.UrlWebMailAddr, UriKind.Absolute));
this.WebmailBrowser.Navigate(new Uri(Constants.UrlWebMail_Addr, UriKind.Absolute));
}
}
}

View File

@@ -63,27 +63,81 @@ namespace CampusAppWP8.Resources {
/// <summary>
/// Sucht eine lokalisierte Zeichenfolge, die LectureModel ähnelt.
/// </summary>
internal static string IsolatedStorageLectureModel {
internal static string IsolatedStorage_LectureModel {
get {
return ResourceManager.GetString("IsolatedStorageLectureModel", resourceCulture);
return ResourceManager.GetString("IsolatedStorage_LectureModel", resourceCulture);
}
}
/// <summary>
/// Sucht eine lokalisierte Zeichenfolge, die lsf_auszug ähnelt.
/// </summary>
internal static string LectureXmlValidRootName {
get {
return ResourceManager.GetString("LectureXmlValidRootName", resourceCulture);
}
}
/// <summary>
/// Sucht eine lokalisierte Zeichenfolge, die Studiengang ähnelt.
/// </summary>
internal static string ParamGetLecture_Course {
get {
return ResourceManager.GetString("ParamGetLecture_Course", resourceCulture);
}
}
/// <summary>
/// Sucht eine lokalisierte Zeichenfolge, die Abschluss ähnelt.
/// </summary>
internal static string ParamGetLecture_Degree {
get {
return ResourceManager.GetString("ParamGetLecture_Degree", resourceCulture);
}
}
/// <summary>
/// Sucht eine lokalisierte Zeichenfolge, die Von ähnelt.
/// </summary>
internal static string ParamGetLecture_From {
get {
return ResourceManager.GetString("ParamGetLecture_From", resourceCulture);
}
}
/// <summary>
/// Sucht eine lokalisierte Zeichenfolge, die Semester ähnelt.
/// </summary>
internal static string ParamGetLecture_Semester {
get {
return ResourceManager.GetString("ParamGetLecture_Semester", resourceCulture);
}
}
/// <summary>
/// Sucht eine lokalisierte Zeichenfolge, die Bis ähnelt.
/// </summary>
internal static string ParamGetLecture_To {
get {
return ResourceManager.GetString("ParamGetLecture_To", resourceCulture);
}
}
/// <summary>
/// Sucht eine lokalisierte Zeichenfolge, die ActivityId ähnelt.
/// </summary>
internal static string ParamLectureActivityId {
internal static string ParamModelLecture_ActivityId {
get {
return ResourceManager.GetString("ParamLectureActivityId", resourceCulture);
return ResourceManager.GetString("ParamModelLecture_ActivityId", resourceCulture);
}
}
/// <summary>
/// Sucht eine lokalisierte Zeichenfolge, die ModulNumber ähnelt.
/// </summary>
internal static string ParamLectureModulNumber {
internal static string ParamModelLecture_ModulNumber {
get {
return ResourceManager.GetString("ParamLectureModulNumber", resourceCulture);
return ResourceManager.GetString("ParamModelLecture_ModulNumber", resourceCulture);
}
}
@@ -99,54 +153,54 @@ namespace CampusAppWP8.Resources {
/// <summary>
/// Sucht eine lokalisierte Zeichenfolge, die /Pages/Lecture/ModulWebPage.xaml ähnelt.
/// </summary>
internal static string PathLectureModulWebPage {
internal static string PathLecture_ModulWebPage {
get {
return ResourceManager.GetString("PathLectureModulWebPage", resourceCulture);
return ResourceManager.GetString("PathLecture_ModulWebPage", resourceCulture);
}
}
/// <summary>
/// Sucht eine lokalisierte Zeichenfolge, die /Pages/Lecture/ResultDetailPage.xaml ähnelt.
/// </summary>
internal static string PathResultDetailPage {
internal static string PathLecture_ResultDetailPage {
get {
return ResourceManager.GetString("PathResultDetailPage", resourceCulture);
return ResourceManager.GetString("PathLecture_ResultDetailPage", resourceCulture);
}
}
/// <summary>
/// Sucht eine lokalisierte Zeichenfolge, die /Pages/Lecture/ResultPage.xaml ähnelt.
/// </summary>
internal static string PathResultPage {
internal static string PathLecture_ResultPage {
get {
return ResourceManager.GetString("PathResultPage", resourceCulture);
return ResourceManager.GetString("PathLecture_ResultPage", resourceCulture);
}
}
/// <summary>
/// Sucht eine lokalisierte Zeichenfolge, die http://www.zv.tu-cottbus.de/LSFveranst/LSF4 ähnelt.
/// </summary>
internal static string UrlLectureApiBaseAddr {
internal static string UrlLecture_ApiBaseAddr {
get {
return ResourceManager.GetString("UrlLectureApiBaseAddr", resourceCulture);
return ResourceManager.GetString("UrlLecture_ApiBaseAddr", resourceCulture);
}
}
/// <summary>
/// Sucht eine lokalisierte Zeichenfolge, die https://www.tu-cottbus.de/modul/ ähnelt.
/// </summary>
internal static string UrlLectureModulBaseAddr {
internal static string UrlLecture_ModulBaseAddr {
get {
return ResourceManager.GetString("UrlLectureModulBaseAddr", resourceCulture);
return ResourceManager.GetString("UrlLecture_ModulBaseAddr", resourceCulture);
}
}
/// <summary>
/// Sucht eine lokalisierte Zeichenfolge, die https://webmail.tu-cottbus.de ähnelt.
/// </summary>
internal static string UrlWebMailAddr {
internal static string UrlWebMail_Addr {
get {
return ResourceManager.GetString("UrlWebMailAddr", resourceCulture);
return ResourceManager.GetString("UrlWebMail_Addr", resourceCulture);
}
}

View File

@@ -117,37 +117,55 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="IsolatedStorageLectureModel" xml:space="preserve">
<data name="IsolatedStorage_LectureModel" xml:space="preserve">
<value>LectureModel</value>
</data>
<data name="ParamLectureActivityId" xml:space="preserve">
<data name="ParamModelLecture_ActivityId" xml:space="preserve">
<value>ActivityId</value>
</data>
<data name="ParamLectureModulNumber" xml:space="preserve">
<data name="ParamModelLecture_ModulNumber" xml:space="preserve">
<value>ModulNumber</value>
</data>
<data name="ParamUrl" xml:space="preserve">
<value>Url</value>
</data>
<data name="PathLectureModulWebPage" xml:space="preserve">
<data name="PathLecture_ModulWebPage" xml:space="preserve">
<value>/Pages/Lecture/ModulWebPage.xaml</value>
</data>
<data name="PathResultDetailPage" xml:space="preserve">
<data name="PathLecture_ResultDetailPage" xml:space="preserve">
<value>/Pages/Lecture/ResultDetailPage.xaml</value>
</data>
<data name="UrlLectureModulBaseAddr" xml:space="preserve">
<data name="UrlLecture_ModulBaseAddr" xml:space="preserve">
<value>https://www.tu-cottbus.de/modul/</value>
</data>
<data name="XMLRootElementName" xml:space="preserve">
<value>root</value>
</data>
<data name="UrlWebMailAddr" xml:space="preserve">
<data name="UrlWebMail_Addr" xml:space="preserve">
<value>https://webmail.tu-cottbus.de</value>
</data>
<data name="PathResultPage" xml:space="preserve">
<data name="PathLecture_ResultPage" xml:space="preserve">
<value>/Pages/Lecture/ResultPage.xaml</value>
</data>
<data name="UrlLectureApiBaseAddr" xml:space="preserve">
<data name="LectureXmlValidRootName" xml:space="preserve">
<value>lsf_auszug</value>
</data>
<data name="ParamGetLecture_Course" xml:space="preserve">
<value>Studiengang</value>
</data>
<data name="ParamGetLecture_Degree" xml:space="preserve">
<value>Abschluss</value>
</data>
<data name="ParamGetLecture_From" xml:space="preserve">
<value>Von</value>
</data>
<data name="ParamGetLecture_Semester" xml:space="preserve">
<value>Semester</value>
</data>
<data name="ParamGetLecture_To" xml:space="preserve">
<value>Bis</value>
</data>
<data name="UrlLecture_ApiBaseAddr" xml:space="preserve">
<value>http://www.zv.tu-cottbus.de/LSFveranst/LSF4</value>
</data>
</root>

View File

@@ -1,13 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//-----------------------------------------------------------------------
// <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}"/>
/// This class handle the events of a API <see cref="RestApi{T}"/>
/// </summary>
public class ApiEventHandler
{

View File

@@ -7,10 +7,10 @@
//----------------------------------------------------------------------using System;
namespace CampusAppWP8.Utility
{
using CampusAppWP8.Model.Utility;
using System;
using System.Collections.Generic;
using System.Net;
using CampusAppWP8.Model.Utility;
/// <summary>
/// Class realize the access of restful RestAPI
@@ -66,14 +66,16 @@ namespace CampusAppWP8.Utility
/// Method create the Url for the http-get-method
/// </summary>
/// <param name="parameters"> list of parameters</param>
/// <returns></returns>
/// <returns>absolute API-Url include GetParameter</returns>
public Uri CreateGetUrl(List<UrlParamModel> parameters)
{
string paramterStr = string.Empty;
foreach(UrlParamModel parameter in parameters){
foreach (UrlParamModel parameter in parameters)
{
paramterStr += parameter.ToString();
}
string getUrlStr = client.BaseAddress + "?" + paramterStr;
string getUrlStr = this.client.BaseAddress + "?" + paramterStr;
return new Uri(getUrlStr, UriKind.Absolute);
}
@@ -91,7 +93,7 @@ namespace CampusAppWP8.Utility
}
/// <summary>
/// Method realize the http-delete-method
/// Method realize the http-head-method
/// </summary>
/// <remarks>
/// is not supported by WebClient
@@ -104,7 +106,7 @@ namespace CampusAppWP8.Utility
}
/// <summary>
/// Method realize the http-delete-method
/// Method realize the http-options-method
/// </summary>
/// <remarks>
/// is not supported by WebClient
@@ -117,7 +119,7 @@ namespace CampusAppWP8.Utility
}
/// <summary>
/// Method realize the http-delete-method
/// Method realize the http-connect-method
/// </summary>
/// <remarks>
/// is not supported by WebClient
@@ -130,7 +132,7 @@ namespace CampusAppWP8.Utility
}
/// <summary>
/// Method realize the http-delete-method
/// Method realize the http-trace-method
/// </summary>
/// <remarks>
/// is not supported by WebClient
@@ -154,7 +156,7 @@ namespace CampusAppWP8.Utility
}
/// <summary>
/// Method realize the http-get-method
/// Method realize the http-put-method
/// </summary>
/// <param name="url">Url of the resource</param>
/// <param name="action">callback method</param>
@@ -165,7 +167,7 @@ namespace CampusAppWP8.Utility
}
/// <summary>
/// Method realize the http-get-method
/// Method realize the http-patch-method
/// </summary>
/// <param name="url">Url of the resource</param>
/// <param name="action">callback method</param>

View File

@@ -1,37 +1,63 @@
using CampusAppWP8.Model.Utility;
using CampusAppWP8.Resources;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using System.Xml.Serialization;
//-----------------------------------------------------------------------
// <copyright file="XmlApi.cs" company="BTU/IIT">
// Company copyright tag.
// </copyright>
// <author>stubbfel</author>
// <sience>13.06.2013</sience>
//----------------------------------------------------------------------
namespace CampusAppWP8.Utility
{
public class XmlApi<T> : RestApi
using System;
using System.Collections.Generic;
using System.Net;
using System.Xml.Linq;
using System.Xml.Serialization;
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> : RestApi
{
/// <summary>
/// The model of the feed
/// </summary>
private T model;
protected string validRootName = Constants.XMLRootElementName;
#region Members
/// <summary>
/// EventHandler of the api
/// EventHandler of the API
/// </summary>
private readonly ApiEventHandler eventHandler;
public XmlApi(Uri apiBaseAddress): base(apiBaseAddress)
/// <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;
#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.eventHandler = new ApiEventHandler();
}
#endregion
#region Proberty
/// <summary>
/// Gets or sets for the model of the feed
/// Gets or sets for the model of the API
/// </summary>
public T Model
{
@@ -50,7 +76,7 @@ namespace CampusAppWP8.Utility
}
/// <summary>
/// Gets for the event-handler of the feed
/// Gets for the event-handler of the API
/// </summary>
public ApiEventHandler EventHandler
{
@@ -58,11 +84,84 @@ namespace CampusAppWP8.Utility
}
/// <summary>
/// Method will be execute if the download of the feed is completed and create the model
/// 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
#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)
{
XmlSerializer serializer = new XmlSerializer(typeof(T));
XDocument document = XDocument.Parse(xmlString);
if (!document.Root.Name.ToString().Equals(this.ValidRootName))
{
XElement content = document.Root;
document = new XDocument();
document.Add(new XElement(this.ValidRootName, content));
}
T model = (T)serializer.Deserialize(document.CreateReader());
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>
public void DownloadCompleted(object sender, DownloadStringCompletedEventArgs e)
private void DownloadCompleted(object sender, DownloadStringCompletedEventArgs e)
{
Exception downloadError = e.Error;
if (downloadError != null)
@@ -76,53 +175,7 @@ namespace CampusAppWP8.Utility
this.CreateModel(downloadResult);
}
}
/// <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 XMLHttpGet(List<UrlParamModel> parameters)
{
Uri getUrl = this.CreateGetUrl(parameters);
this.HttpGet(getUrl, this.DownloadCompleted);
}
/// <summary>
/// Method create the model of the feed
/// </summary>
/// <param name="xmlString">content of the feed</param>
private void CreateModel(string xmlString)
{
if (xmlString == null || xmlString == string.Empty)
{
return;
}
this.Deserialization(xmlString);
this.EventHandler.FireApiReadyevent();
}
/// <summary>
/// Method implement the deserialization a Xml-feed
/// </summary>
/// <param name="feedString">content of the feed</param>
protected void Deserialization(string feedString)
{
XmlSerializer serializer = new XmlSerializer(typeof(T));
XDocument document = XDocument.Parse(feedString);
if (!document.Root.Name.ToString().Equals(validRootName))
{
XElement content = document.Root;
document = new XDocument();
document.Add(new XElement(validRootName, content));
}
T model = (T)serializer.Deserialize(document.CreateReader());
if (model != null)
{
this.Model = model;
}
}
#endregion
#endregion
}
}

View File

@@ -14,7 +14,7 @@ namespace CampusAppWP8.Utility
/// This a abstract Class for reading, store and deserialization Feeds from the Web.
/// </summary>
/// <typeparam name="T">Type for model of the feed</typeparam>
public abstract class Feed<T>:RestApi
public abstract class Feed<T> : RestApi
{
#region Member

View File

@@ -19,9 +19,9 @@ namespace CampusAppWP8.Utility
public abstract class XmlFeed<T> : Feed<T>
{
/// <summary>
/// Variablo for the name of the roottag
/// Variable for the name of the root-tag
/// </summary>
protected string validRootName = Constants.XMLRootElementName;
private string validRootName = Constants.XMLRootElementName;
#region Constructor
@@ -43,6 +43,27 @@ namespace CampusAppWP8.Utility
}
#endregion
#region Proberty
/// <summary>
/// Gets or sets the ValidRootName of the feed
/// </summary>
protected string ValidRootName
{
get
{
return this.validRootName;
}
set
{
if (value != this.validRootName)
{
this.validRootName = value;
}
}
}
#endregion
#region Methods
/// <summary>
@@ -53,11 +74,11 @@ namespace CampusAppWP8.Utility
{
XmlSerializer serializer = new XmlSerializer(typeof(T));
XDocument document = XDocument.Parse(feedString);
if (!document.Root.Name.ToString().Equals(validRootName))
if (!document.Root.Name.ToString().Equals(this.ValidRootName))
{
XElement content = document.Root;
document = new XDocument();
document.Add(new XElement(validRootName, content));
document.Add(new XElement(this.ValidRootName, content));
}
T model = (T)serializer.Deserialize(document.CreateReader());