refactor schedulagent
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="ScheduledAgent.cs" company="BTU/IIT">
|
||||
// Company copyright tag.
|
||||
// The MIT License (MIT). Copyright (c) 2013 BTU/IIT.
|
||||
// </copyright>
|
||||
// <author>stubbfel</author>
|
||||
// <sience>18.09.2013</sience>
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
// <author>Stubbfel</author>
|
||||
// <date>15.10.2013</date>
|
||||
// <summary>Implements the scheduled agent class</summary>
|
||||
//-----------------------------------------------------------------------
|
||||
namespace CampusAppWP8ScheduledTaskAgent
|
||||
{
|
||||
using System;
|
||||
@@ -21,40 +21,31 @@ namespace CampusAppWP8ScheduledTaskAgent
|
||||
using Microsoft.Phone.Scheduler;
|
||||
using Microsoft.Phone.Shell;
|
||||
|
||||
/// <summary>
|
||||
/// Class for agent of the BackgroundTask
|
||||
/// </summary>
|
||||
/// <summary> Class for agent of the BackgroundTask. </summary>
|
||||
/// <remarks> Stubbfel, 15.10.2013. </remarks>
|
||||
/// <seealso cref="T:Microsoft.Phone.Scheduler.ScheduledTaskAgent"/>
|
||||
public class ScheduledAgent : ScheduledTaskAgent
|
||||
{
|
||||
#region Member
|
||||
|
||||
/// <summary>
|
||||
/// Model for the mensa feed
|
||||
/// </summary>
|
||||
/// <summary> Model for the mensa feed. </summary>
|
||||
private MenuWeekModel mensaModel;
|
||||
|
||||
/// <summary>
|
||||
/// Model for the event feed
|
||||
/// </summary>
|
||||
/// <summary> Model for the event feed. </summary>
|
||||
private RSSViewModel eventModel;
|
||||
|
||||
/// <summary>
|
||||
/// Model for the news feed
|
||||
/// </summary>
|
||||
/// <summary> Model for the news feed. </summary>
|
||||
private RSSViewModel newsModel;
|
||||
|
||||
/// <summary>
|
||||
/// Variable for the runnig feeds
|
||||
/// </summary>
|
||||
/// <summary> Variable for the running feeds. </summary>
|
||||
private int runningFeeds;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// Initializes static members of the <see cref="ScheduledAgent" /> class.
|
||||
/// </summary>
|
||||
/// <summary> Initializes static members of the <see cref="ScheduledAgent" /> class. </summary>
|
||||
/// <remarks> Stubbfel, 15.10.2013. </remarks>
|
||||
static ScheduledAgent()
|
||||
{
|
||||
Deployment.Current.Dispatcher.BeginInvoke(delegate
|
||||
@@ -69,10 +60,9 @@ namespace CampusAppWP8ScheduledTaskAgent
|
||||
|
||||
#region protected
|
||||
|
||||
/// <summary>
|
||||
/// override OnInvoke
|
||||
/// </summary>
|
||||
/// <param name="task">the background Task</param>
|
||||
/// <summary> override OnInvoke. </summary>
|
||||
/// <remarks> Stubbfel, 15.10.2013. </remarks>
|
||||
/// <seealso cref="M:Microsoft.Phone.Scheduler.ScheduledTaskAgent.OnInvoke(ScheduledTask)"/>
|
||||
protected override void OnInvoke(ScheduledTask task)
|
||||
{
|
||||
int notRunningFeeds = 0;
|
||||
@@ -120,11 +110,10 @@ namespace CampusAppWP8ScheduledTaskAgent
|
||||
|
||||
#region private
|
||||
|
||||
/// <summary>
|
||||
/// Method handle UnhandledException
|
||||
/// </summary>
|
||||
/// <param name="sender">sender of Exception</param>
|
||||
/// <param name="e">Exception Args</param>
|
||||
/// <summary> Method handle UnhandledException. </summary>
|
||||
/// <remarks> Stubbfel, 15.10.2013. </remarks>
|
||||
/// <param name="sender"> sender of Exception. </param>
|
||||
/// <param name="e"> Exception Args. </param>
|
||||
private static void UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
|
||||
{
|
||||
if (Debugger.IsAttached)
|
||||
@@ -133,10 +122,9 @@ namespace CampusAppWP8ScheduledTaskAgent
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method handle the EventBackgroundTask
|
||||
/// </summary>
|
||||
/// <param name="task">the eventTask</param>
|
||||
/// <summary> Method handle the EventBackgroundTask. </summary>
|
||||
/// <remarks> Stubbfel, 15.10.2013. </remarks>
|
||||
/// <param name="task"> the eventTask. </param>
|
||||
private void HandleEventTask(ScheduledTask task)
|
||||
{
|
||||
if (this.eventModel == null || !this.CheckRssIsUpToDate(this.eventModel.CreateTime))
|
||||
@@ -155,10 +143,9 @@ namespace CampusAppWP8ScheduledTaskAgent
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method handle the NewsBackgroundTask
|
||||
/// </summary>
|
||||
/// <param name="task">the newsTask</param>
|
||||
/// <summary> Method handle the NewsBackgroundTask. </summary>
|
||||
/// <remarks> Stubbfel, 15.10.2013. </remarks>
|
||||
/// <param name="task"> the newsTask. </param>
|
||||
private void HandleNewsTask(ScheduledTask task)
|
||||
{
|
||||
if (this.newsModel == null || !this.CheckRssIsUpToDate(this.newsModel.CreateTime))
|
||||
@@ -177,11 +164,10 @@ namespace CampusAppWP8ScheduledTaskAgent
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ResponseHandler for the EventFeed
|
||||
/// </summary>
|
||||
/// <param name="sender">sender of the Event</param>
|
||||
/// <param name="arg">Event Args</param>
|
||||
/// <summary> ResponseHandler for the EventFeed. </summary>
|
||||
/// <remarks> Stubbfel, 15.10.2013. </remarks>
|
||||
/// <param name="sender"> sender of the Event. </param>
|
||||
/// <param name="arg"> Event Args. </param>
|
||||
private void GetEventIsReady(object sender, System.Net.DownloadStringCompletedEventArgs arg)
|
||||
{
|
||||
if (arg.Result != null)
|
||||
@@ -200,11 +186,10 @@ namespace CampusAppWP8ScheduledTaskAgent
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ResponseHandler for the NewsFeed
|
||||
/// </summary>
|
||||
/// <param name="sender">sender of the Event</param>
|
||||
/// <param name="arg">Event Args</param>
|
||||
/// <summary> ResponseHandler for the NewsFeed. </summary>
|
||||
/// <remarks> Stubbfel, 15.10.2013. </remarks>
|
||||
/// <param name="sender"> sender of the Event. </param>
|
||||
/// <param name="arg"> Event Args. </param>
|
||||
private void GetNewsIsReady(object sender, System.Net.DownloadStringCompletedEventArgs arg)
|
||||
{
|
||||
if (arg.Result != null)
|
||||
@@ -223,9 +208,8 @@ namespace CampusAppWP8ScheduledTaskAgent
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method update the NewsTile
|
||||
/// </summary>
|
||||
/// <summary> Method update the NewsTile. </summary>
|
||||
/// <remarks> Stubbfel, 15.10.2013. </remarks>
|
||||
private void UpdateNewsTile()
|
||||
{
|
||||
ShellTile tileToFind = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains(CampusAppWPortalLib8.Resources.Constants.PathNews_NewsIndexPage));
|
||||
@@ -243,6 +227,7 @@ namespace CampusAppWP8ScheduledTaskAgent
|
||||
|
||||
tileToFind.Update(data);
|
||||
}
|
||||
|
||||
this.runningFeeds--;
|
||||
}
|
||||
|
||||
@@ -256,9 +241,8 @@ namespace CampusAppWP8ScheduledTaskAgent
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method update the EventTile
|
||||
/// </summary>
|
||||
/// <summary> Method update the EventTile. </summary>
|
||||
/// <remarks> Stubbfel, 15.10.2013. </remarks>
|
||||
private void UpdateEventTile()
|
||||
{
|
||||
ShellTile tileToFind = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains(CampusAppWPortalLib8.Resources.Constants.PathEvents_EventsIndexPage));
|
||||
@@ -277,6 +261,7 @@ namespace CampusAppWP8ScheduledTaskAgent
|
||||
|
||||
tileToFind.Update(data);
|
||||
}
|
||||
|
||||
this.runningFeeds--;
|
||||
}
|
||||
|
||||
@@ -286,11 +271,10 @@ namespace CampusAppWP8ScheduledTaskAgent
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determine the correct MensaFeed/Url
|
||||
/// </summary>
|
||||
/// <param name="mensaTaskDesc">the Description of the MensaTask</param>
|
||||
/// <returns>Url of a mensa, which is set is in the UserProfile</returns>
|
||||
/// <summary> Determine the correct MensaFeed/Url. </summary>
|
||||
/// <remarks> Stubbfel, 15.10.2013. </remarks>
|
||||
/// <param name="mensaTaskDesc"> the Description of the MensaTask. </param>
|
||||
/// <returns> Url of a mensa, which is set is in the UserProfile. </returns>
|
||||
private Uri CalcMensaUrl(string mensaTaskDesc)
|
||||
{
|
||||
Uri url;
|
||||
@@ -318,10 +302,9 @@ namespace CampusAppWP8ScheduledTaskAgent
|
||||
return url;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method handle the MensaBackgroundTask
|
||||
/// </summary>
|
||||
/// <param name="task">the newsTask</param>
|
||||
/// <summary> Method handle the MensaBackgroundTask. </summary>
|
||||
/// <remarks> Stubbfel, 15.10.2013. </remarks>
|
||||
/// <param name="task"> the newsTask. </param>
|
||||
private void HandleMensaTask(ScheduledTask task)
|
||||
{
|
||||
if (this.mensaModel == null || !this.CheckMensaIsUpToDate(this.mensaModel.CreateTime))
|
||||
@@ -336,11 +319,10 @@ namespace CampusAppWP8ScheduledTaskAgent
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ResponseHandler for the MensaFeed
|
||||
/// </summary>
|
||||
/// <param name="sender">sender of the Event</param>
|
||||
/// <param name="arg">Event Args</param>
|
||||
/// <summary> ResponseHandler for the MensaFeed. </summary>
|
||||
/// <remarks> Stubbfel, 15.10.2013. </remarks>
|
||||
/// <param name="sender"> sender of the Event. </param>
|
||||
/// <param name="arg"> Event Args. </param>
|
||||
private void GetMensaIsReady(object sender, System.Net.DownloadStringCompletedEventArgs arg)
|
||||
{
|
||||
if (arg.Result != null)
|
||||
@@ -358,9 +340,8 @@ namespace CampusAppWP8ScheduledTaskAgent
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method update the NewsTile
|
||||
/// </summary>
|
||||
/// <summary> Method update the NewsTile. </summary>
|
||||
/// <remarks> Stubbfel, 15.10.2013. </remarks>
|
||||
private void UpdateMensaTile()
|
||||
{
|
||||
ShellTile tileToFind = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains(CampusAppWPortalLib8.Resources.Constants.PathMensa_MensaPage));
|
||||
@@ -391,6 +372,7 @@ namespace CampusAppWP8ScheduledTaskAgent
|
||||
int randomNumber = random.Next(0, mealCount);
|
||||
MealModel meal = this.mensaModel.Menus[dayIndex].Meals[randomNumber];
|
||||
data.WideContent3 = meal.MealName + ": " + DefaultStringManager.ToShortString(meal.MealDesc, 30, "...");
|
||||
|
||||
// data.Count = this.mensaModel.Menus[dayIndex].Meals.Count;
|
||||
}
|
||||
}
|
||||
@@ -405,11 +387,10 @@ namespace CampusAppWP8ScheduledTaskAgent
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if the model of the mensa is up-to-date
|
||||
/// </summary>
|
||||
/// <param name="lastModified"> Date of the last modification</param>
|
||||
/// <returns>true, if it is up-to-date, otherwise false</returns>
|
||||
/// <summary> Check if the model of the mensa is up-to-date. </summary>
|
||||
/// <remarks> Stubbfel, 15.10.2013. </remarks>
|
||||
/// <param name="lastModified"> Date of the last modification. </param>
|
||||
/// <returns> true, if it is up-to-date, otherwise false. </returns>
|
||||
private bool CheckMensaIsUpToDate(DateTime lastModified)
|
||||
{
|
||||
int diff = lastModified.CompareTo(MenuWeekModel.CalcFirstWeekDay());
|
||||
@@ -422,11 +403,10 @@ namespace CampusAppWP8ScheduledTaskAgent
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if the model of the RSS feed is up-to-date
|
||||
/// </summary>
|
||||
/// <param name="lastModified"> Date of the last modification</param>
|
||||
/// <returns>true, if it is up-to-date, otherwise false</returns>
|
||||
/// <summary> Check if the model of the RSS feed is up-to-date. </summary>
|
||||
/// <remarks> Stubbfel, 15.10.2013. </remarks>
|
||||
/// <param name="lastModified"> Date of the last modification. </param>
|
||||
/// <returns> true, if it is up-to-date, otherwise false. </returns>
|
||||
private bool CheckRssIsUpToDate(DateTime lastModified)
|
||||
{
|
||||
int diff = lastModified.CompareTo(DateTime.Now.AddDays(1));
|
||||
|
||||
@@ -2,13 +2,14 @@
|
||||
<GlobalSettings>
|
||||
<CollectionProperty Name="RecognizedWords">
|
||||
<Value>perodic</Value>
|
||||
<Value>stubbfel</Value>
|
||||
</CollectionProperty>
|
||||
</GlobalSettings>
|
||||
<Analyzers>
|
||||
<Analyzer AnalyzerId="StyleCop.CSharp.DocumentationRules">
|
||||
<AnalyzerSettings>
|
||||
<StringProperty Name="CompanyName">BTU/IIT</StringProperty>
|
||||
<StringProperty Name="Copyright">BTU/IIT</StringProperty>
|
||||
<StringProperty Name="Copyright">The MIT License (MIT). Copyright (c) 2013 BTU/IIT.</StringProperty>
|
||||
</AnalyzerSettings>
|
||||
</Analyzer>
|
||||
</Analyzers>
|
||||
|
||||
@@ -1,26 +1,25 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="BackgroundTasks.cs" company="BTU/IIT">
|
||||
// Company copyright tag.
|
||||
// The MIT License (MIT). Copyright (c) 2013 BTU/IIT.
|
||||
// </copyright>
|
||||
// <author>stubbfel</author>
|
||||
// <sience>18.09.2013</sience>
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
// <author>Stubbfel</author>
|
||||
// <date>15.10.2013</date>
|
||||
// <summary>Implements the background tasks class</summary>
|
||||
//-----------------------------------------------------------------------
|
||||
namespace CampusAppWP8ScheduledTaskAgent.Utility
|
||||
{
|
||||
using System;
|
||||
using CampusAppWPortalLib8.Utility;
|
||||
using Microsoft.Phone.Scheduler;
|
||||
|
||||
/// <summary>
|
||||
/// Class provide some static methods for background tasks
|
||||
/// </summary>
|
||||
/// <summary> Class provide some static methods for background tasks. </summary>
|
||||
/// <remarks> Stubbfel, 15.10.2013. </remarks>
|
||||
/// <seealso cref="T:CampusAppWPortalLib8.Utility.AbstractBackgroundTasks"/>
|
||||
public class BackgroundTasks : AbstractBackgroundTasks
|
||||
{
|
||||
/// <summary>
|
||||
/// Method stop a certain PerodicTask
|
||||
/// </summary>
|
||||
/// <param name="taskName">name of the task</param>
|
||||
/// <summary> Method stop a certain PerodicTask. </summary>
|
||||
/// <remarks> Stubbfel, 15.10.2013. </remarks>
|
||||
/// <param name="taskName"> name of the task. </param>
|
||||
public static void StopPerodicTask(string taskName)
|
||||
{
|
||||
PeriodicTask periodicTask = ScheduledActionService.Find(taskName) as PeriodicTask;
|
||||
|
||||
@@ -1,34 +1,33 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// <copyright file="HttpRequest.cs" company="BTU/IIT">
|
||||
// Company copyright tag.
|
||||
// The MIT License (MIT). Copyright (c) 2013 BTU/IIT.
|
||||
// </copyright>
|
||||
// <author>stubbfel</author>
|
||||
// <sience>10.06.2013</sience>
|
||||
//----------------------------------------------------------------------
|
||||
// <author>Stubbfel</author>
|
||||
// <date>15.10.2013</date>
|
||||
// <summary>Implements the HTTP request class</summary>
|
||||
//-----------------------------------------------------------------------
|
||||
namespace CampusAppWP8ScheduledTaskAgent.Utility
|
||||
{
|
||||
using System;
|
||||
using System.Net;
|
||||
using CampusAppWPortalLib8.Utility;
|
||||
|
||||
/// <summary>
|
||||
/// Class realize the access of restful HttpRequest
|
||||
/// </summary>
|
||||
/// <summary> Class realize the access of restful HttpRequest. </summary>
|
||||
/// <remarks> Stubbfel, 15.10.2013. </remarks>
|
||||
/// <seealso cref="T:CampusAppWPortalLib8.Utility.AbstractHttpRequest"/>
|
||||
public class HttpRequest : AbstractHttpRequest
|
||||
{
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HttpRequest" /> class.
|
||||
/// </summary>
|
||||
/// <summary> Initializes a new instance of the <see cref="HttpRequest" /> class. </summary>
|
||||
/// <remarks> Stubbfel, 15.10.2013. </remarks>
|
||||
public HttpRequest()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HttpRequest" /> class.
|
||||
/// </summary>
|
||||
/// <param name="apiBaseAddress">the url of the HttpRequest base address</param>
|
||||
/// <summary> Initializes a new instance of the <see cref="HttpRequest" /> class. </summary>
|
||||
/// <remarks> Stubbfel, 15.10.2013. </remarks>
|
||||
/// <param name="apiBaseAddress"> the url of the HttpRequest base address. </param>
|
||||
public HttpRequest(Uri apiBaseAddress)
|
||||
{
|
||||
this.BaseAddress = apiBaseAddress.AbsoluteUri;
|
||||
@@ -38,11 +37,10 @@ namespace CampusAppWP8ScheduledTaskAgent.Utility
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Method realize the http-get-method resource
|
||||
/// </summary>
|
||||
/// <param name="url">Url of the resource</param>
|
||||
/// <param name="action">callback method</param>
|
||||
/// <summary> Method realize the http-get-method resource. </summary>
|
||||
/// <remarks> Stubbfel, 15.10.2013. </remarks>
|
||||
/// <param name="url"> Url of the resource. </param>
|
||||
/// <param name="action"> callback method. </param>
|
||||
public void HttpGet(Uri url, Action<object, DownloadStringCompletedEventArgs> action)
|
||||
{
|
||||
WebClient client = new WebClient();
|
||||
|
||||
Reference in New Issue
Block a user