diff --git a/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj b/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj index 7e4ac706..c3933669 100644 --- a/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj +++ b/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj @@ -208,10 +208,7 @@ - - - @@ -224,8 +221,6 @@ Code - - diff --git a/CampusAppWP8/CampusAppWP8/Resources/Constants.resx b/CampusAppWP8/CampusAppWP8/Resources/Constants.resx index d3d546e9..f106b186 100644 --- a/CampusAppWP8/CampusAppWP8/Resources/Constants.resx +++ b/CampusAppWP8/CampusAppWP8/Resources/Constants.resx @@ -255,6 +255,9 @@ EventsFeed.xml + + EventsFeed.xml + http://www.studentenwerk-frankfurt.de/2011/ClassPackage/App_IKMZ_BTU/ diff --git a/CampusAppWP8/CampusAppWP8/utility/Feed.cs b/CampusAppWP8/CampusAppWP8/utility/Feed.cs deleted file mode 100644 index 9a118158..00000000 --- a/CampusAppWP8/CampusAppWP8/utility/Feed.cs +++ /dev/null @@ -1,249 +0,0 @@ -//----------------------------------------------------------------------- -// -// Company copyright tag. -// -// stubbfel -// 03.05.2013 -//---------------------------------------------------------------------- -namespace CampusAppWP8.Utility -{ - using System; - using System.Net; - - /// - /// This a abstract Class for reading, store and deserialization Feeds from the Web. - /// - /// Type for model of the feed - public abstract class Feed : HttpRequest - { - #region Member - - /// - /// URL of the feed - /// - private readonly Uri feedURL; - - /// - /// EventHandler of the feed - /// - private readonly FeedEventHandler eventHandler; - - /// - /// Filename for the storage-file of the feed - /// - private readonly string fileName; - - /// - /// The model of the feed - /// - private T model; - - #endregion - - #region Constructor - - /// - /// Initializes a new instance of the class. - /// - public Feed() - { - this.eventHandler = new FeedEventHandler(); - } - - /// - /// Initializes a new instance of the class. - /// - /// Url of the Feed - /// Name of the file, which the feed will be stored - public Feed(Uri feedURL, string fileName) - { - this.feedURL = feedURL; - this.eventHandler = new FeedEventHandler(); - this.fileName = fileName; - } - - #endregion - - #region Proberty - - /// - /// Gets for the url of the feed - /// - public Uri FeedURL - { - get { return this.feedURL; } - } - - /// - /// Gets for the event-handler of the feed - /// - public FeedEventHandler EventHandler - { - get { return this.eventHandler; } - } - - /// - /// Gets or sets for the model of the feed - /// - public T Model - { - get - { - return this.model; - } - - set - { - if ((value == null && this.model != null) || !value.Equals(this.model)) - { - this.model = value; - } - } - } - - /// - /// Gets for the storage-file of the feed - /// - public string FileName - { - get { return this.fileName; } - } - - #endregion - - #region Methods - - #region public - /// - /// Method load the feed with content. At first is try to load from model, then from file and at last from the web. - /// - public void LoadFeed() - { - if (this.IsModelUpToDate()) - { - this.EventHandler.FireFeedReadyevent(); - return; - } - - if (this.IsFileUpToDate()) - { - this.LoadFile(); - } - else - { - this.DownloadFeed(); - } - } - - #endregion - - #region protected - - /// - /// The abstract method check if the content of the file is up-to-date, its has to implement by subclasses - /// - /// true if its up-to-date, otherwise false - protected abstract bool CheckIsFileUpToDate(); - - /// - /// The abstract method check if the content of the model is up-to-date, its has to implement by subclasses - /// - /// true if its up-to-date, otherwise false - protected abstract bool CheckIsModelUpToDate(); - - /// - /// The abstract method convert feed to a model, its has to implement by subclasses - /// - /// content of the feed - protected abstract void Deserialization(string feedString); - - #endregion - - #region private - - /// - /// Method load content from the file and create the model - /// - private void LoadFile() - { - string feedString = FileManager.ReadFile(this.FileName); - this.CreateModel(feedString); - } - - /// - /// Method load content from the web - /// - private void DownloadFeed() - { - this.HttpGet(this.FeedURL, this.DownloadCompleted); - } - - /// - /// Method check if the content of the file is up-to-date - /// - /// true if its up-to-date, otherwise false - private bool IsFileUpToDate() - { - if (!FileManager.ExistsFile(this.FileName)) - { - return false; - } - - return this.CheckIsFileUpToDate(); - } - - /// - /// Method check if the content of the model is up-to-date - /// - /// true if its up-to-date, otherwise false - private bool IsModelUpToDate() - { - if (this.Model != null) - { - return this.CheckIsModelUpToDate(); - } - - return false; - } - - /// - /// Method will be execute if the download of the feed is completed and create the model - /// - /// Sender of the event - /// Arguments of the event - 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); - } - } - - /// - /// Method create the model of the feed - /// - /// content of the feed - private void CreateModel(string feedString) - { - if (feedString == null || feedString == string.Empty) - { - return; - } - - this.Deserialization(feedString); - this.EventHandler.FireFeedReadyevent(); - } - - #endregion - - #endregion - } -} diff --git a/CampusAppWP8/CampusAppWP8/utility/FeedEventHandler.cs b/CampusAppWP8/CampusAppWP8/utility/FeedEventHandler.cs deleted file mode 100644 index cc5a4e94..00000000 --- a/CampusAppWP8/CampusAppWP8/utility/FeedEventHandler.cs +++ /dev/null @@ -1,54 +0,0 @@ -//----------------------------------------------------------------------- -// -// Company copyright tag. -// -// stubbfel -// 03.05.2013 -//---------------------------------------------------------------------- -namespace CampusAppWP8.Utility -{ - /// - /// This class handle the events of a feed - /// - public class FeedEventHandler - { - #region Constructor - - /// - /// Initializes a new instance of the class. - /// - public FeedEventHandler() - { - } - - #endregion - - #region Delegate&Events - /// - /// Delegate for the ready event - /// - public delegate void FeedReadyHandler(); - - /// - /// The ready event - /// - public event FeedReadyHandler FeedIsReadyEvent; - - #endregion - - #region Method - - /// - /// Method fire a ready event - /// - public void FireFeedReadyevent() - { - if (this.FeedIsReadyEvent != null) - { - this.FeedIsReadyEvent(); - } - } - - #endregion - } -} diff --git a/CampusAppWP8/CampusAppWP8/utility/FileManager.cs b/CampusAppWP8/CampusAppWP8/utility/FileManager.cs deleted file mode 100644 index 884a4edb..00000000 --- a/CampusAppWP8/CampusAppWP8/utility/FileManager.cs +++ /dev/null @@ -1,115 +0,0 @@ -//----------------------------------------------------------------------- -// -// Company copyright tag. -// -// stubbfel -// 03.05.2013 -//---------------------------------------------------------------------- -namespace CampusAppWP8.Utility -{ - using System; - using System.IO; - using System.Text; - using Windows.Storage; - - /// - /// This a static Class, which provide some method for files - /// - public static class FileManager - { - #region members - - /// - /// Member for the local folder - /// - private static readonly IStorageFolder LocalFolder = ApplicationData.Current.LocalFolder; - - #endregion - - #region public - - /// - /// Method write a content to an file - /// - /// name of the file - /// content of the file - public static void WriteFile(string fileName, string content) - { - WriteFileAsync(fileName, content); - } - - /// - /// Method read content from a file - /// - /// - /// Method crash sometimes by OpenStreamForReadAsync() or OpenAccessStream() - /// - /// name of the file - /// content of the file, null if file doesn't exist - 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; - } - - /// - /// Method return info of a file - /// - /// name of the file - /// info of the file - public static FileInfo GetFileInfo(string fileName) - { - FileInfo info = new FileInfo(LocalFolder.Path + "\\" + fileName); - return info; - } - - /// - /// Method check if a file is existing - /// - /// name of the file - /// true if file exists, otherwise false - public static bool ExistsFile(string fileName) - { - return GetFileInfo(fileName).Exists; - } - - #endregion - - #region private - - /// - /// Method write a content to a new file. If the file exists, it will be replaced - /// - /// - /// Method crash sometimes by OpenStreamForWriteAsync() or OpenAccessStream() - /// - /// name of the file - /// content of the file - 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 - } -} \ No newline at end of file diff --git a/CampusAppWP8/CampusAppWP8/utility/XMLFeed.cs b/CampusAppWP8/CampusAppWP8/utility/XMLFeed.cs deleted file mode 100644 index 36ad864f..00000000 --- a/CampusAppWP8/CampusAppWP8/utility/XMLFeed.cs +++ /dev/null @@ -1,81 +0,0 @@ -//----------------------------------------------------------------------- -// -// Company copyright tag. -// -// stubbfel -// 03.05.2013 -//---------------------------------------------------------------------- -namespace CampusAppWP8.Utility -{ - using System; - using CampusAppWP8.Resources; - - /// - /// This abstract Class is for Xml-feeds - /// - /// Type for model of the feed - public abstract class XmlFeed : Feed - { - /// - /// Variable for the name of the root-tag - /// - private string validRootName = Constants.XMLRootElementName; - - #region Constructor - - /// - /// Initializes a new instance of the class. - /// - public XmlFeed() - { - } - - /// - /// Initializes a new instance of the class. - /// - /// Url of the Feed - /// Name of the file, which the feed will be stored - public XmlFeed(Uri feedURL, string fileName) - : base(feedURL, fileName) - { - } - #endregion - - #region Proberty - /// - /// Gets or sets the ValidRootName of the feed - /// - protected string ValidRootName - { - get - { - return this.validRootName; - } - - set - { - if (value != this.validRootName) - { - this.validRootName = value; - } - } - } - #endregion - - #region Methods - - /// - /// Method implement the deserialization a Xml-feed - /// - /// content of the feed - protected override void Deserialization(string feedString) - { - T model = XmlManager.DeserializationToModel(feedString, ValidRootName); - if (model != null) - { - this.Model = model; - } - } - #endregion - } -} diff --git a/CampusAppWP8/CampusAppWP8/utility/XmlFile.cs b/CampusAppWP8/CampusAppWP8/utility/XmlFile.cs deleted file mode 100644 index 29196969..00000000 --- a/CampusAppWP8/CampusAppWP8/utility/XmlFile.cs +++ /dev/null @@ -1,38 +0,0 @@ -//----------------------------------------------------------------------------- -// -// Company copyright tag. -// -// fiedlchr -// 05.07.2013 -//----------------------------------------------------------------------------- -namespace CampusAppWP8.Utility -{ - using CampusAppWP8.Resources; - - public class XmlFile : 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(data, Constants.XMLRootElementName); - } - - return retValue; - } - - } -} \ No newline at end of file