public NewsEntity(NewsEntity entity) : base(PARTITION_KEY, entity.RowKey) { NewsId = entity.NewsId; Title = entity.Title; Description = entity.Description; Image = entity.Image; Link = entity.Link; PublishDate = entity.PublishDate; Source = entity.Source; MovieName = entity.MovieName; ArtistName = entity.ArtistName; FutureJson = entity.FutureJson; IsActive = entity.IsActive; }
public static NewsEntity CreateNewsEntity(string title, string description, string image, string link, string publishDate, string source, string movieName, string artistName, string futureJson, bool isActive) { var newsId = Guid.NewGuid().ToString(); var newsEntity = new NewsEntity(newsId); newsEntity.Title = title; newsEntity.Description = description; newsEntity.Image = image; newsEntity.Link = link; newsEntity.PublishDate = publishDate; newsEntity.Source = source; newsEntity.ArtistName = movieName; newsEntity.MovieName = artistName; newsEntity.FutureJson = futureJson; newsEntity.IsActive = isActive; return(newsEntity); }
private List<NewsEntity> ParseNewsItems(string xml, string type) { XmlDocument doc = new XmlDocument(); try { doc.LoadXml(xml); List<NewsEntity> newsList = new List<NewsEntity>(); // Need mechanism to track the last news publish date. Currently it will add news instead of update each time. switch (type) { case "BollywoodNewsWorld": #region BollywoodNewsWorld var nodes = doc.SelectNodes("rss/channel/item"); foreach (XmlNode node in nodes) { NewsEntity news = new NewsEntity(); news.Description = node.SelectSingleNode("description") == null ? string.Empty : Util.StripHTMLTags(node.SelectSingleNode("description").InnerText); news.FutureJson = string.Empty; news.Image = string.Empty; news.Link = node.SelectSingleNode("link") == null ? string.Empty : node.SelectSingleNode("link").InnerText; news.PublishDate = node.SelectSingleNode("pubDate") == null ? string.Empty : node.SelectSingleNode("pubDate").InnerText; news.RowKey = news.NewsId = Guid.NewGuid().ToString(); news.Source = type; news.Title = node.SelectSingleNode("title") == null ? string.Empty : node.SelectSingleNode("title").InnerText; news.MovieName = string.Empty; news.ArtistName = string.Empty; newsList.Add(news); } #endregion break; case "GlamSham": #region GlamSham var items1 = doc.SelectNodes("rss/channel/item"); foreach (XmlNode node in items1) { NewsEntity news = new NewsEntity(); news.RowKey = news.NewsId = Guid.NewGuid().ToString(); news.Description = node.SelectSingleNode("description") == null ? string.Empty : Util.StripHTMLTags(node.SelectSingleNode("description").InnerText); news.FutureJson = string.Empty; news.Image = node.SelectSingleNode("img_scoop") == null ? string.Empty : node.SelectSingleNode("img_scoop").InnerText; //download image in our blob storage if (!string.IsNullOrEmpty(news.Image)) { news.Image = Util.DownloadImage(news.Image, news.NewsId); } news.PublishDate = node.SelectSingleNode("pubDate") == null ? string.Empty : node.SelectSingleNode("pubDate").InnerText; news.Source = type; news.Link = node.SelectSingleNode("link") == null ? string.Empty : node.SelectSingleNode("link").InnerText; news.Title = node.SelectSingleNode("title") == null ? string.Empty : node.SelectSingleNode("title").InnerText; news.MovieName = string.Empty; news.ArtistName = string.Empty; newsList.Add(news); } #endregion break; case "BollywoodHungama": #region BollywoodHungama var items2 = doc.SelectNodes("rss/channel/item"); foreach (XmlNode node in items2) { NewsEntity news = new NewsEntity(); news.RowKey = news.NewsId = Guid.NewGuid().ToString(); news.Description = node.SelectSingleNode("description") == null ? string.Empty : Util.StripHTMLTags(node.SelectSingleNode("description").InnerText); news.FutureJson = string.Empty; news.Image = node.SelectSingleNode("image") == null ? string.Empty : node.SelectSingleNode("image").InnerText; //download image in our blob storage if (!string.IsNullOrEmpty(news.Image)) { news.Image = Util.DownloadImage(news.Image, news.NewsId); } news.PublishDate = node.SelectSingleNode("pubDate") == null ? string.Empty : node.SelectSingleNode("pubDate").InnerText; news.Source = type; news.Link = node.SelectSingleNode("link") == null ? string.Empty : node.SelectSingleNode("link").InnerText; news.Title = node.SelectSingleNode("title") == null ? string.Empty : node.SelectSingleNode("title").InnerText; news.MovieName = string.Empty; news.ArtistName = string.Empty; newsList.Add(news); } #endregion break; case "HindustanTimes": #region BollywoodHungama var items3 = doc.SelectNodes("rss/channel/item"); foreach (XmlNode node in items3) { NewsEntity news = new NewsEntity(); news.RowKey = news.NewsId = Guid.NewGuid().ToString(); news.Description = node.SelectSingleNode("description") == null ? string.Empty : Util.StripHTMLTags(node.SelectSingleNode("description").InnerText); news.FutureJson = string.Empty; news.Image = node.SelectSingleNode("enclosure") == null ? string.Empty : node.SelectSingleNode("enclosure").Attributes["url"].Value; //download image in our blob storage if (!string.IsNullOrEmpty(news.Image)) { news.Image = Util.DownloadImage(news.Image, news.NewsId); } news.PublishDate = node.SelectSingleNode("pubDate") == null ? string.Empty : node.SelectSingleNode("pubDate").InnerText; news.RowKey = news.NewsId = Guid.NewGuid().ToString(); news.Source = type; news.Link = node.SelectSingleNode("link") == null ? string.Empty : node.SelectSingleNode("link").InnerText; news.Title = node.SelectSingleNode("title") == null ? string.Empty : node.SelectSingleNode("title").InnerText; news.MovieName = string.Empty; news.ArtistName = string.Empty; newsList.Add(news); } #endregion break; } return newsList; } catch (Exception) { return null; } }
public static NewsEntity CreateNewsEntity(string title, string description, string image, string link, string publishDate, string source, string movieName, string artistName, string futureJson, bool isActive) { var newsId = Guid.NewGuid().ToString(); var newsEntity = new NewsEntity(newsId); newsEntity.Title = title; newsEntity.Description = description; newsEntity.Image = image; newsEntity.Link = link; newsEntity.PublishDate = publishDate; newsEntity.Source = source; newsEntity.ArtistName = movieName; newsEntity.MovieName = artistName; newsEntity.FutureJson = futureJson; newsEntity.IsActive = isActive; return newsEntity; }