Archived
1
0

DownloadAgent

This commit is contained in:
Michael Gordeev
2018-07-11 18:58:05 +03:00
parent 839be10ed2
commit 71cc12106c
39 changed files with 1359 additions and 55 deletions
+67
View File
@@ -0,0 +1,67 @@
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<Notification> Notifications = new List<Notification>();
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));
}
}
}