This commit is contained in:
stubbfel
2013-06-18 15:22:50 +02:00
parent 38b379c6d6
commit 518bbc00ce
5 changed files with 45 additions and 26 deletions

View File

@@ -183,6 +183,7 @@
<Compile Include="Utility\URLList.cs" />
<Compile Include="Utility\XmlApi.cs" />
<Compile Include="Utility\XmlFeed.cs" />
<Compile Include="Utility\XmlManager.cs" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">

View File

@@ -13,7 +13,7 @@
<Capability Name="ID_CAP_ISV_CAMERA" />
</Capabilities>
<Tasks>
<DefaultTask Name="_default" NavigationPage="pages/StartPage.xaml" />
<DefaultTask Name="_default" NavigationPage="pages/mensa/MensaPage.xaml" />
</Tasks>
<Tokens>
<PrimaryToken TokenID="CampusAppWP8Token" TaskName="_default">

View File

@@ -10,8 +10,6 @@ namespace CampusAppWP8.Utility
using System;
using System.Collections.Generic;
using System.Net;
using System.Xml.Linq;
using System.Xml.Serialization;
using CampusAppWP8.Model.Utility;
using CampusAppWP8.Resources;
@@ -140,16 +138,7 @@ namespace CampusAppWP8.Utility
/// <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());
T model = XmlManager.DeserializationToModel<T>(xmlString, ValidRootName);
if (model != null)
{
this.Model = model;

View File

@@ -0,0 +1,40 @@
//-----------------------------------------------------------------------
// <copyright file="XmlManager.cs" company="BTU/IIT">
// Company copyright tag.
// </copyright>
// <author>stubbfel</author>
// <sience>18.06.2013</sience>
//----------------------------------------------------------------------
namespace CampusAppWP8.Utility
{
using System.Xml.Linq;
using System.Xml.Serialization;
/// <summary>
/// Class provides some Xml-methods
/// </summary>
public class XmlManager
{
/// <summary>
/// Method deserialization a string to a Model
/// </summary>
/// <typeparam name="T">the model</typeparam>
/// <param name="xmlString">the XmlString</param>
/// <param name="validRootName">name of the RootTag</param>
/// <returns>return the deserialization of the model</returns>
public static T DeserializationToModel<T>(string xmlString, string validRootName)
{
XmlSerializer serializer = new XmlSerializer(typeof(T));
XDocument document = XDocument.Parse(xmlString);
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());
return model;
}
}
}

View File

@@ -8,9 +8,7 @@
namespace CampusAppWP8.Utility
{
using System;
using System.Xml.Linq;
using System.Xml.Serialization;
using CampusAppWP8.Resources;
using CampusAppWP8.Resources;
/// <summary>
/// This abstract Class is for Xml-feeds
@@ -72,16 +70,7 @@ namespace CampusAppWP8.Utility
/// <param name="feedString">content of the feed</param>
protected override void Deserialization(string feedString)
{
XmlSerializer serializer = new XmlSerializer(typeof(T));
XDocument document = XDocument.Parse(feedString);
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());
T model = XmlManager.DeserializationToModel<T>(feedString, ValidRootName);
if (model != null)
{
this.Model = model;