diff --git a/CampusAppWP8/CampusAppWP8/Api/Lecture/LectureApi.cs b/CampusAppWP8/CampusAppWP8/Api/Lecture/LectureApi.cs index 885c86fc..ddcf309d 100644 --- a/CampusAppWP8/CampusAppWP8/Api/Lecture/LectureApi.cs +++ b/CampusAppWP8/CampusAppWP8/Api/Lecture/LectureApi.cs @@ -11,6 +11,7 @@ namespace CampusAppWP8.Feed.Lecture using CampusAppWP8.Model.Lecture; using CampusAppWP8.Resources; using CampusAppWP8.Utility; + using CampusAppWP8.Model; /// /// Class for the feed of the Lecture @@ -18,13 +19,13 @@ namespace CampusAppWP8.Feed.Lecture /// /// need the XmlAPI /// - public class LectureApi : XmlApi + public class LectureApi : XmlModel { /// /// Initializes a new instance of the class. /// public LectureApi() - : base(new Uri(Constants.UrlLecture_ApiBaseAddr)) + : base(ModelType.Feed, Constants.UrlLecture_ApiBaseAddr) { this.ValidRootName = Constants.LectureXmlValidRootName; } diff --git a/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj b/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj index 1c76561c..30b3410b 100644 --- a/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj +++ b/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj @@ -206,8 +206,6 @@ Constants.resx - - @@ -221,7 +219,6 @@ Code - diff --git a/CampusAppWP8/CampusAppWP8/Feed/Link/ClubLinkFeed.cs b/CampusAppWP8/CampusAppWP8/Feed/Link/ClubLinkFeed.cs index d6a0b9af..edcba0f7 100644 --- a/CampusAppWP8/CampusAppWP8/Feed/Link/ClubLinkFeed.cs +++ b/CampusAppWP8/CampusAppWP8/Feed/Link/ClubLinkFeed.cs @@ -27,8 +27,9 @@ namespace CampusAppWP8.Feed.Link public ClubLinkFeed() : base(ModelType.FileAndFeed, Constants.FileLink_ClubLinks, Constants.UrlLink_ClubLinks) { - this.isFileUpToDateOnLoad += new IsFileUpToDate(this.CheckIsFileUpToDateOnLoad); + this.isFileUpToDateOnLoad += new IsFileUpToDate(this.CheckIsFileUpToDate); this.isModelUpToDateOnLoad += new IsModelUpToDate(this.CheckIsModelUpToDate); + this.isFileUpToDateOnSave += new IsFileUpToDate(this.CheckIsFileUpToDate); } #endregion @@ -59,8 +60,13 @@ namespace CampusAppWP8.Feed.Link /// reference of the FeedModel /// info about the file /// true, if file is up-to-date, otherwise false - private bool CheckIsFileUpToDateOnLoad(LinkListModel model, FileInfo fileInfo) + private bool CheckIsFileUpToDate(LinkListModel model, FileInfo fileInfo) { + if (fileInfo == null || !fileInfo.Exists) + { + return false; + } + DateTime lastModified = fileInfo.LastWriteTime; return this.CheckIsUpToDate(lastModified); } diff --git a/CampusAppWP8/CampusAppWP8/Feed/Link/CommonLinkFeed.cs b/CampusAppWP8/CampusAppWP8/Feed/Link/CommonLinkFeed.cs index 721c5fc3..6b756de6 100644 --- a/CampusAppWP8/CampusAppWP8/Feed/Link/CommonLinkFeed.cs +++ b/CampusAppWP8/CampusAppWP8/Feed/Link/CommonLinkFeed.cs @@ -27,8 +27,8 @@ namespace CampusAppWP8.Feed.Link public CommonLinkFeed() : base(ModelType.FileAndFeed, Constants.FileLink_CommonLinks, Constants.UrlLink_CommonLinks) { - this.isFileUpToDateOnLoad += new IsFileUpToDate(this.CheckIsFileUpToDateOnLoad); - this.isFileUpToDateOnSave += new IsFileUpToDate(this.CheckIsFileUpToDateOnLoad); + this.isFileUpToDateOnLoad += new IsFileUpToDate(this.CheckIsFileUpToDate); + this.isFileUpToDateOnSave += new IsFileUpToDate(this.CheckIsFileUpToDate); this.isModelUpToDateOnLoad += new IsModelUpToDate(this.CheckIsModelUpToDate); } @@ -60,12 +60,19 @@ namespace CampusAppWP8.Feed.Link /// reference of the FeedModel /// info about the file /// true, if file is up-to-date, otherwise false - private bool CheckIsFileUpToDateOnLoad(LinkListModel model, FileInfo fileInfo) + private bool CheckIsFileUpToDate(LinkListModel model, FileInfo fileInfo) { + if (fileInfo == null || !fileInfo.Exists) + { + return false; + } + DateTime lastModified = fileInfo.LastWriteTime; return this.CheckIsUpToDate(lastModified); } + + /// /// Check if the model or file is up-to-date. /// diff --git a/CampusAppWP8/CampusAppWP8/Feed/Mensa/MensaFeed.cs b/CampusAppWP8/CampusAppWP8/Feed/Mensa/MensaFeed.cs index 9a1a2886..03b09f06 100644 --- a/CampusAppWP8/CampusAppWP8/Feed/Mensa/MensaFeed.cs +++ b/CampusAppWP8/CampusAppWP8/Feed/Mensa/MensaFeed.cs @@ -27,8 +27,9 @@ namespace CampusAppWP8.Feed.Mensa public MensaFeed() : base(ModelType.FileAndFeed, Constants.FileMensa_Shedule, Constants.UrlMensa_Week) { - this.isFileUpToDateOnLoad += new IsFileUpToDate(this.CheckIsFileUpToDateOnLoad); + this.isFileUpToDateOnLoad += new IsFileUpToDate(this.CheckIsFileUpToDate); this.isModelUpToDateOnLoad += new IsModelUpToDate(this.CheckIsModelUpToDate); + this.isFileUpToDateOnSave += new IsFileUpToDate(this.CheckIsFileUpToDate); } #endregion @@ -59,8 +60,13 @@ namespace CampusAppWP8.Feed.Mensa /// reference of the FeedModel /// info about the file /// true, if file is up-to-date, otherwise false - private bool CheckIsFileUpToDateOnLoad(MenuWeekModel model, FileInfo fileInfo) + private bool CheckIsFileUpToDate(MenuWeekModel model, FileInfo fileInfo) { + if (fileInfo == null || !fileInfo.Exists) + { + return false; + } + DateTime lastModified = fileInfo.LastWriteTime; return this.CheckIsUpToDate(lastModified); } diff --git a/CampusAppWP8/CampusAppWP8/Feed/StudentCouncil/StudentCouncilFeed.cs b/CampusAppWP8/CampusAppWP8/Feed/StudentCouncil/StudentCouncilFeed.cs index caaddd5c..64098618 100644 --- a/CampusAppWP8/CampusAppWP8/Feed/StudentCouncil/StudentCouncilFeed.cs +++ b/CampusAppWP8/CampusAppWP8/Feed/StudentCouncil/StudentCouncilFeed.cs @@ -27,8 +27,9 @@ namespace CampusAppWP8.Feed.StudentCouncil public StudentCouncilFeed() : base(ModelType.FileAndFeed, Constants.FileStudentCouncil_StudentCouncils, Constants.UrlStudentCouncil_StudentCouncils) { - this.isFileUpToDateOnLoad += new IsFileUpToDate(this.CheckIsFileUpToDateOnLoad); + this.isFileUpToDateOnLoad += new IsFileUpToDate(this.CheckIsFileUpToDate); this.isModelUpToDateOnLoad += new IsModelUpToDate(this.CheckIsModelUpToDate); + this.isFileUpToDateOnSave += new IsFileUpToDate(this.CheckIsFileUpToDate); } #endregion @@ -59,8 +60,13 @@ namespace CampusAppWP8.Feed.StudentCouncil /// reference of the FeedModel /// info about the file /// true, if file is up-to-date, otherwise false - private bool CheckIsFileUpToDateOnLoad(StudentCouncilListModel model, FileInfo fileInfo) + private bool CheckIsFileUpToDate(StudentCouncilListModel model, FileInfo fileInfo) { + if (fileInfo == null || !fileInfo.Exists) + { + return false; + } + DateTime lastModified = fileInfo.LastWriteTime; return this.CheckIsUpToDate(lastModified); } diff --git a/CampusAppWP8/CampusAppWP8/Model/Utility/URLParamModel.cs b/CampusAppWP8/CampusAppWP8/Model/Utility/URLParamModel.cs index c8d9c1a2..186f6d61 100644 --- a/CampusAppWP8/CampusAppWP8/Model/Utility/URLParamModel.cs +++ b/CampusAppWP8/CampusAppWP8/Model/Utility/URLParamModel.cs @@ -60,6 +60,17 @@ namespace CampusAppWP8.Model.Utility return this.key; } } + + /// + /// Gets or sets the token, which indicate that tha paramterlist started + /// + public string ParamToken + { + get + { + return "?"; + } + } #endregion #region Methods diff --git a/CampusAppWP8/CampusAppWP8/Model/XmlModel.cs b/CampusAppWP8/CampusAppWP8/Model/XmlModel.cs index 7803e0e8..ffb56040 100644 --- a/CampusAppWP8/CampusAppWP8/Model/XmlModel.cs +++ b/CampusAppWP8/CampusAppWP8/Model/XmlModel.cs @@ -26,6 +26,7 @@ namespace CampusAppWP8.Model public XmlModel(ModelType modelType, string fileName, string url) : base(modelType, fileName, url) { + this.ValidRootName = Constants.XMLRootElementName; } /// @@ -39,6 +40,11 @@ namespace CampusAppWP8.Model { } + /// + /// Gets or sets for the name of the root-tag + /// + protected string ValidRootName { get; set; } + /// /// Create the model from a xml byte array. /// @@ -50,7 +56,7 @@ namespace CampusAppWP8.Model string data = Encoding.UTF8.GetString(modelData, 0, modelData.Length); - T tempModel = XmlManager.DeserializationToModel(data, Constants.XMLRootElementName); + T tempModel = XmlManager.DeserializationToModel(data, this.ValidRootName); if (tempModel != null) { this.Model = tempModel; diff --git a/CampusAppWP8/CampusAppWP8/Pages/Lecture/LecturePage.xaml.cs b/CampusAppWP8/CampusAppWP8/Pages/Lecture/LecturePage.xaml.cs index 8afc016e..37f46e87 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/Lecture/LecturePage.xaml.cs +++ b/CampusAppWP8/CampusAppWP8/Pages/Lecture/LecturePage.xaml.cs @@ -167,10 +167,11 @@ namespace CampusAppWP8.Pages.Lecture private void SendRequest(object sender, RoutedEventArgs e) { this.api = new LectureApi(); - this.api.EventHandler.ApiIsReadyEvent += new ApiEventHandler.ApiReadyHandler(this.ApiIsReady); + this.api.onLoaded += new LectureApi.OnLoaded(this.ApiIsReady); this.ProgressBar.Visibility = System.Windows.Visibility.Visible; List parameterList = this.CreateUrlParameter(); - this.api.ApiGet(parameterList); + this.api.SetUriParams(parameterList); + this.api.LoadData(); } /// diff --git a/CampusAppWP8/CampusAppWP8/Pages/Lecture/ResultPage.xaml b/CampusAppWP8/CampusAppWP8/Pages/Lecture/ResultPage.xaml index d4d8c4f4..a2854ff7 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/Lecture/ResultPage.xaml +++ b/CampusAppWP8/CampusAppWP8/Pages/Lecture/ResultPage.xaml @@ -57,9 +57,11 @@ - + + + + - diff --git a/CampusAppWP8/CampusAppWP8/Pages/Links/LinkPage.xaml.cs b/CampusAppWP8/CampusAppWP8/Pages/Links/LinkPage.xaml.cs index e85a87b6..d71672e3 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/Links/LinkPage.xaml.cs +++ b/CampusAppWP8/CampusAppWP8/Pages/Links/LinkPage.xaml.cs @@ -68,7 +68,7 @@ namespace CampusAppWP8.Pages.Links } /// - /// Override the OnNavigatedTo method + /// Override the OnNavigatedFrom method /// /// Arguments of navigation protected override void OnNavigatedFrom(NavigationEventArgs e) @@ -76,6 +76,7 @@ namespace CampusAppWP8.Pages.Links this.clubLinkFeed.SaveData(); this.commonLinkFeed.SaveData(); } + #endregion #region private diff --git a/CampusAppWP8/CampusAppWP8/Pages/Mensa/MensaPage.xaml.cs b/CampusAppWP8/CampusAppWP8/Pages/Mensa/MensaPage.xaml.cs index cc42ef95..640ce4a8 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/Mensa/MensaPage.xaml.cs +++ b/CampusAppWP8/CampusAppWP8/Pages/Mensa/MensaPage.xaml.cs @@ -67,6 +67,16 @@ namespace CampusAppWP8.Pages.Mensa this.ProgressBar.Visibility = System.Windows.Visibility.Visible; this.feed.LoadData(); } + + /// + /// Override the OnNavigatedFrom method + /// + /// Arguments of navigation + protected override void OnNavigatedFrom(NavigationEventArgs e) + { + this.feed.SaveData(); + } + #endregion #region private @@ -88,7 +98,6 @@ namespace CampusAppWP8.Pages.Mensa { this.SetupMensaPivot(); this.ProgressBar.Visibility = System.Windows.Visibility.Collapsed; - this.feed.SaveData(); } /// diff --git a/CampusAppWP8/CampusAppWP8/Pages/Openinghours/OpeninghoursPage.xaml.cs b/CampusAppWP8/CampusAppWP8/Pages/Openinghours/OpeninghoursPage.xaml.cs index b8c56c47..48da50e3 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/Openinghours/OpeninghoursPage.xaml.cs +++ b/CampusAppWP8/CampusAppWP8/Pages/Openinghours/OpeninghoursPage.xaml.cs @@ -63,6 +63,15 @@ namespace CampusAppWP8.Pages.Openinghours this.feed.LoadData(); } + /// + /// Override the OnNavigatedFrom method + /// + /// Arguments of navigation + protected override void OnNavigatedFrom(NavigationEventArgs e) + { + this.feed.SaveData(); + } + // protected #endregion @@ -84,7 +93,6 @@ namespace CampusAppWP8.Pages.Openinghours { this.SetupInstitutionList(); this.ProgressBar.Visibility = System.Windows.Visibility.Collapsed; - this.feed.SaveData(); } /// diff --git a/CampusAppWP8/CampusAppWP8/Pages/StudentCouncil/StudentCouncilPage.xaml.cs b/CampusAppWP8/CampusAppWP8/Pages/StudentCouncil/StudentCouncilPage.xaml.cs index 486d4611..ee716951 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/StudentCouncil/StudentCouncilPage.xaml.cs +++ b/CampusAppWP8/CampusAppWP8/Pages/StudentCouncil/StudentCouncilPage.xaml.cs @@ -59,6 +59,15 @@ namespace CampusAppWP8.Pages.StudentCouncil this.feed.LoadData(); } + /// + /// Override the OnNavigatedFrom method + /// + /// Arguments of navigation + protected override void OnNavigatedFrom(NavigationEventArgs e) + { + this.feed.SaveData(); + } + #endregion #region private @@ -78,7 +87,6 @@ namespace CampusAppWP8.Pages.StudentCouncil { this.SetupStudentCouncilPivot(); this.ProgressBar.Visibility = System.Windows.Visibility.Collapsed; - this.feed.SaveData(); } /// diff --git a/CampusAppWP8/CampusAppWP8/Utility/Api.cs b/CampusAppWP8/CampusAppWP8/Utility/Api.cs deleted file mode 100644 index a0178de8..00000000 --- a/CampusAppWP8/CampusAppWP8/Utility/Api.cs +++ /dev/null @@ -1,144 +0,0 @@ -//----------------------------------------------------------------------- -// -// Company copyright tag. -// -// stubbfel -// 19.06.2013 -//---------------------------------------------------------------------- -namespace CampusAppWP8.Utility -{ - using System; - using System.Collections.Generic; - using System.Net; - using CampusAppWP8.Model.Utility; - - /// - /// This abstract Class is for API - /// - /// Type for model of the API - public abstract class Api : HttpRequest - { - #region Members - - /// - /// EventHandler of the API - /// - private readonly ApiEventHandler eventHandler; - - /// - /// The model of the API - /// - private T model; - - #endregion - - #region Constructor - - /// - /// Initializes a new instance of the class. - /// - /// BaseUrl of the API - public Api(Uri apiBaseAddress) - : base(apiBaseAddress) - { - this.eventHandler = new ApiEventHandler(); - } - - #endregion - - #region Proberty - - /// - /// Gets or sets for the model of the API - /// - public T Model - { - get - { - return this.model; - } - - set - { - if ((value == null && this.model != null) || !value.Equals(this.model)) - { - this.model = value; - } - } - } - - /// - /// Gets for the event-handler of the API - /// - public ApiEventHandler EventHandler - { - get { return this.eventHandler; } - } - #endregion - - #region Methods - - #region public - - /// - /// Method send an HTTP-Get for an API - /// - /// list of GetParameter - public void ApiGet(List parameters) - { - Uri getUrl = this.CreateGetUrl(parameters); - this.HttpGet(getUrl, this.DownloadCompleted); - } - #endregion - - #region protected - - /// - /// Method implement the deserialization a Xml-API - /// - /// content of the API - protected abstract void Deserialization(string xmlString); - - #endregion - - #region private - - /// - /// Method create the model of the API - /// - /// content of the API - private void CreateModel(string resultString) - { - if (resultString == null || resultString == string.Empty) - { - return; - } - - this.Deserialization(resultString); - this.EventHandler.FireApiReadyevent(); - } - - /// - /// Method will be execute if the download of the API 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); - } - } - #endregion - - #endregion - } -} diff --git a/CampusAppWP8/CampusAppWP8/Utility/ApiEventHandler.cs b/CampusAppWP8/CampusAppWP8/Utility/ApiEventHandler.cs deleted file mode 100644 index ddb1baaa..00000000 --- a/CampusAppWP8/CampusAppWP8/Utility/ApiEventHandler.cs +++ /dev/null @@ -1,47 +0,0 @@ -//----------------------------------------------------------------------- -// -// Company copyright tag. -// -// stubbfel -// 17.06.2013 -//---------------------------------------------------------------------- -namespace CampusAppWP8.Utility -{ - /// - /// This class handle the events of a API - /// - public class ApiEventHandler - { - /// - /// Initializes a new instance of the class. - /// - public ApiEventHandler() - { - } - - #region Delegate&Events - /// - /// Delegate for the ready event - /// - public delegate void ApiReadyHandler(); - - /// - /// The ready event - /// - public event ApiReadyHandler ApiIsReadyEvent; - - #endregion - - #region Method - - /// - /// Method fire a ready event - /// - public void FireApiReadyevent() - { - this.ApiIsReadyEvent(); - } - - #endregion - } -} diff --git a/CampusAppWP8/CampusAppWP8/Utility/HttpRequest.cs b/CampusAppWP8/CampusAppWP8/Utility/HttpRequest.cs index 665a004f..859a8982 100644 --- a/CampusAppWP8/CampusAppWP8/Utility/HttpRequest.cs +++ b/CampusAppWP8/CampusAppWP8/Utility/HttpRequest.cs @@ -68,12 +68,18 @@ namespace CampusAppWP8.Utility public Uri CreateGetUrl(List parameters) { string paramterStr = string.Empty; + string seperator = string.Empty; foreach (UrlParamModel parameter in parameters) { + if (string.Empty.Equals(seperator)) + { + seperator = parameter.ParamToken; + } + paramterStr += parameter.ToString(); } - string getUrlStr = baseAddress + "?" + paramterStr; + string getUrlStr = baseAddress + seperator + paramterStr; return new Uri(getUrlStr, UriKind.Absolute); } diff --git a/CampusAppWP8/CampusAppWP8/Utility/XmlApi.cs b/CampusAppWP8/CampusAppWP8/Utility/XmlApi.cs deleted file mode 100644 index 2f1aa0e3..00000000 --- a/CampusAppWP8/CampusAppWP8/Utility/XmlApi.cs +++ /dev/null @@ -1,84 +0,0 @@ -//----------------------------------------------------------------------- -// -// Company copyright tag. -// -// stubbfel -// 13.06.2013 -//---------------------------------------------------------------------- -namespace CampusAppWP8.Utility -{ - using System; - using System.Collections.Generic; - using System.Net; - using CampusAppWP8.Model.Utility; - using CampusAppWP8.Resources; - - /// - /// This abstract Class is for Xml-API - /// - /// Type for model of the API - public abstract class XmlApi : Api - { - #region Members - - /// - /// Variable for the name of the root-tag - /// - private string validRootName; - - #endregion - - #region Constructor - - /// - /// Initializes a new instance of the class. - /// - /// BaseUrl of the API - public XmlApi(Uri apiBaseAddress) - : base(apiBaseAddress) - { - this.validRootName = Constants.XMLRootElementName; - } - - #endregion - - #region Proberty - - /// - /// Gets or sets the ValidRootName of the API - /// - protected string ValidRootName - { - get - { - return this.validRootName; - } - - set - { - if (value != this.validRootName) - { - this.validRootName = value; - } - } - } - - #endregion - - #region Methods - - /// - /// Method implement the deserialization a Xml-API - /// - /// content of the API - protected override void Deserialization(string xmlString) - { - T model = XmlManager.DeserializationToModel(xmlString, this.ValidRootName); - if (model != null) - { - this.Model = model; - } - } - #endregion - } -}