public void LoadPreviousJson() { var path = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName, "feed", JsonGenerator.CurrentDate()); if (Directory.Exists(path) && Directory.EnumerateFiles(path).Any()) { foreach (var file in Directory.EnumerateFiles(path)) { var json = File.ReadAllText(file); var jsonObject = JObject.Parse(json); foreach (var item in jsonObject["items"]) { var date = item["pubDate"]; var formattedDate = DateFormatter.ChangePubdateFormat(date.ToString()); if (!_newsCache.ContainsKey(item["title"].ToString())) { try { UpdateCache(item["title"].ToString(), formattedDate.Date); } catch (Exception e) { Console.WriteLine(e); throw; } } } } } }
public List <Content> ListOfNewsGenerator() { Rss channel; NewsCache cache = new NewsCache(); var serializer = new XmlSerializer(typeof(Rss)); using (var reader = new StringReader(Feeder().Result)) { channel = (Rss)serializer.Deserialize(reader); foreach (var item in channel.Channel.Items) { var formattedDate = DateFormatter.ChangePubdateFormat(item.PubDate); if (!cache.IsAlreadySaved(item.Title, formattedDate.Date)) { _items.Add(item); cache.UpdateCache(item.Title, formattedDate.Date); } } } return(_items); }