From e27a8bb98980008bcf6def0cb53000da732195b9 Mon Sep 17 00:00:00 2001 From: stubbfel Date: Wed, 19 Jun 2013 10:30:51 +0200 Subject: [PATCH 1/2] add api class --- CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj | 1 + .../Pages/Lecture/LecturePage.xaml.cs | 2 +- .../Pages/Lecture/ResultPage.xaml.cs | 2 + .../CampusAppWP8/Properties/WMAppManifest.xml | 2 +- CampusAppWP8/CampusAppWP8/Utility/Api.cs | 140 ++++++++++++++++++ CampusAppWP8/CampusAppWP8/Utility/XmlApi.cs | 98 +----------- 6 files changed, 151 insertions(+), 94 deletions(-) create mode 100644 CampusAppWP8/CampusAppWP8/Utility/Api.cs diff --git a/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj b/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj index 14c3174d..2535a30b 100644 --- a/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj +++ b/CampusAppWP8/CampusAppWP8/CampusAppWP8.csproj @@ -172,6 +172,7 @@ True Constants.resx + diff --git a/CampusAppWP8/CampusAppWP8/Pages/Lecture/LecturePage.xaml.cs b/CampusAppWP8/CampusAppWP8/Pages/Lecture/LecturePage.xaml.cs index 95c960be..48b5398d 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/Lecture/LecturePage.xaml.cs +++ b/CampusAppWP8/CampusAppWP8/Pages/Lecture/LecturePage.xaml.cs @@ -167,7 +167,7 @@ namespace CampusAppWP8.Pages.Lecture this.api.EventHandler.ApiIsReadyEvent += new ApiEventHandler.ApiReadyHandler(this.ApiIsReady); this.ProgressBar.Visibility = System.Windows.Visibility.Visible; List parameterList = this.CreateUrlParameter(); - this.api.XMLHttpGet(parameterList); + this.api.ApiGet(parameterList); } /// diff --git a/CampusAppWP8/CampusAppWP8/Pages/Lecture/ResultPage.xaml.cs b/CampusAppWP8/CampusAppWP8/Pages/Lecture/ResultPage.xaml.cs index fbb9157a..a9f96ba4 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/Lecture/ResultPage.xaml.cs +++ b/CampusAppWP8/CampusAppWP8/Pages/Lecture/ResultPage.xaml.cs @@ -133,6 +133,7 @@ namespace CampusAppWP8.Pages.Lecture private void ShowModulWebPage(object sender, RoutedEventArgs e) { Button btn = (Button)sender; + HideOptions((StackPanel)btn.Parent); Uri url = new Uri(Constants.PathLecture_ModulWebPage + "?" + Constants.ParamModelLecture_ModulNumber + "=" + btn.Tag, UriKind.Relative); NavigationService.Navigate(url); } @@ -145,6 +146,7 @@ namespace CampusAppWP8.Pages.Lecture private void ShowDetailPage(object sender, RoutedEventArgs e) { Button btn = (Button)sender; + HideOptions((StackPanel)btn.Parent); Uri url = new Uri(Constants.PathLecture_ResultDetailPage + "?" + Constants.ParamModelLecture_ActivityId + "=" + btn.Tag, UriKind.Relative); NavigationService.Navigate(url); } diff --git a/CampusAppWP8/CampusAppWP8/Properties/WMAppManifest.xml b/CampusAppWP8/CampusAppWP8/Properties/WMAppManifest.xml index f4b319d3..b65e09d5 100644 --- a/CampusAppWP8/CampusAppWP8/Properties/WMAppManifest.xml +++ b/CampusAppWP8/CampusAppWP8/Properties/WMAppManifest.xml @@ -13,7 +13,7 @@ - + diff --git a/CampusAppWP8/CampusAppWP8/Utility/Api.cs b/CampusAppWP8/CampusAppWP8/Utility/Api.cs new file mode 100644 index 00000000..b1dbe58c --- /dev/null +++ b/CampusAppWP8/CampusAppWP8/Utility/Api.cs @@ -0,0 +1,140 @@ +using CampusAppWP8.Model.Utility; +//----------------------------------------------------------------------- +// +// Company copyright tag. +// +// stubbfel +// 13.06.2013 +//---------------------------------------------------------------------- +namespace CampusAppWP8.Utility +{ + using System; + using System.Collections.Generic; + using System.Net; + + 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/XmlApi.cs b/CampusAppWP8/CampusAppWP8/Utility/XmlApi.cs index 71e48753..ad34ab5f 100644 --- a/CampusAppWP8/CampusAppWP8/Utility/XmlApi.cs +++ b/CampusAppWP8/CampusAppWP8/Utility/XmlApi.cs @@ -17,24 +17,14 @@ namespace CampusAppWP8.Utility /// This abstract Class is for Xml-API /// /// Type for model of the API - public abstract class XmlApi : HttpRequest + public abstract class XmlApi : Api { #region Members - - /// - /// EventHandler of the API - /// - private readonly ApiEventHandler eventHandler; - - /// - /// The model of the API - /// - private T model; - + /// /// Variable for the name of the root-tag /// - private string validRootName = Constants.XMLRootElementName; + private string validRootName; #endregion @@ -47,40 +37,13 @@ namespace CampusAppWP8.Utility public XmlApi(Uri apiBaseAddress) : base(apiBaseAddress) { - this.eventHandler = new ApiEventHandler(); + this.validRootName = Constants.XMLRootElementName; } #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; } - } - /// /// Gets or sets the ValidRootName of the API /// @@ -103,40 +66,12 @@ namespace CampusAppWP8.Utility #endregion #region Methods - #region public - - /// - /// Method send an HTTP-Get for an Xml-API - /// - /// list of GetParameter - public void XMLHttpGet(List parameters) - { - Uri getUrl = this.CreateGetUrl(parameters); - this.HttpGet(getUrl, this.DownloadCompleted); - } - - /// - /// Method create the model of the API - /// - /// content of the API - private void CreateModel(string xmlString) - { - if (xmlString == null || xmlString == string.Empty) - { - return; - } - - this.Deserialization(xmlString); - this.EventHandler.FireApiReadyevent(); - } - #endregion - - #region private + /// /// Method implement the deserialization a Xml-API /// /// content of the API - private void Deserialization(string xmlString) + protected override void Deserialization(string xmlString) { T model = XmlManager.DeserializationToModel(xmlString, ValidRootName); if (model != null) @@ -144,27 +79,6 @@ namespace CampusAppWP8.Utility this.Model = model; } } - - /// - /// 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 } } From ce6358b9f7b6dc308654fabb37d751b56a281b66 Mon Sep 17 00:00:00 2001 From: stubbfel Date: Wed, 19 Jun 2013 10:32:55 +0200 Subject: [PATCH 2/2] clear stylecop warning #48 --- CampusAppWP8/CampusAppWP8/Utility/Api.cs | 14 +++++++++----- CampusAppWP8/CampusAppWP8/Utility/XmlApi.cs | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CampusAppWP8/CampusAppWP8/Utility/Api.cs b/CampusAppWP8/CampusAppWP8/Utility/Api.cs index b1dbe58c..a7ef98e5 100644 --- a/CampusAppWP8/CampusAppWP8/Utility/Api.cs +++ b/CampusAppWP8/CampusAppWP8/Utility/Api.cs @@ -1,17 +1,21 @@ -using CampusAppWP8.Model.Utility; -//----------------------------------------------------------------------- -// +//----------------------------------------------------------------------- +// // Company copyright tag. // // stubbfel -// 13.06.2013 +// 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 @@ -31,7 +35,7 @@ namespace CampusAppWP8.Utility #region Constructor /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// BaseUrl of the API public Api(Uri apiBaseAddress) diff --git a/CampusAppWP8/CampusAppWP8/Utility/XmlApi.cs b/CampusAppWP8/CampusAppWP8/Utility/XmlApi.cs index ad34ab5f..2f1aa0e3 100644 --- a/CampusAppWP8/CampusAppWP8/Utility/XmlApi.cs +++ b/CampusAppWP8/CampusAppWP8/Utility/XmlApi.cs @@ -73,7 +73,7 @@ namespace CampusAppWP8.Utility /// content of the API protected override void Deserialization(string xmlString) { - T model = XmlManager.DeserializationToModel(xmlString, ValidRootName); + T model = XmlManager.DeserializationToModel(xmlString, this.ValidRootName); if (model != null) { this.Model = model;