/// <summary> /// Creates and adds the data to the viewmodels /// </summary> public void LoadData(bool reload) { if (!IsEssentialsLoaded) { LoadInfo(); LoadAssociations(); LoadSettings(); try { LoadFaceBookSettings(); } catch (Exception) { //NIET INGELOGD } } if (!reload) { return; } RestoItems.Clear(); NewsItems.Clear(); ActivityItems.Clear(); SchamperItems.Clear(); _fromCache = DateTime.Now.AddMinutes(-60) < _cacheTime; if (!_fromCache && !HasConnection) { _fromCache = true; } LoadNews(); LoadResto(); LoadActivities(); LoadSchamper(); }
public void ProcessSchamper(object sender, DownloadStringCompletedEventArgs e) { XElement resultElements = null; if ((e == null && !_fromCache) || (e != null && (e.Error != null || e.Cancelled))) { _schamper = true; return; } if (e == null && _fromCache) { var s = LoadFromStorage("schamper", ".xml"); if (!s.Equals("")) { resultElements = XElement.Parse(s); } else { return; } } else if (e != null) { resultElements = XElement.Parse(SaveToStorage("schamper", ".xml", e.Result)); } if (resultElements != null) { var xElement = resultElements.Element(XName.Get("channel")); if (xElement != null) { foreach (var schamperItem in xElement.Elements()) { if (schamperItem.Name != "item") { continue; } var dc = XNamespace.Get("http://purl.org/dc/elements/1.1/"); string date = null, author = null, title = null, image = null, content = null; var element = schamperItem.Element(dc + "creator"); if (element != null) { author = element.Value; } element = schamperItem.Element("pubDate"); if (element != null) { date = element.Value; } element = schamperItem.Element(XName.Get("title")); if (element != null) { title = element.Value; } element = schamperItem.Element(XName.Get("description")); if (element != null) { content = element.Value; string[] inputs = { content }; const string pattern = @"(https?:)?//?[^''""<>]+?\.(jpg|jpeg|gif|png)"; var rgx = new Regex(pattern, RegexOptions.IgnoreCase); foreach (var match in from input in inputs select rgx.Matches(input) into matches where matches.Count > 0 from Match match in matches select match) { image = match.Value; } } if (SchamperItems != null) { SchamperItems.Add(new SchamperItemsViewModel { Author = author, Content = content, ImagePath = image, Title = title, Date = date }); } } } } _schamper = true; }