private async Task <bool> isNew(KD_Model_Net kd) { try { var localFolder = Windows.Storage.ApplicationData.Current.LocalFolder; var tempkdfile = await localFolder.CreateFileAsync("tempkdfile", Windows.Storage.CreationCollisionOption.OpenIfExists); var array = Windows.Data.Json.JsonArray.Parse(await Windows.Storage.FileIO.ReadTextAsync(tempkdfile)); foreach (var item in array) { if (item.GetObject().GetNamedString("num") == kd.num) { if (item.GetObject().GetNamedString("time") == kd.newdata.time) { return(false); } else { await UpdataNum(kd); return(true); } } } return(false); } catch (Exception) { return(false); } }
private void ShowToast(KD_Model_Net kd) { var doc = new XmlDocument(); doc.LoadXml(WebUtility.HtmlDecode(string.Format(ToastTemplateXml, kd.name, kd.com_cn, kd.newdata.context)), new XmlLoadSettings { ProhibitDtd = false, ValidateOnParse = false, ElementContentWhiteSpace = false, ResolveExternals = false }); var toast = new ToastNotification(doc); ToastNotificationManager.CreateToastNotifier().Show(toast); }
private async Task UpdateTile() { try { var kd_list = await GetKD(); var updater = TileUpdateManager.CreateTileUpdaterForApplication(); updater.EnableNotificationQueueForWide310x150(true); updater.EnableNotificationQueueForSquare150x150(true); updater.EnableNotificationQueueForSquare310x310(true); updater.EnableNotificationQueue(true); updater.Clear(); foreach (var kd in kd_list) { var kd_net = new KD_Model_Net(kd); await kd_net.Load(); if (kd_net.message == "ok" && kd_net.ischeck == "0") { var tilexml = string.Format(TileTemplateXml, kd_net.name, kd_net.com_cn, kd_net.newdata.context, kd_net.newdata.time_s); var doc = new Windows.Data.Xml.Dom.XmlDocument(); doc.LoadXml(WebUtility.HtmlDecode(tilexml), new XmlLoadSettings { ProhibitDtd = false, ValidateOnParse = false, ElementContentWhiteSpace = false, ResolveExternals = false }); updater.Update(new TileNotification(doc)); if (await isNew(kd_net)) { ShowToast(kd_net); } } } //string tilexml = "<tile><binding template=\"TileMedium\"><text hint-style=\"subtitle\" id=\"0\">{0} {1} "+time_s+ "</text><text hint-wrap='true' id=\"1\">{2}</text></binding><binding template=\"TileWide\"><text hint-style=\"subtitle\">{0} {1} " + time_s + "</text><text hint-wrap='true'>{2}</text></binding><binding template=\"TileLarge\"><text hint-style=\"subtitle\">{0} {1} " + time_s + "</text><text hint-wrap='true'>{2}</text></binding></tile>"; } catch (Exception e) { Debug.WriteLine(e.Message); } }
private async Task UpdataNum(KD_Model_Net kd) { try { var localFolder = Windows.Storage.ApplicationData.Current.LocalFolder; var tempkdfile = await localFolder.CreateFileAsync("tempkdfile", Windows.Storage.CreationCollisionOption.OpenIfExists); var array = Windows.Data.Json.JsonArray.Parse(await Windows.Storage.FileIO.ReadTextAsync(tempkdfile)); for (int i = 0; i < array.Count; i++) { if (array[i].GetObject().GetNamedString("num") == kd.num) { array[i].GetObject().Remove("time"); array[i].GetObject().Add("time", Windows.Data.Json.JsonValue.CreateStringValue(kd.newdata.time)); await Windows.Storage.FileIO.WriteTextAsync(tempkdfile, array.ToString()); return; } } } catch (Exception) { } }