Merge branch 'release/rdel' into develmaster

This commit is contained in:
stubbfel
2013-07-16 14:00:15 +02:00
7 changed files with 3 additions and 542 deletions

View File

@@ -208,10 +208,7 @@
<Compile Include="ThemelizedIcons.cs" />
<Compile Include="Utility\Api.cs" />
<Compile Include="Utility\ApiEventHandler.cs" />
<Compile Include="Utility\Feed.cs" />
<Compile Include="Utility\FeedEventHandler.cs" />
<Compile Include="Utility\File.cs" />
<Compile Include="Utility\FileManager.cs" />
<Compile Include="Utility\Logger.cs" />
<Compile Include="Utility\HttpRequest.cs" />
<Compile Include="Utility\Lui\Button\GoToMapButton.cs" />
@@ -224,8 +221,6 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="Utility\XmlApi.cs" />
<Compile Include="Utility\XmlFeed.cs" />
<Compile Include="Utility\XmlFile.cs" />
<Compile Include="Utility\XmlManager.cs" />
</ItemGroup>
<ItemGroup>

View File

@@ -255,6 +255,9 @@
<data name="FileEvents_Name" xml:space="preserve">
<value>EventsFeed.xml</value>
</data>
<data name="FileEvents_Name" xml:space="preserve">
<value>EventsFeed.xml</value>
</data>
<data name="UrlMensa_Week" xml:space="preserve">
<value>http://www.studentenwerk-frankfurt.de/2011/ClassPackage/App_IKMZ_BTU/</value>
</data>

View File

@@ -1,249 +0,0 @@
//-----------------------------------------------------------------------
// <copyright file="Feed.cs" company="BTU/IIT">
// Company copyright tag.
// </copyright>
// <author>stubbfel</author>
// <sience>03.05.2013</sience>
//----------------------------------------------------------------------
namespace CampusAppWP8.Utility
{
using System;
using System.Net;
/// <summary>
/// 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> : HttpRequest
{
#region Member
/// <summary>
/// URL of the feed
/// </summary>
private readonly Uri feedURL;
/// <summary>
/// EventHandler of the feed
/// </summary>
private readonly FeedEventHandler eventHandler;
/// <summary>
/// Filename for the storage-file of the feed
/// </summary>
private readonly string fileName;
/// <summary>
/// The model of the feed
/// </summary>
private T model;
#endregion
#region Constructor
/// <summary>
/// Initializes a new instance of the <see cref="Feed{T}" /> class.
/// </summary>
public Feed()
{
this.eventHandler = new FeedEventHandler();
}
/// <summary>
/// Initializes a new instance of the <see cref="Feed{T}" /> class.
/// </summary>
/// <param name="feedURL">Url of the Feed</param>
/// <param name="fileName">Name of the file, which the feed will be stored</param>
public Feed(Uri feedURL, string fileName)
{
this.feedURL = feedURL;
this.eventHandler = new FeedEventHandler();
this.fileName = fileName;
}
#endregion
#region Proberty
/// <summary>
/// Gets for the url of the feed
/// </summary>
public Uri FeedURL
{
get { return this.feedURL; }
}
/// <summary>
/// Gets for the event-handler of the feed
/// </summary>
public FeedEventHandler EventHandler
{
get { return this.eventHandler; }
}
/// <summary>
/// Gets or sets for the model of the feed
/// </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 storage-file of the feed
/// </summary>
public string FileName
{
get { return this.fileName; }
}
#endregion
#region Methods
#region public
/// <summary>
/// Method load the feed with content. At first is try to load from model, then from file and at last from the web.
/// </summary>
public void LoadFeed()
{
if (this.IsModelUpToDate())
{
this.EventHandler.FireFeedReadyevent();
return;
}
if (this.IsFileUpToDate())
{
this.LoadFile();
}
else
{
this.DownloadFeed();
}
}
#endregion
#region protected
/// <summary>
/// The abstract method check if the content of the file is up-to-date, its has to implement by subclasses
/// </summary>
/// <returns>true if its up-to-date, otherwise false</returns>
protected abstract bool CheckIsFileUpToDate();
/// <summary>
/// The abstract method check if the content of the model is up-to-date, its has to implement by subclasses
/// </summary>
/// <returns>true if its up-to-date, otherwise false</returns>
protected abstract bool CheckIsModelUpToDate();
/// <summary>
/// The abstract method convert feed to a model, its has to implement by subclasses
/// </summary>
/// <param name="feedString">content of the feed</param>
protected abstract void Deserialization(string feedString);
#endregion
#region private
/// <summary>
/// Method load content from the file and create the model
/// </summary>
private void LoadFile()
{
string feedString = FileManager.ReadFile(this.FileName);
this.CreateModel(feedString);
}
/// <summary>
/// Method load content from the web
/// </summary>
private void DownloadFeed()
{
this.HttpGet(this.FeedURL, this.DownloadCompleted);
}
/// <summary>
/// Method check if the content of the file is up-to-date
/// </summary>
/// <returns>true if its up-to-date, otherwise false</returns>
private bool IsFileUpToDate()
{
if (!FileManager.ExistsFile(this.FileName))
{
return false;
}
return this.CheckIsFileUpToDate();
}
/// <summary>
/// Method check if the content of the model is up-to-date
/// </summary>
/// <returns>true if its up-to-date, otherwise false</returns>
private bool IsModelUpToDate()
{
if (this.Model != null)
{
return this.CheckIsModelUpToDate();
}
return false;
}
/// <summary>
/// Method will be execute if the download of the feed 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);
FileManager.WriteFile(this.FileName, downloadResult);
}
}
/// <summary>
/// Method create the model of the feed
/// </summary>
/// <param name="feedString">content of the feed</param>
private void CreateModel(string feedString)
{
if (feedString == null || feedString == string.Empty)
{
return;
}
this.Deserialization(feedString);
this.EventHandler.FireFeedReadyevent();
}
#endregion
#endregion
}
}

View File

@@ -1,54 +0,0 @@
//-----------------------------------------------------------------------
// <copyright file="FeedEventHandler.cs" company="BTU/IIT">
// Company copyright tag.
// </copyright>
// <author>stubbfel</author>
// <sience>03.05.2013</sience>
//----------------------------------------------------------------------
namespace CampusAppWP8.Utility
{
/// <summary>
/// This class handle the events of a feed <see cref="Feed{T}"/>
/// </summary>
public class FeedEventHandler
{
#region Constructor
/// <summary>
/// Initializes a new instance of the <see cref="FeedEventHandler" /> class.
/// </summary>
public FeedEventHandler()
{
}
#endregion
#region Delegate&Events
/// <summary>
/// Delegate for the ready event
/// </summary>
public delegate void FeedReadyHandler();
/// <summary>
/// The ready event
/// </summary>
public event FeedReadyHandler FeedIsReadyEvent;
#endregion
#region Method
/// <summary>
/// Method fire a ready event
/// </summary>
public void FireFeedReadyevent()
{
if (this.FeedIsReadyEvent != null)
{
this.FeedIsReadyEvent();
}
}
#endregion
}
}

View File

@@ -1,115 +0,0 @@
//-----------------------------------------------------------------------
// <copyright file="FileManager.cs" company="BTU/IIT">
// Company copyright tag.
// </copyright>
// <author>stubbfel</author>
// <sience>03.05.2013</sience>
//----------------------------------------------------------------------
namespace CampusAppWP8.Utility
{
using System;
using System.IO;
using System.Text;
using Windows.Storage;
/// <summary>
/// This a static Class, which provide some method for files
/// </summary>
public static class FileManager
{
#region members
/// <summary>
/// Member for the local folder
/// </summary>
private static readonly IStorageFolder LocalFolder = ApplicationData.Current.LocalFolder;
#endregion
#region public
/// <summary>
/// Method write a content to an file
/// </summary>
/// <param name="fileName">name of the file</param>
/// <param name="content">content of the file</param>
public static void WriteFile(string fileName, string content)
{
WriteFileAsync(fileName, content);
}
/// <summary>
/// Method read content from a file
/// </summary>
/// <remarks>
/// Method crash sometimes by OpenStreamForReadAsync() or OpenAccessStream()
/// </remarks>
/// <param name="fileName">name of the file</param>
/// <returns>content of the file, null if file doesn't exist</returns>
public static string ReadFile(string fileName)
{
string content = null;
if (!ExistsFile(fileName))
{
return null;
}
using (Stream fileStream = LocalFolder.OpenStreamForReadAsync(fileName).Result)
{
using (StreamReader streamReader = new StreamReader(fileStream))
{
content = streamReader.ReadToEnd();
}
}
return content;
}
/// <summary>
/// Method return info of a file
/// </summary>
/// <param name="fileName">name of the file</param>
/// <returns>info of the file</returns>
public static FileInfo GetFileInfo(string fileName)
{
FileInfo info = new FileInfo(LocalFolder.Path + "\\" + fileName);
return info;
}
/// <summary>
/// Method check if a file is existing
/// </summary>
/// <param name="fileName">name of the file</param>
/// <returns>true if file exists, otherwise false</returns>
public static bool ExistsFile(string fileName)
{
return GetFileInfo(fileName).Exists;
}
#endregion
#region private
/// <summary>
/// Method write a content to a new file. If the file exists, it will be replaced
/// </summary>
/// <remarks>
/// Method crash sometimes by OpenStreamForWriteAsync() or OpenAccessStream()
/// </remarks>
/// <param name="fileName">name of the file</param>
/// <param name="content">content of the file</param>
private static async void WriteFileAsync(string fileName, string content)
{
IStorageFile storageFile = await LocalFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
using (Stream stream = await storageFile.OpenStreamForWriteAsync())
{
byte[] contentByte = Encoding.UTF8.GetBytes(content);
//await stream.WriteAsync(contentByte, 0, contentByte.Length);
stream.Write(contentByte, 0, contentByte.Length);
}
}
#endregion
}
}

View File

@@ -1,81 +0,0 @@
//-----------------------------------------------------------------------
// <copyright file="XmlFeed.cs" company="BTU/IIT">
// Company copyright tag.
// </copyright>
// <author>stubbfel</author>
// <sience>03.05.2013</sience>
//----------------------------------------------------------------------
namespace CampusAppWP8.Utility
{
using System;
using CampusAppWP8.Resources;
/// <summary>
/// This abstract Class is for Xml-feeds
/// </summary>
/// <typeparam name="T">Type for model of the feed</typeparam>
public abstract class XmlFeed<T> : Feed<T>
{
/// <summary>
/// Variable for the name of the root-tag
/// </summary>
private string validRootName = Constants.XMLRootElementName;
#region Constructor
/// <summary>
/// Initializes a new instance of the <see cref="XmlFeed{T}" /> class.
/// </summary>
public XmlFeed()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="XmlFeed{T}" /> class.
/// </summary>
/// <param name="feedURL">Url of the Feed</param>
/// <param name="fileName">Name of the file, which the feed will be stored</param>
public XmlFeed(Uri feedURL, string fileName)
: base(feedURL, fileName)
{
}
#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>
/// Method implement the deserialization a Xml-feed
/// </summary>
/// <param name="feedString">content of the feed</param>
protected override void Deserialization(string feedString)
{
T model = XmlManager.DeserializationToModel<T>(feedString, ValidRootName);
if (model != null)
{
this.Model = model;
}
}
#endregion
}
}

View File

@@ -1,38 +0,0 @@
//-----------------------------------------------------------------------------
// <copyright file="XmlFile.cs" company="BTU/IIT">
// Company copyright tag.
// </copyright>
// <author>fiedlchr</author>
// <sience>05.07.2013</sience>
//-----------------------------------------------------------------------------
namespace CampusAppWP8.Utility
{
using CampusAppWP8.Resources;
public class XmlFile<T> : File
{
public XmlFile(string filename) : base(filename, IOTypeRead.ReadAsync, IOTypeWrite.WriteSync)
{
}
public bool LoadModel(T model)
{
bool retValue = true;
string data = this.ReadFile();
if ((data == null)
|| (data.Equals(string.Empty) == true))
{
retValue = false;
}
else
{
model = XmlManager.DeserializationToModel<T>(data, Constants.XMLRootElementName);
}
return retValue;
}
}
}