コード例 #1
0
        public async Task <List <RssSourceDto> > Handle(GetRssSourceByIdQuery request, CancellationToken cancellationToken)
        {
            var rssSources = await _context.RssSources.Where(s => !request.Id.HasValue || s.Id.Equals(request.Id))
                             .Select(s => _mapper.Map <RssSourceDto>(s))
                             .ToListAsync(cancellationToken);

            return(rssSources);
        }
コード例 #2
0
ファイル: NewsCqsService.cs プロジェクト: ItSerzh/GoodNews
        public async Task Aggregate()
        {
            var query      = new GetRssSourceByIdQuery(null);
            var rssSources = await _mediator.Send(query);

            var newsList = new ConcurrentBag <NewsDto>();

            var currentNewsUrls = await _mediator.Send(new GetOwnNewsUrlQuery());

            Parallel.ForEach(rssSources, (rssSource) =>
            {
                using (var reader = XmlReader.Create(rssSource.Url))
                {
                    var feed = SyndicationFeed.Load(reader);
                    reader.Close();

                    var feedUrls = feed.Items.Select(i => i.Id).ToList();


                    Log.Information($"News count in DB: {currentNewsUrls.Count}");

                    foreach (var feedItem in feed.Items)
                    {
                        if (!currentNewsUrls.Any(url => url.Equals(feedItem.Id)))
                        {
                            var newsDto = new NewsDto()
                            {
                                Id          = Guid.NewGuid(),
                                RssSourceId = rssSource.Id,
                                Url         = feedItem.Id,
                                Title       = feedItem.Title.Text,
                                Summary     = SyndicationHelper.GetSyndicationItemSummary(feedItem),
                                NewsDate    = feedItem.PublishDate.UtcDateTime,
                                DateCollect = DateTime.UtcNow
                            };
                            newsList.Add(newsDto);
                        }
                    }
                }
            });
            //return newsList;
        }
コード例 #3
0
        public async Task <IEnumerable <RssSourceDto> > GetRssSources(Guid?id = null)
        {
            var getRssSourceByIdQuery = new GetRssSourceByIdQuery(id);

            return(await _mediator.Send(getRssSourceByIdQuery));
        }