public static FeedCollection IntervalHandler(FeedCollection mainCollection) { DateTime CurrentTime = DateTime.Now; if (mainCollection != null && mainCollection.Count > 0) { try { for (int i = 0; i < mainCollection.Count; i++) { TimeSpan timeDiff = CurrentTime - mainCollection[i].TimeLastChecked; var hoursSinceCheck = timeDiff.Hours; Feed feedToCheck = (Feed)mainCollection[i].DeepClone(); if (mainCollection[i].UpdateInterval == 24 && hoursSinceCheck >= 24 || mainCollection[i].UpdateInterval == 1 && hoursSinceCheck >= 1) { TransferInterface.UpdateChecker(feedToCheck); if (TransferInterface.TransmitFeed.FeedItems.Count > mainCollection[i].FeedItems.Count) { mainCollection[i] = TransferInterface.TransmitFeed; mainCollection[i].TimeLastChecked = DateTime.Now; } } } } catch (Exception e) { Console.Write(e.Message); } } return(mainCollection); }
public static void XmlOperation(Feed myFeed) { var xmlString = Data.GetXml.getXmlInfo(); var dom = new XmlDocument(); if (xmlString != null) { try { dom.LoadXml(xmlString); foreach (XmlNode item in dom.DocumentElement.SelectNodes("channel/item")) { var title = item.SelectSingleNode("title").InnerText; var description = item.SelectSingleNode("description").InnerText; var itemPubDate = item.SelectSingleNode("pubDate").InnerText; var guid = item.SelectSingleNode("guid").Value; string mediaUrl = null; var enclosure = item.SelectSingleNode("enclosure"); if (enclosure != null) { mediaUrl = enclosure.Attributes["url"].Value; } var media = item.SelectSingleNode("media"); if (media != null) { mediaUrl = media.Attributes["url"].Value; } FeedItem myFeedItem = new FeedItem(guid, title, mediaUrl, itemPubDate, description); myFeed.addFeedItem(myFeedItem); } TransferInterface.TransmitFeed = myFeed; } catch { string message = "URL:en måste inkludera en RSS-feed"; bool ERROR = true; TransferInterface.ErrorHandler(ERROR, message); } } else { string message = "Felaktig URL!"; bool ERROR = true; TransferInterface.ErrorHandler(ERROR, message); } }