Archived
1
0

Notification system development 1

This commit is contained in:
Michael Gordeev
2018-08-18 09:21:57 +03:00
parent 26907c9aac
commit 4c4f4ed967
13 changed files with 291 additions and 155 deletions
+19 -27
View File
@@ -16,7 +16,7 @@ using Windows.UI.Notifications;
namespace FoxTube.Background
{
public delegate void NotificationHandler(object sender, string xml);
public delegate void NotificationHandler(object sender, Notification item);
public sealed class BackgroundProcessor : IBackgroundTask
{
@@ -45,7 +45,7 @@ namespace FoxTube.Background
{
def = taskInstance.GetDeferral();
if (settings.Values["lastCheck"] == null)
settings.Values.Add("lastCheck", XmlConvert.ToString(DateTime.Now));
settings.Values.Add("lastCheck", XmlConvert.ToString(DateTime.Now, "YYYY-MM-DDThh:mm:ss"));
else lastCheck = XmlConvert.ToDateTime(settings.Values["lastCheck"] as string, XmlDateTimeSerializationMode.Unspecified);
if (settings.Values["notificationsHistory"] != null)
@@ -57,9 +57,6 @@ namespace FoxTube.Background
settings.Values.Add("notificationsHistory", doc.InnerXml);
}
if((bool)settings.Values["authorized"] == true)
CheckAccount();
CheckAnnouncements();
SendNSave();
@@ -114,49 +111,44 @@ namespace FoxTube.Background
}
}
string CheckAnnouncements()
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) - lastCheck.ToUniversalTime()).TotalSeconds > 0)
doc.Load(XmlReader.Create("http://foxgame.hol.es/foxtube-messages.xml"));
if ((XmlConvert.ToDateTimeOffset((doc["posts"].FirstChild as XmlElement).GetAttribute("time"), "YYYY-MM-DDThh:mm:ss") - lastCheck.ToUniversalTime()).TotalSeconds > 0)
Notifications.Add(new Notification("internal", (doc["posts"].FirstChild as XmlElement).GetAttribute("id"),
doc["posts"].FirstChild["notificationHeader"].InnerText,
doc["posts"].FirstChild["content"].InnerText,
XmlConvert.ToDateTime((doc["posts"].FirstChild as XmlElement).GetAttribute("time"),
XmlDateTimeSerializationMode.Unspecified),
XmlConvert.ToDateTimeOffset((doc["posts"].FirstChild as XmlElement).GetAttribute("time"), "YYYY-MM-DDThh:mm:ss"),
(doc["posts"].FirstChild as XmlElement).GetAttribute("image"), null));
return doc.InnerXml;
}
void SendNotification(Notification notification)
{
ToastNotificationManager.CreateToastNotifier().Show(notification.GetToast(0));
ToastNotificationManager.CreateToastNotifier().Show(notification.GetToast());
}
void SendNSave()
{
foreach (Notification n in Notifications)
{
NotificationRecieved.Invoke(this, n.GetXml());
NotificationRecieved.Invoke(this, n);
doc["history"].InnerXml += n.GetXml();
}
settings.Values.Add("notificationsHistory", doc.InnerXml);
if ((bool)settings.Values["notifications"])
foreach (Notification n in Notifications)
switch (n.Type)
{
case NotificationType.Video:
if ((bool)settings.Values["newVideoNotification"])
SendNotification(n);
break;
foreach (Notification n in Notifications)
switch (n.Type)
{
case NotificationType.Video:
if ((bool)settings.Values["newVideoNotification"])
SendNotification(n);
break;
case NotificationType.Internal:
if ((bool)settings.Values["newmessagesNotification"])
SendNotification(n);
break;
}
case NotificationType.Internal:
SendNotification(n);
break;
}
}
}
}