Advertisement
FrayxRulez

Untitled

Oct 27th, 2014
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.66 KB | None | 0 0
  1. using NotificationsExtensions.TileContent;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Net.Http;
  6. using System.Text;
  7. using System.Text.RegularExpressions;
  8. using System.Xml.Linq;
  9. using Windows.ApplicationModel.Background;
  10. using Windows.UI.Notifications;
  11.  
  12. namespace CineBlog.Background
  13. {
  14.     public sealed class LiveTileTask : IBackgroundTask
  15.     {
  16.         public async void Run(IBackgroundTaskInstance taskInstance)
  17.         {
  18.             var deferral = taskInstance.GetDeferral();
  19.  
  20.             var client = new HttpClient();
  21.             var request = new HttpRequestMessage(HttpMethod.Get, "http://www.cineblog01.eu/feed/");
  22.             var response = await client.SendAsync(request);
  23.             var content = await response.Content.ReadAsStringAsync();
  24.             var document = XDocument.Parse(content);
  25.  
  26.             var tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();
  27.             tileUpdater.EnableNotificationQueue(true);
  28.  
  29.             var index = 0;
  30.  
  31.             foreach (var item in document.Descendants("item"))
  32.             {
  33.                 var title = item.Descendants("title").FirstOrDefault().Value;
  34.                 var description = item.Descendants("description").FirstOrDefault().Value;
  35.                 var thumbnail = Regex.Match(description, "<img.+?src=[\"'](.+?)[\"'].*?>").Groups[1].Value;
  36.  
  37.                 var tileLargeContent = TileContentFactory.CreateTileSquare310x310ImageAndTextOverlay01();
  38.                 tileLargeContent.Image.Src = thumbnail;
  39.                 tileLargeContent.TextHeadingWrap.Text = title;
  40.  
  41.                 var tileWideContent = TileContentFactory.CreateTileWide310x150PeekImage03();
  42.                 tileWideContent.Image.Src = thumbnail;
  43.                 tileWideContent.TextHeadingWrap.Text = title;
  44.  
  45.                 //var tileMediumContent = TileContentFactory.CreateTileSquare150x150PeekImageAndText04();
  46.                 //tileMediumContent.Image.Src = thumbnail;
  47.                 //tileMediumContent.TextBodyWrap.Text = title;
  48.                 var tileMediumContent = TileContentFactory.CreateTileSquare150x150PeekImageAndText02();
  49.                 tileMediumContent.Image.Src = thumbnail;
  50.                 tileMediumContent.TextHeading.Text = title;
  51.  
  52.                 tileWideContent.Square150x150Content = tileMediumContent;
  53.                 tileLargeContent.Wide310x150Content = tileWideContent;
  54.  
  55.                 var liveTile = tileLargeContent.CreateNotification();
  56.                 liveTile.Tag = "tile" + index;
  57.  
  58.                 tileUpdater.Update(liveTile);
  59.  
  60.                 index++;
  61.             }
  62.  
  63.             deferral.Complete();
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement