Пример #1
0
        public static async Task <List <NewsModel> > GetGpuNews()
        {
            var parameters = new HttpRequestParameters
            {
                Url    = StringResources.GpuRssUrl,
                Method = HttpMethod.Get
            };

            var result = await HttpRequestHelper.GetStringFromUrl(parameters);

            if (string.IsNullOrEmpty(result))
            {
                return(null);
            }

            var rssContent = XmlSerializationHelper.DeserializeStringToXmlObject <GpuRss>(result);

            if (rssContent == null)
            {
                return(null);
            }

            var news       = new List <NewsModel>();
            var itemsCount = rssContent.Channel.Item.Count;
            var rgx        = new Regex("\\&\\w+\\;$");

            foreach (var gpNews in rssContent.Channel.Item)
            {
                if (string.IsNullOrEmpty(gpNews.Title) ||
                    string.IsNullOrEmpty(gpNews.Description) ||
                    string.IsNullOrEmpty(gpNews.Link2) ||
                    gpNews.Enclosure == null)
                {
                    continue;
                }

                gpNews.Description = rgx.Replace(gpNews.Description, "...");

                var newNews = new NewsModel
                {
                    Title            = gpNews.Title,
                    Description      = gpNews.Description,
                    CoverArtImageUrl = gpNews.Enclosure.Url,
                    OriginalUrl      = gpNews.Link2
                };

                news.Add(newNews);
            }
            return(news);
        }