public List<BindData> Retrive(string Data) { List<BindData> list = new List<BindData>(); try { XDocument doc = XDocument.Parse(Data); foreach (XElement ele in doc.Descendants("item")) { BindData d = new BindData(); d.Tag = ele.Element("link").Value; d.Content = ele.Element("title").Value; string destocheck = ele.Element("description").Value; HtmlDocument HTdoc = new HtmlDocument(); HTdoc.LoadHtml(destocheck); HTdoc.DetectEncodingHtml(destocheck); d.Description = HttpUtility.HtmlDecode(HTdoc.DocumentNode.InnerText); list.Add(d); } return list; } catch (Exception c) { list=null; return list; } }
/// <summary> /// Agent that runs a scheduled task /// </summary> /// <param name="task"> /// The invoked task /// </param> /// <remarks> /// This method is called when a periodic or resource intensive task is invoked /// </remarks> protected override void OnInvoke(ScheduledTask task) { //TODO: Add code to perform your task in backgroun try { int q = ShellTile.ActiveTiles.Count(); foreach (ShellTile t in ShellTile.ActiveTiles) { if (t.NavigationUri != ShellTile.ActiveTiles.First().NavigationUri) { List<BindData> list = new List<BindData>(); ScheduledTaskAgent1.XML x = new ScheduledTaskAgent1.XML(); string link, filename, uri = t.NavigationUri.ToString(); string uri1 = uri.Remove(0, uri.IndexOf("=") + 1); link = uri1.Substring(0, uri1.IndexOf("&FileName")); string uri2 = uri1.Remove(0, uri1.IndexOf("&FileName") + 10); filename = uri2; string data = GetData(filename); list = x.Retrive(data); BindData toupdate = new BindData(); Random rand = new Random(); toupdate = list.ElementAt(rand.Next(list.Count)); t.Update(new StandardTileData { BackContent = toupdate.Content }); } } //ShellToast toast = new ShellToast(); //Mutex mutex = new Mutex(true, "ScheduledAgentData"); //mutex.WaitOne(); //IsolatedStorageSettings setting = IsolatedStorageSettings.ApplicationSettings; //toast.Title = "Tile"; //mutex.ReleaseMutex(); //toast.Content = "Updated"; //toast.Show(); //ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromSeconds(3)); } catch(Exception e) { ShellToast toast = new ShellToast(); Mutex mutex = new Mutex(true, "ScheduledAgentData"); mutex.WaitOne(); IsolatedStorageSettings setting = IsolatedStorageSettings.ApplicationSettings; toast.Title = "Tile"; mutex.ReleaseMutex(); toast.Content = "Tile Updation failed due to"+e.Message; toast.Show(); //ScheduledActionService.LaunchForTest(task.Name, TimeSpan.FromMinutes(3)); } NotifyComplete(); }