Exemplo n.º 1
0
        private async Task FetchAndSendEmail(CommentsDownloaderDbContext context)
        {
            var messages = context.CommentRequests.Where(
                cr => cr.CommentsFetched && !cr.MailSent).ToList();

            if (messages.Any())
            {
                foreach (var message in messages)
                {
                    _logger.LogInformation($"sending mail for {message.TempFileDirectory}");
                    message.MailSent = await SendMail(message);

                    message.ModifiedBy   = "System";
                    message.ModifiedDate = DateTime.UtcNow;
                    context.Attach(message);
                    context.Entry(message).State = EntityState.Modified;
                    await context.SaveChangesAsync();
                }
            }
        }
        private async Task FetchAndSendRequests(CommentsDownloaderDbContext context)
        {
            var requests = context.CommentRequests.Where(cr => !cr.CommentsFetched).ToList();

            if (requests.Any())
            {
                foreach (var request in requests)
                {
                    var    host     = new Uri(request.RequestUrl)?.Host;
                    string fileName = "";
                    switch (host)
                    {
                    case AppConstants.YoutubeHost:
                        _logger.LogInformation("Hello Youtube");
                        fileName = await _fetcherFactory(AppConstants.Youtube).FetchComments(request);

                        break;

                    case AppConstants.AmazonHost:
                        _logger.LogInformation("Hello Amazon");
                        fileName = await _fetcherFactory(AppConstants.Amazon).FetchComments(request);

                        break;

                    default:
                        _logger.LogInformation("We haven't implemented that yet");
                        break;
                    }
                    request.CommentsFetched   = true;
                    request.ModifiedBy        = "System";
                    request.TempFileDirectory = fileName;
                    request.ModifiedDate      = DateTime.UtcNow;
                    context.Attach(request);
                    context.Entry(request).State = EntityState.Modified;
                    await context.SaveChangesAsync();
                }
            }
        }