public static void CreateSchedule() { var tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication(); var plannedUpdated = tileUpdater.GetScheduledTileNotifications(); DateTime now = DateTime.Now; DateTime planTill = now.AddHours(4); DateTime updateTime = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, 0).AddMinutes(1); if (plannedUpdated.Count > 0) { updateTime = plannedUpdated.Select(x => x.DeliveryTime.DateTime).Union(new[] { updateTime }).Max(); } XmlDocument documentNow = WriteXml(now); tileUpdater.Update(new TileNotification(documentNow) { ExpirationTime = now.AddMinutes(1) }); for (var startPlanning = updateTime; startPlanning < planTill; startPlanning = startPlanning.AddMinutes(1)) { XmlDocument document = WriteXml(startPlanning); ScheduledTileNotification scheduledNotification = new ScheduledTileNotification(document, new DateTimeOffset(startPlanning)) { ExpirationTime = startPlanning.AddMinutes(1) }; tileUpdater.AddToSchedule(scheduledNotification); } }
void ScheduleTile(String updateString, DateTime dueTime, int idNumber) { // Set up the wide tile text ITileWide310x150Text09 tileContent = TileContentFactory.CreateTileWide310x150Text09(); tileContent.TextHeading.Text = updateString; tileContent.TextBodyWrap.Text = "Received: " + dueTime.ToLocalTime(); // Set up square tile text ITileSquare150x150Text04 squareContent = TileContentFactory.CreateTileSquare150x150Text04(); squareContent.TextBodyWrap.Text = updateString; tileContent.Square150x150Content = squareContent; // Create the notification object ScheduledTileNotification futureTile = new ScheduledTileNotification(tileContent.GetXml(), dueTime); futureTile.Id = "Tile" + idNumber; // Add to schedule // You can update a secondary tile in the same manner using CreateTileUpdaterForSecondaryTile(tileId) // See "Tiles" sample for more details TileUpdateManager.CreateTileUpdaterForApplication().AddToSchedule(futureTile); rootPage.NotifyUser("Scheduled a tile with ID: " + futureTile.Id, NotifyType.StatusMessage); }
private void FutureLiveTile() { var applicationTile = TileContentFactory.CreateTileWidePeekImage02(); var tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication(CoreApplication.Id); // clear the existing tile info tileUpdater.Clear(); applicationTile.TextHeading.Text = "Future Top Scores"; applicationTile.TextBody1.Text = "Future Player 1 - 100"; applicationTile.TextBody2.Text = "Future Player 1 - 92"; applicationTile.TextBody3.Text = "Future Player 1 - 90"; applicationTile.TextBody4.Text = "Future Player 1 - 85"; applicationTile.RequireSquareContent = false; applicationTile.Image.Src = "/Images/AltLiveTileImage_310x150.png"; var futureTile = new ScheduledTileNotification(applicationTile.GetXml(), DateTime.Now.AddSeconds(10)); if (ExpireContent) { futureTile.ExpirationTime = DateTime.Now.AddSeconds(20); } tileUpdater.AddToSchedule(futureTile); }
void ScheduleTileWithStringManipulation(String updateString, DateTime dueTime, int idNumber) { string tileXmlString = "<tile>" + "<visual version='2'>" + "<binding template='TileWide310x150Text09' fallback='TileWideText09'>" + "<text id='1'>" + updateString + "</text>" + "<text id='2'>" + "Received: " + dueTime.ToLocalTime() + "</text>" + "</binding>" + "<binding template='TileSquare150x150Text04' fallback='TileSquareText04'>" + "<text id='1'>" + updateString + "</text>" + "</binding>" + "</visual>" + "</tile>"; Windows.Data.Xml.Dom.XmlDocument tileDOM = new Windows.Data.Xml.Dom.XmlDocument(); try { tileDOM.LoadXml(tileXmlString); // Create the notification object ScheduledTileNotification futureTile = new ScheduledTileNotification(tileDOM, dueTime); futureTile.Id = "Tile" + idNumber; // Add to schedule // You can update a secondary tile in the same manner using CreateTileUpdaterForSecondaryTile(tileId) // See "Tiles" sample for more details TileUpdateManager.CreateTileUpdaterForApplication().AddToSchedule(futureTile); rootPage.NotifyUser("Scheduled a tile with ID: " + futureTile.Id, NotifyType.StatusMessage); } catch (Exception) { rootPage.NotifyUser("Error loading the xml, check for invalid characters in the input", NotifyType.ErrorMessage); } }
public static void UpdateTile() { // create the instance of Tile Updater, which enables you to change the appearance of the calling app's tile var updater = TileUpdateManager.CreateTileUpdaterForApplication(); // enables the tile to queue up to five notifications updater.EnableNotificationQueue(true); updater.Clear(); // task is set to run after 15 minutes so we need to schedule 15 notifications // to change tile every minute // WARNING: Maybe there can be a gap which will require more then 15 notifications??? var now = DateTime.Now; for (int i = 1; i <= 15; i++) { var notifyTime = now.Subtract(TimeSpan.FromSeconds(now.Second)).AddMinutes(i); // plan it for start of the new minute var notifyText = notifyTime.ToString("MM.dd.yyyy hh:mm", System.Globalization.CultureInfo.InvariantCulture); // get the XML content of one of the predefined tile templates, so that, you can customize it XmlDocument tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150PeekImageAndText04); tileXml.GetElementsByTagName("text")[0].InnerText = notifyText; // Create a new tile notification. var notification = new ScheduledTileNotification(tileXml, notifyTime); notification.ExpirationTime = notifyTime.AddSeconds(10); updater.AddToSchedule(notification); } }
public static void CreateScheduledTileNotification(TileContent content, DateTime dueTime, string id) { ScheduledTileNotification scheduledTile = new ScheduledTileNotification(content.GetXml(), dueTime); scheduledTile.Id = id; RemoveSpecScheduledTileNotification(id); TileUpdateManager.CreateTileUpdaterForApplication().AddToSchedule(scheduledTile); }
public void ScheduleRedditTileUpdate(string tileId, IList <GalleryItem> images) { TileContent content = GetTileContent(tileId, images); var dueTime = DateTime.Now.AddSeconds(5); var futureTile = new ScheduledTileNotification(content.GetXml(), dueTime); TileUpdateManager.CreateTileUpdaterForSecondaryTile(tileId).AddToSchedule(futureTile); }
private static void CreateScheduledTileNotification(TaskModel task, XmlDocument xml) { ScheduledTileNotification tile = new ScheduledTileNotification(xml, task.Notification); tile.Id = task.Id.ToString(); tile.ExpirationTime = new DateTimeOffset(task.Deadline); TileUpdateManager.CreateTileUpdaterForApplication().AddToSchedule(tile); }
private static void _updatePrimaryTile(string text, string imgSrc, string imgAlt, TileTemplateType templateType) { TileUpdateManager.CreateTileUpdaterForApplication().EnableNotificationQueue(true); XmlDocument tileXml = TileUpdateManager.GetTemplateContent(templateType); //TileWide310x150ImageAndText01 //version XmlNodeList tileVersionAttributes = tileXml.GetElementsByTagName("visual"); ((XmlElement)tileVersionAttributes[0]).SetAttribute("version", "2"); //tileXml.FirstChild.FirstChild.Attributes[0].NodeValue = "2"; ////branding //XmlNodeList tileBindingAttributes = tileXml.GetElementsByTagName("binding"); //((XmlElement)tileBindingAttributes[0]).SetAttribute("branding", "logo"); //text XmlNodeList tileTextAttributes = tileXml.GetElementsByTagName("text"); if (tileTextAttributes.Count > 0) { tileTextAttributes[0].InnerText = text; } //tileTextAttributes[1].InnerText = "xxxxx"; //image XmlNodeList tileImageAttributes = tileXml.GetElementsByTagName("image"); ////image from apps package //((XmlElement)tileImageAttributes[0]).SetAttribute("src", "ms-appx:///assets/redWide.png"); //((XmlElement)tileImageAttributes[0]).SetAttribute("alt", "red graphic"); ////image from apps local storage //((XmlElement)tileImageAttributes[0]).SetAttribute("src", "ms-appdata:///local/redWide.png"); //((XmlElement)tileImageAttributes[0]).SetAttribute("alt", "red graphic"); ((XmlElement)tileImageAttributes[0]).SetAttribute("src", imgSrc); ((XmlElement)tileImageAttributes[0]).SetAttribute("alt", imgAlt); ////image from the web //((XmlElement)tileImageAttributes[0]).SetAttribute("src", "http://www.contoso.com/redWide.png"); //((XmlElement)tileImageAttributes[0]).SetAttribute("alt", "red graphic"); //create notifcation //TileNotification tileNotification = new TileNotification(tileXml); ScheduledTileNotification stn = new ScheduledTileNotification(tileXml, DateTimeOffset.Now.AddSeconds(8)); //notification expires in //tileNotification.ExpirationTime = DateTimeOffset.UtcNow.AddMinutes(10); //forced clear notification for app //Windows.UI.Notifications.TileUpdateManager.CreateTileUpdaterForApplication().Clear(); //send notification to app tile //TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification); TileUpdateManager.CreateTileUpdaterForApplication().AddToSchedule(stn); }
public static void doTask() { var tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication(); var plannedUpdates = tileUpdater.GetScheduledTileNotifications(); string language = GlobalizationPreferences.Languages.First(); CultureInfo cultureInfo = new CultureInfo(language); DateTime now = DateTime.Now; DateTime planTill = now.AddHours(1); DateTime updateTime = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, 0).AddMinutes(1); if (plannedUpdates.Count > 0) { updateTime = plannedUpdates.Select(x => x.DeliveryTime.DateTime).Union(new[] { updateTime }).Max(); } // xml for Tile layout : https://msdn.microsoft.com/en-us/library/windows/apps/hh761491.aspx const string xml = @"<tile><visual> <binding template=""TileMedium""><text hint-style=""subtitle"" hint-wrap=""true"" id=""1"">{0}</text></binding> <binding template=""TileWide""><text hint-style=""title"" hint-wrap=""true"" id=""1"">{0}</text><text id=""2"">{1}</text></binding> </visual></tile>"; string textTime = getTextTime(now); var tileXmlNow = string.Format(xml, textTime, now.ToString(cultureInfo.DateTimeFormat.LongDatePattern)); XmlDocument documentNow = new XmlDocument(); documentNow.LoadXml(tileXmlNow); tileUpdater.Update(new TileNotification(documentNow) { ExpirationTime = now.AddMinutes(1) }); // for next 1 hour Schedule the notifications. for (var startPlanning = updateTime; startPlanning < planTill; startPlanning = startPlanning.AddMinutes(1)) { try { textTime = getTextTime(startPlanning); var tileXml = string.Format(xml, textTime, startPlanning.ToString(cultureInfo.DateTimeFormat.LongDatePattern)); XmlDocument document = new XmlDocument(); document.LoadXml(tileXml); ScheduledTileNotification scheduledNotification = new ScheduledTileNotification(document, new DateTimeOffset(startPlanning)) { ExpirationTime = startPlanning.AddMinutes(1) }; tileUpdater.AddToSchedule(scheduledNotification); } catch (Exception e) { // do nothing } } }
public async static void RefreshTiles(IList <Memo> allMemos) { // load xml template var installLocation = Windows.ApplicationModel.Package.Current.InstalledLocation; var assetsFolder = await installLocation.GetFolderAsync("Assets"); var tileXmlFile = await assetsFolder.GetFileAsync(tileXmlFileName); var xmlText = await FileIO.ReadTextAsync(tileXmlFile); // set TileUpdater var tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication(); tileUpdater.EnableNotificationQueue(true); // start time var startTime = DateTime.Now.AddSeconds(10); // temp list to add tiles, then reverse it according to the emgergency tileUpdater.Clear(); var now = DateTime.Now; List <Memo> tempList = new List <Memo>(); for (int i = 0, addCount = 0; i < allMemos.Count && addCount < 5; ++i) { Memo memo = allMemos[i]; if (now.CompareTo(memo.Time) <= 0) { ++addCount; tempList.Add(memo); } } // reverse and add to schedule for (int i = 0; i < tempList.Count; ++i) { Memo memo = tempList[tempList.Count - 1 - i]; // set title and caption var tileXml = new XmlDocument(); tileXml.LoadXml(string.Format(xmlText, memo.Title, Time2String.Time2Str(memo.Time) + "\n" + memo.Content)); var tileNotification = new ScheduledTileNotification(tileXml, startTime.AddSeconds(i * 10)); tileNotification.Tag = memo.MemoID.Substring(6, 10); // set expiration time tileNotification.ExpirationTime = memo.Time.AddMinutes(1); tileUpdater.AddToSchedule(tileNotification); } }
//Update tile for today private void UpdateTile(CalendarDataReader reader, DateTime dueTime) { int month = dueTime.Month; int day = dueTime.Day; PanchangData pdata = reader.GetPanchangData(month, day); //create the wide template ITileWideText01 tileContent = TileContentFactory.CreateTileWideText01(); tileContent.TextHeading.Text = dueTime.ToString("d"); // Uncomment the following line to enable debugging tileContent.TextBody1.Text = pdata._fieldValues[(int)FieldType.SanskritMonth]; tileContent.TextBody2.Text = pdata._fieldValues[(int)FieldType.TamilMonth]; tileContent.TextBody3.Text = pdata._fieldValues[(int)FieldType.Festival]; //create the square template and attach it to the wide template ITileSquareText01 squareContent = TileContentFactory.CreateTileSquareText01(); squareContent.TextHeading.Text = dueTime.ToString("d"); squareContent.TextBody1.Text = pdata._fieldValues[(int)FieldType.SanskritMonth]; squareContent.TextBody2.Text = pdata._fieldValues[(int)FieldType.TamilMonth]; squareContent.TextBody3.Text = pdata._fieldValues[(int)FieldType.Festival]; tileContent.SquareContent = squareContent; if (dueTime > DateTime.Now) { ScheduledTileNotification futureTile = new ScheduledTileNotification(tileContent.GetXml(), dueTime); TileUpdateManager.CreateTileUpdaterForApplication().AddToSchedule(futureTile); } else { //send the notification //TileUpdateManager.CreateTileUpdaterForApplication().Update(tileContent.CreateNotification()); } //Send another notification. this gives a nice animation in mogo tileContent.TextBody1.Text = pdata._fieldValues[(int)FieldType.Paksha]; tileContent.TextBody2.Text = pdata._fieldValues[(int)FieldType.Tithi]; tileContent.TextBody3.Text = pdata._fieldValues[(int)FieldType.Nakshatra]; if (dueTime > DateTime.Now) { ScheduledTileNotification futureTile = new ScheduledTileNotification(tileContent.GetXml(), dueTime); TileUpdateManager.CreateTileUpdaterForApplication().AddToSchedule(futureTile); } else { //send the notification //TileUpdateManager.CreateTileUpdaterForApplication().Update(tileContent.CreateNotification()); } }
/// <summary> /// One large square image with four smaller square images to its right, no text. /// http://msdn.microsoft.com/en-us/library/windows/apps/hh761491#TileWideImageCollection /// </summary> /// <param name="item">The current Note item, this will allow us to get the notebooks for the image collection.</param> private static void TryCreateCollectionTile(NoteDataCommon item) { var totalImages = item.NoteBook.Items.SelectMany(i => i.Images).ToList(); if (totalImages.Count >= 5) { ITileWide310x150ImageCollection tileContent = TileContentFactory.CreateTileWide310x150ImageCollection(); for (var i = 0; i < 5; i++) { var imgUrl = totalImages[i].ToBaseUrl(); switch (i) { case 0: tileContent.ImageMain.Src = imgUrl; tileContent.ImageMain.Alt = item.NoteBook.Title; break; case 1: tileContent.ImageSmallColumn1Row1.Src = imgUrl; tileContent.ImageSmallColumn1Row1.Alt = item.NoteBook.Title; break; case 2: tileContent.ImageSmallColumn1Row2.Src = imgUrl; tileContent.ImageSmallColumn1Row2.Alt = item.NoteBook.Title; break; case 3: tileContent.ImageSmallColumn2Row1.Src = imgUrl; tileContent.ImageSmallColumn2Row1.Alt = item.NoteBook.Title; break; case 4: tileContent.ImageSmallColumn2Row2.Src = imgUrl; tileContent.ImageSmallColumn2Row2.Alt = item.NoteBook.Title; break; } } ITileSquare150x150PeekImageAndText04 squareTileContent = TileContentFactory.CreateTileSquare150x150PeekImageAndText04(); squareTileContent.Image.Src = totalImages[0].ToBaseUrl(); squareTileContent.Image.Alt = item.Title; squareTileContent.TextBodyWrap.Text = item.Title; tileContent.Square150x150Content = squareTileContent; ScheduledTileNotification schduleTile = new ScheduledTileNotification(tileContent.GetXml(), DateTime.Now.AddSeconds(10)); TileUpdateManager.CreateTileUpdaterForApplication().EnableNotificationQueue(true); TileUpdateManager.CreateTileUpdaterForApplication().AddToSchedule(schduleTile); } }
public void SetLiveTile(string text1, string text2) { if ((ApplicationData.Current.RoamingSettings.Values["LiveTile"].ToString() == "true") && gesamtAnzahlNoten != 0) { var tileXml1 = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare310x310ImageAndText02); var tileXml2 = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWide310x150ImageAndText02); var tileXml3 = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150PeekImageAndText01); var notification1 = new ScheduledTileNotification(tileXml1, DateTime.Now.AddSeconds(2)); var notification2 = new ScheduledTileNotification(tileXml2, DateTime.Now.AddSeconds(4)); var notification3 = new ScheduledTileNotification(tileXml3, DateTime.Now.AddSeconds(6)); notification1.ExpirationTime = DateTime.Now + TimeSpan.FromDays(14); notification2.ExpirationTime = DateTime.Now + TimeSpan.FromDays(14); notification3.ExpirationTime = DateTime.Now + TimeSpan.FromDays(14); //groß XmlNodeList nodes1 = tileXml1.GetElementsByTagName("image"); nodes1[0].Attributes[1].NodeValue = "ms-appx:///Assets/" + "large-live.png"; nodes1 = tileXml1.GetElementsByTagName("text"); nodes1[0].InnerText = text1; nodes1[1].InnerText = text2; //weit XmlNodeList nodes2 = tileXml2.GetElementsByTagName("image"); nodes2[0].Attributes[1].NodeValue = "ms-appx:///Assets/" + "wide-live.png"; nodes2 = tileXml2.GetElementsByTagName("text"); nodes2[0].InnerText = text1; nodes2[1].InnerText = text2; //normal XmlNodeList nodes3 = tileXml3.GetElementsByTagName("image"); nodes3[0].Attributes[1].NodeValue = "ms-appx:///Assets/" + "small-live.png"; nodes3 = tileXml3.GetElementsByTagName("text"); nodes3[0].InnerText = "Stand"; nodes3[1].InnerText = text1; nodes3[2].InnerText = text2; TileUpdateManager.CreateTileUpdaterForApplication().EnableNotificationQueue(true); TileUpdateManager.CreateTileUpdaterForApplication().AddToSchedule(notification1); TileUpdateManager.CreateTileUpdaterForApplication().AddToSchedule(notification2); TileUpdateManager.CreateTileUpdaterForApplication().AddToSchedule(notification3); } else { TileUpdateManager.CreateTileUpdaterForApplication().Clear(); } }
public static void CreateSchedule(int cinemaid = -1) { TileUpdater updater = TileUpdateManager.CreateTileUpdaterForApplication(); foreach (var item in updater.GetScheduledTileNotifications()) { if (DateTime.Now > item.ExpirationTime) { updater.RemoveFromSchedule(item); } } IReadOnlyList <ScheduledTileNotification> scheduledTileNotifications = updater.GetScheduledTileNotifications(); DateTime time = DateTime.Now; DateTime time2 = time.AddHours(2.0); DateTime time3 = new DateTime(time.Year, time.Month, time.Day, time.Hour, time.Minute, 0).AddMinutes(1.0); if (scheduledTileNotifications.Count > 0) { DateTime dtTemp = scheduledTileNotifications[scheduledTileNotifications.Count - 1].DeliveryTime.DateTime.AddMinutes(1); if (dtTemp > time3) { time3 = dtTemp; } } string format = "<tile><visual><binding template=\"TileSquareImage\"><image id=\"1\" src=\"{0}\"/></binding></visual></tile>"; for (DateTime time4 = time3; time4 < time2; time4 = time4.AddMinutes(1.0)) { try { List <Uri> uris = App.GetRandomImages(cinemaid); string str2 = string.Format(format, uris[0], uris[1], uris[2], uris[3], uris[4]); XmlDocument document = new XmlDocument(); document.LoadXml(str2); ScheduledTileNotification notification2 = new ScheduledTileNotification(document, new DateTimeOffset(time4)); notification2.ExpirationTime = (new DateTimeOffset?((DateTimeOffset)time4.AddMinutes(1.0))); ScheduledTileNotification notification = notification2; updater.AddToSchedule(notification); } catch (Exception) { } } }
/// <summary> /// Removes the tile from the schedule. /// </summary> /// <param name="uid">The uid.</param> public static void RemoveTile(string uid) { try { // Check if a tile has a tag with the specified uid ScheduledTileNotification scheduledTileNotification = _tileUpdater.GetScheduledTileNotifications().FirstOrDefault(o => o.Tag.Equals(uid, StringComparison.OrdinalIgnoreCase)); // If a tile is found, remove it if (scheduledTileNotification != null) { _tileUpdater.RemoveFromSchedule(scheduledTileNotification); } } catch (Exception ex) { LogFile.Instance.LogError("", "", ex.ToString()); } }
// Update tile for today private void UpdateTile(SampleDataItem item, DateTime dueTime, DateTime expiryTime) { DateTime date = dueTime; int month = date.Month; int day = date.Day; String festival; var notifier = TileUpdateManager.CreateTileUpdaterForApplication(); Debug.WriteLine("Update tile {0} {1}", dueTime, expiryTime); festival = item.GetFestival(month, day); PanchangData pdata = item.GetPanchangData(month, day); // create the wide template ITileWideText01 tileContent = TileContentFactory.CreateTileWideText01(); tileContent.TextHeading.Text = date.ToString("d"); tileContent.TextBody1.Text = pdata._fieldValues[(int)FieldType.SanskritMonth]; tileContent.TextBody2.Text = pdata._fieldValues[(int)FieldType.TamilMonth]; tileContent.TextBody3.Text = festival; // create the square template and attach it to the wide template ITileSquareText01 squareContent = TileContentFactory.CreateTileSquareText01(); squareContent.TextHeading.Text = date.ToString("d"); squareContent.TextBody1.Text = pdata._fieldValues[(int)FieldType.SanskritMonth]; squareContent.TextBody2.Text = pdata._fieldValues[(int)FieldType.TamilMonth]; squareContent.TextBody3.Text = festival; tileContent.SquareContent = squareContent; // send the notification ScheduledTileNotification futureTile = new ScheduledTileNotification(tileContent.GetXml(), dueTime); futureTile.ExpirationTime = expiryTime; notifier.AddToSchedule(futureTile); // Send another notification. this gives a nice animation in mogo tileContent.TextBody1.Text = pdata._fieldValues[(int)FieldType.Paksha]; tileContent.TextBody2.Text = pdata._fieldValues[(int)FieldType.Tithi]; tileContent.TextBody3.Text = pdata._fieldValues[(int)FieldType.Nakshatra]; futureTile = new ScheduledTileNotification(tileContent.GetXml(), dueTime); futureTile.ExpirationTime = expiryTime; notifier.AddToSchedule(futureTile); Debug.WriteLine("Count of scheduled notifications {0}", notifier.GetScheduledTileNotifications().Count); }
// Tile public void showTile() { XmlDocument smallTileData = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150PeekImageAndText02); XmlNodeList smallTextData = smallTileData.GetElementsByTagName("text"); XmlNodeList smallImageData = smallTileData.GetElementsByTagName("image"); smallTextData[0].InnerText = postsList.ElementAt(0).brief; smallTextData[1].InnerText = postsList.ElementAt(0).date; ((XmlElement)smallImageData[0]).SetAttribute("src", "ms-appx:///" + postsList.ElementAt(0).imageUrl); // ((XmlElement)smallImageData[0]).SetAttribute("src", "ms-appx:///Assets/Logo.jpg"); ((XmlElement)smallImageData[0]).SetAttribute("alt", "red graphic"); //宽版 // XmlDocument wideTileData = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWide310x150BlockAndText01); // XmlNodeList wideTextData = smallTileData.GetElementsByTagName("text"); // XmlNodeList wideImageData = smallTileData.GetElementsByTagName("image"); // wideTextData[0].InnerText = postsList.ElementAt(0).brief; // wideTextData[1].InnerText = postsList.ElementAt(0).date; // ((XmlElement)wideImageData[0]).SetAttribute("src", "ms-appx:///" + postsList.ElementAt(0).imageUrl); //// ((XmlElement)wideImageData[0]).SetAttribute("src", "ms-appx:///Assets/Wide310x150Logo.scale-100.jpg"); // ((XmlElement)wideImageData[0]).SetAttribute("alt", "red graphic"); // IXmlNode newNode = wideTileData.ImportNode(smallTileData.GetElementsByTagName("binding").Item(0), true); // 计划通知 Int16 dueTimeInSeconds = 3; DateTime dueTime = DateTime.Now.AddSeconds(dueTimeInSeconds); ScheduledTileNotification scheduledTile = new ScheduledTileNotification(smallTileData, dueTime); scheduledTile.Id = "Future_Tile"; //TileUpdateManager.CreateTileUpdaterForApplication().AddToSchedule(scheduledTile); TileNotification notification = new TileNotification(smallTileData); //TileNotification notification = new TileNotification(wideTileData); //notification.ExpirationTime = DateTimeOffset.UtcNow.AddSeconds(10); // TileUpdateManager.CreateTileUpdaterForApplication().Update(notification); //定期通知 string polledUrl = "http://appdev.sysu.edu.cn/~mad/Tools/Test/sample.xml"; PeriodicUpdateRecurrence recurrence = PeriodicUpdateRecurrence.HalfHour; System.Uri url = new System.Uri(polledUrl); // TileUpdateManager.CreateTileUpdaterForApplication().StartPeriodicUpdate(url, recurrence); }
/// <summary> /// 更新头条文章的磁贴tile /// </summary> /// <param name="t"></param> private static void UpdateTile(LatestStories t) { //头5条 循环更新到tile中 List <string> list = t.Top_Stories.ToList().Select(s => s.Title).ToList(); List <string> list_image = t.Top_Stories.ToList().Select(s => s.Image).ToList(); var tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication(); var plannedNotifications = tileUpdater.GetScheduledTileNotifications(); DateTime now = DateTime.Now; DateTime updateTime = now; DateTime planTill = now.AddMinutes(60); //每次制定1小时的tile更新计划 //删除还未执行的计划 if (plannedNotifications.Count > 0) { plannedNotifications.ToList().ForEach(s => tileUpdater.RemoveFromSchedule(s)); } int index = 0; int count = list.Count; //制定tile更新的计划 for (var startPlanning = updateTime; startPlanning < planTill; startPlanning = startPlanning.AddSeconds(10)) { try { var tilexml = TileContentFactory.CreateTileSquare150x150PeekImageAndText02(); tilexml.Image.Src = list_image[index % count]; tilexml.TextHeading.Text = "知乎日报UWP"; tilexml.TextBodyWrap.Text = list[index % count]; index++; ScheduledTileNotification stn = new ScheduledTileNotification(tilexml.GetXml(), startPlanning); stn.ExpirationTime = startPlanning.AddSeconds(8); tileUpdater.AddToSchedule(stn); } catch { } } }
/// <summary> /// Show a local notification at a specified time /// </summary> /// <param name="title">Title of the notification</param> /// <param name="body">Body or description of the notification</param> /// <param name="id">Id of the notification</param> /// <param name="notifyTime">Time to show notification</param> public void Show(string title, string body, int id, DateTime notifyTime) { var xmlData = string.Format(_TOAST_TEXT02_TEMPLATE, title, body); var xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xmlData); var correctedTime = notifyTime <= DateTime.Now ? DateTime.Now.AddMilliseconds(100) : notifyTime; var scheduledTileNotification = new ScheduledTileNotification(xmlDoc, correctedTime) { Id = id.ToString() }; TileUpdateManager.CreateTileUpdaterForApplication().AddToSchedule(scheduledTileNotification); }
public static async void GenerateSceduledTileNotifications(IEnumerable <Contact> contacts, int numOfTiles) { List <Contact> cList = contacts.Where(c => c.ContactImage != null).ToList(); cList.Sort((x, y) => DateTime.Compare(Convert.ToDateTime(x.CreationDate), Convert.ToDateTime(y.CreationDate))); StorageFolder storageFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("LiveTileImages", CreationCollisionOption.OpenIfExists); foreach (var item in await storageFolder.GetFilesAsync()) { await item.DeleteAsync(); } int count = cList.Count >= numOfTiles ? numOfTiles : cList.Count; for (int i = 0; i < count; i++) { Contact c_tmp = cList[i]; StorageFile tilePic = await storageFolder.CreateFileAsync(c_tmp.Id + ".png", CreationCollisionOption.ReplaceExisting); await FileIO.WriteBytesAsync(tilePic, c_tmp.ContactImage); // not over 200K or 1024px or TemporaryFolder var imageUri = new Uri("ms-appdata:///local/LiveTileImages/" + c_tmp.Id + ".png", UriKind.Absolute); string tileXmlString = "<tile>" + "<visual>" + "<binding template='TileMedium' branding='name'>" + "<image id='1' src='" + imageUri + "'/>" + "<text id='1'>" + c_tmp.Name + "</text>" + "</binding>" + "</visual>" + "</tile>"; XmlDocument tileXml = new XmlDocument(); tileXml.LoadXml(tileXmlString); ScheduledTileNotification sceduleNotification = new ScheduledTileNotification(tileXml, DateTime.Now.AddSeconds(15)); TileUpdateManager.CreateTileUpdaterForApplication().EnableNotificationQueue(true); TileUpdateManager.CreateTileUpdaterForApplication().AddToSchedule(sceduleNotification); } }
/// <summary> /// Notifies the specified notification. /// </summary> /// <param name="notification">The notification.</param> public void Notify(LocalNotification notification) { var tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150Text02); var tileTitle = tileXml.GetElementsByTagName("text"); ((XmlElement)tileTitle[0]).InnerText = notification.Title; ((XmlElement)tileTitle[1]).InnerText = notification.Text; var correctedTime = notification.NotifyTime <= DateTime.Now ? DateTime.Now.AddMilliseconds(100) : notification.NotifyTime; var scheduledTileNotification = new ScheduledTileNotification(tileXml, correctedTime) { Id = notification.Id.ToString() }; TileUpdateManager.CreateTileUpdaterForApplication().AddToSchedule(scheduledTileNotification); }
public void Add(ref ListBox display, string value, TimeSpan occurs) { DateTime when = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, occurs.Hours, occurs.Minutes, occurs.Seconds); if (when > DateTime.Now) { XmlDocument xml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150Text03); xml.GetElementsByTagName("text")[0].InnerText = value; xml.GetElementsByTagName("text")[1].InnerText = when.ToString("HH:mm"); ScheduledTileNotification tile = new ScheduledTileNotification(xml, when) { Id = _random.Next(1, 100000000).ToString() }; _updater.AddToSchedule(tile); display.Items.Add(new Item { Id = tile.Id, Content = value, Time = when.ToString() }); } }
private static void ScheduleTileUpdate(DateTimeOffset dtoTime, Settings settings) { if (dtoTime < DateTimeOffset.Now) { return; } var tileXml = TileCreator.GenerateTile(settings.AppLanguage, dtoTime, settings.TileTier); Debug.WriteLine("Tile XML generated"); ScheduledTileNotification stn = new ScheduledTileNotification(tileXml, dtoTime); // assign a tag for better id stn.Tag = dtoTime.ToString("yyMMdd hhmm", CultureInfo.InvariantCulture); Debug.WriteLine("Scheduling notification {0}", stn.Tag); var tileUpdaterApp = TileUpdateManager.CreateTileUpdaterForApplication(); tileUpdaterApp.AddToSchedule(stn); // secondary if (SecondaryTile.Exists(SecondaryAppTileId)) { try { ScheduledTileNotification stn2 = new ScheduledTileNotification(tileXml, dtoTime); // assign a tag for better id stn.Tag = dtoTime.ToString("yyMMdd hhmm", CultureInfo.InvariantCulture); Debug.WriteLine("Scheduling notification {0}", stn.Tag); var tileUpdaterApp2 = TileUpdateManager.CreateTileUpdaterForSecondaryTile(SecondaryAppTileId); tileUpdaterApp2.AddToSchedule(stn2); } catch { ; } } }
public static void UpdateTile() { // create the instance of Tile Updater, which enables you to change the appearance of the calling app's tile var updater = TileUpdateManager.CreateTileUpdaterForApplication(); // enables the tile to queue up to five notifications updater.EnableNotificationQueue(true); updater.Clear(); for (int i = 0; i < 15; i++) { // get the XML content of one of the predefined tile templates, so that, you can customize it XmlDocument tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150PeekImageAndText04); tileXml.GetElementsByTagName("text")[0].InnerText = i.ToString(); // Create a new tile notification. var notification = new ScheduledTileNotification(tileXml, DateTime.Now.AddSeconds(10 + i * 10)); notification.ExpirationTime = DateTime.Now.AddSeconds(10 + i * 10 + 5); updater.AddToSchedule(notification); } }
void RefreshListView() { IReadOnlyList <ScheduledToastNotification> scheduledToasts = ToastNotificationManager.CreateToastNotifier().GetScheduledToastNotifications(); IReadOnlyList <ScheduledTileNotification> scheduledTiles = TileUpdateManager.CreateTileUpdaterForApplication().GetScheduledTileNotifications(); int toastLength = scheduledToasts.Count; int tileLength = scheduledTiles.Count; List <NotificationData> bindingList = new List <NotificationData>(toastLength + tileLength); for (int i = 0; i < toastLength; i++) { ScheduledToastNotification toast = scheduledToasts[i]; bindingList.Add(new NotificationData() { ItemType = "Toast", ItemId = toast.Id, DueTime = toast.DeliveryTime.ToLocalTime().ToString(), InputString = toast.Content.GetElementsByTagName("text")[0].InnerText, IsTile = false }); } for (int i = 0; i < tileLength; i++) { ScheduledTileNotification tile = scheduledTiles[i]; bindingList.Add(new NotificationData() { ItemType = "Tile", ItemId = tile.Id, DueTime = tile.DeliveryTime.ToLocalTime().ToString(), InputString = tile.Content.GetElementsByTagName("text")[0].InnerText, IsTile = true }); } ItemGridView.ItemsSource = bindingList; }
private static void UpdateScheduledNotifications(TileUpdater updater, Countdown countdown, DateTime now) { var start = now.Date + countdown.Date.TimeOfDay; if (start < now) { start = start.AddDays(1); } var scheduledNotifications = updater.GetScheduledTileNotifications(); if (scheduledNotifications.Count > 0) { var latest = scheduledNotifications.Max(x => x.DeliveryTime.DateTime); if (latest > start) { start = latest; } } var name = countdown.Name; var imageUri = countdown.GetImageFileUri(); var diff = (start.Date - now.Date).TotalDays; if (diff < MaxScheduledNotifications) { var end = start.AddDays(MaxScheduledNotifications - diff); for (var plan = start; plan <= end; plan = plan.AddDays(1)) { var daysRemaining = countdown.GetDaysRemaining(plan); var content = CreateTileContent(name, imageUri, daysRemaining); var notification = new ScheduledTileNotification(content, plan); updater.AddToSchedule(notification); } } }
private static void Schedule(TileUpdater updater, XmlDocument content, DateTime deliveryTime, DateTime?expirationTime) { if (deliveryTime == null || deliveryTime < DateTime.Now.AddSeconds(30)) { var tileNotif = new TileNotification(content); if (expirationTime != null) { tileNotif.ExpirationTime = expirationTime; } updater.Update(tileNotif); } else { var scheduledNotif = new ScheduledTileNotification(content, deliveryTime); if (expirationTime != null) { scheduledNotif.ExpirationTime = expirationTime; } updater.AddToSchedule(scheduledNotif); } }
// 添加指定的 ScheduledTileNotification 到指定的 secondary tile 的计划列表中 private void btnAddScheduledTile_Click(object sender, RoutedEventArgs e) { string tileXml = $@" <tile> <visual> <binding template='TileSmall'> <text>Small(小){DateTime.Now.ToString("HH:mm:ss")}</text> </binding> <binding template='TileMedium'> <text>Medium(中){DateTime.Now.ToString("HH:mm:ss")}</text> </binding> <binding template='TileWide'> <text>Wide(宽){DateTime.Now.ToString("HH:mm:ss")}</text> </binding> <binding template='TileLarge'> <text>Large(大){DateTime.Now.ToString("HH:mm:ss")}</text> </binding> </visual> </tile>"; XmlDocument tileDoc = new XmlDocument(); tileDoc.LoadXml(tileXml); // 实例化 ScheduledTileNotification 对象(15 秒后显示此 Tile 通知) DateTime dt = DateTime.Now.AddSeconds(15); ScheduledTileNotification tileNotification = new ScheduledTileNotification(tileDoc, dt); tileNotification.Id = new Random().Next(100000, 1000000).ToString();; tileNotification.Tag = $"在 {dt.ToString("HH:mm:ss")} 时显示此 tile 通知"; // 将指定的 ScheduledTileNotification 对象添加进指定的 secondary tile 的计划列表 TileUpdater tileUpdater = TileUpdateManager.CreateTileUpdaterForSecondaryTile(TILEID); tileUpdater.AddToSchedule(tileNotification); tileUpdater.EnableNotificationQueue(true); // 启用 tile 的队列功能(最多可容纳 5 个 tile) ShowScheduledTiles(); }
private void tileUpdateButton_Click(object sender, RoutedEventArgs e) { // タイルのテンプレート選択 // http://msdn.microsoft.com/ja-jp/library/windows/apps/hh761491.aspx#TileSquareText03 XmlDocument tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWideImageAndText01); // キューに複数のタイル通知を設定可能にする //TileUpdateManager.CreateTileUpdaterForApplication().EnableNotificationQueue(true); XmlNodeList tileTextAttributes = tileXml.GetElementsByTagName("text"); tileTextAttributes[0].InnerText = this.tileText.Text; XmlNodeList tileImageAttributes = tileXml.GetElementsByTagName("image"); ((XmlElement)tileImageAttributes[0]).SetAttribute("src", "ms-appx:///Assets/wideTile.png"); ((XmlElement)tileImageAttributes[0]).SetAttribute("alt", "wideTile.png"); XmlDocument squareTileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquareText04); XmlNodeList squareTileTextAttributes = squareTileXml.GetElementsByTagName("text"); squareTileTextAttributes[0].AppendChild(squareTileXml.CreateTextNode(this.tileText.Text)); IXmlNode node = tileXml.ImportNode(squareTileXml.GetElementsByTagName("binding").Item(0), true); tileXml.GetElementsByTagName("visual").Item(0).AppendChild(node); Int16 dueTimeInSeconds = 15; DateTime dueTime = DateTime.Now.AddSeconds(dueTimeInSeconds); ScheduledTileNotification tileNotification = new ScheduledTileNotification(tileXml, dueTime); tileNotification.Tag = this.tileText.Text; //tileNotification.ExpirationTime = DateTimeOffset.UtcNow.AddSeconds(10); TileUpdateManager.CreateTileUpdaterForApplication().AddToSchedule(tileNotification); }