Archived
1
0

Broke everything; #220: Fixed

This commit is contained in:
Michael Gordeev
2018-12-09 13:41:00 +03:00
parent 1a6447a4aa
commit f16be876c6
19 changed files with 201 additions and 145 deletions
+23 -20
View File
@@ -24,30 +24,33 @@ namespace FoxTube.Background
public async void Run(IBackgroundTaskInstance taskInstance)
{
def = taskInstance.GetDeferral();
try
{
def = taskInstance.GetDeferral();
if (settings.Values["lastCheck"] == null)
settings.Values.Add("lastCheck", XmlConvert.ToString(DateTime.Now));
else lastCheck = XmlConvert.ToDateTime(settings.Values["lastCheck"] as string, XmlDateTimeSerializationMode.Unspecified);
{
settings.Values.Add("lastCheck", DateTime.UtcNow.ToString());
def.Complete();
return;
}
else
lastCheck = DateTime.Parse(settings.Values["lastCheck"] as string);
//ToastNotificationManager.CreateToastNotifier().Show(Notification.GetInternalToast(null, $"{DateTime.Now} Retrieving videos since", lastCheck.ToString(), null, null));
bool[] notificationsSettings = JsonConvert.DeserializeObject<bool[]>(await FileIO.ReadTextAsync(await ApplicationData.Current.RoamingFolder.GetFileAsync("notifications.json")));
if (notificationsSettings[0])
CheckAnnouncements();
if (notificationsSettings[1])
CheckAccount();
}
catch
catch { }
finally
{
lastCheck = DateTime.Now;
settings.Values["lastCheck"] = DateTime.UtcNow.ToString();
def.Complete();
}
ToastNotificationManager.CreateToastNotifier().Show(Notification.GetInternalToast(null, "Background task initialized. Retrieving videos since", lastCheck.ToString(), null, null));
bool[] notificationsSettings = JsonConvert.DeserializeObject<bool[]>(await FileIO.ReadTextAsync(await ApplicationData.Current.RoamingFolder.GetFileAsync("notifications.json")));
if(notificationsSettings[0])
CheckAnnouncements();
if(notificationsSettings[1])
CheckAccount();
settings.Values["lastCheck"] = XmlConvert.ToString(DateTime.Now, "YYYY-MM-DDThh:mm:ss");
def.Complete();
ToastNotificationManager.CreateToastNotifier().Show(Notification.GetInternalToast(null, "Background task complete", DateTime.Now.ToString(), null, null));
}
async void CheckAccount()
@@ -77,8 +80,8 @@ namespace FoxTube.Background
try
{
XmlDocument doc = new XmlDocument();
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)
doc.Load(XmlReader.Create("http://foxgame-studio.000webhostapp.com/foxtube-messages.xml"));
if ((DateTime.Parse((doc["posts"].FirstChild as XmlElement).GetAttribute("time")) - lastCheck).TotalSeconds > 0)
ToastNotificationManager.CreateToastNotifier().Show(
Notification.GetInternalToast(doc["posts"].FirstChild["id"].InnerText,
doc["posts"].FirstChild["header"].InnerText,