using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml; using Windows.ApplicationModel.Background; using Windows.Storage; using Windows.UI.Notifications; namespace FoxTube.Background { public sealed class BackgroundProcessor : IBackgroundTask { public List Notifications = new List(); private DateTime lastCheck; private ApplicationDataContainer settings = ApplicationData.Current.LocalSettings; BackgroundTaskDeferral def; public async void Run(IBackgroundTaskInstance taskInstance) { XmlDocument doc = new XmlDocument(); def = taskInstance.GetDeferral(); if (settings.Values["notificationsHistory"] != null) doc.LoadXml(settings.Values["notificationsHistory"] as string); else { doc.AppendChild(doc.CreateXmlDeclaration("1.0", "utf-8", null)); doc.AppendChild(doc.CreateElement("notifications")); settings.Values.Add("notificationsHistory", doc.InnerXml); } CheckAccount(); CheckAnnouncements(); def.Complete(); } void CheckAccount() { } void CheckAnnouncements() { XmlDocument doc = new XmlDocument(); doc.Load(XmlReader.Create("http://foxgame.hol.es/ftp.xml")); if ((XmlConvert.ToDateTime((doc["posts"].FirstChild as XmlElement).GetAttribute("time"), XmlDateTimeSerializationMode.Utc) - DateTime.UtcNow).TotalSeconds > 0) Notifications.Add(new Notification(NotificationType.Internal, doc["posts"].FirstChild["notificationHeader"].InnerText, doc["posts"].FirstChild["content"].InnerText, XmlConvert.ToDateTime((doc["posts"].FirstChild as XmlElement).GetAttribute("time"), XmlDateTimeSerializationMode.Local), (doc["posts"].FirstChild as XmlElement).GetAttribute("image"))); if ((bool)settings.Values["newmessagesNotification"] == true) SendNotification(Notifications.Last()); } void SendNotification(Notification notification) { ToastNotificationManager.CreateToastNotifier().Show(notification.GetToast(0)); } } }