Beispiel #1
0
        public async Task <bool> ExecuteScrapeJobAsync(ScrapeJob scrapeJob)
        {
            if (scrapeJob == null)
            {
                return(false);
            }

            var result = new ScrapeJobEvent();

            try
            {
                var url = new Uri(scrapeJob.Url);
                result = await _scraper.ExecuteAsync(url, scrapeJob.Pattern);
            }
            catch (UriFormatException ex)
            {
                result.Type      = ScrapeJobEventType.Error;
                result.Message   = ex.Message;
                result.Url       = scrapeJob.Url;
                result.TimeStamp = DateTime.UtcNow;
            }

            result.ScrapeJobForeignKey = scrapeJob.Id;

            await _scrapeJobEventDomainService.AddAsync(result);

            var resultStatus = await _unitOfWork.CommitAsync();

            if (result.Type.Equals(ScrapeJobEventType.Match))
            {
                await SendScrapeSuccessEmail(result);
            }

            return(resultStatus);
        }
Beispiel #2
0
        public async Task <ScrapeJobEventDto> Create(ScrapeJobEventDto scrapeJobEvent)
        {
            if (scrapeJobEvent != null &&
                !string.IsNullOrEmpty(scrapeJobEvent.Message))
            {
                var entity = _mapper.Map <ScrapeJobEvent>(scrapeJobEvent);

                await _scrapeJobEventDomainService.AddAsync(entity);

                var success = await _unitOfWork.CommitAsync();

                if (success)
                {
                    return(_mapper.Map <ScrapeJobEventDto>(entity));
                }
            }

            return(null);
        }