Ejemplo n.º 1
0
        public Either <string, long> AddUrl(string url)
        {
            try
            {
                var existingUrlHolder = _dbContext.FilteredUrls.Find(filteredUrl => filteredUrl.Url.Equals(url));

                if (existingUrlHolder.IsSome)
                {
                    _logger.LogInformation("URL: {0} already exists in filtered url set", url);
                    return(string.Format("URL: {0} already exists in filtered url set", url));
                }

                _logger.LogInformation("Adding URL: {0} to filtered sites", url);
                var filteredUrl = new FilteredUrl()
                {
                    Url = url
                };

                _dbContext.FilteredUrls.Add(filteredUrl);
                _dbContext.SaveChanges();

                return(filteredUrl.Id);
            }
            catch (Exception ex)
            {
                _logger.LogError("Can't add new URL: {0} to be filtered - {1}", url, ex.Message);
                return(string.Format("Can't add URL: {0} to filtered sites", url));
            }
        }
Ejemplo n.º 2
0
        public Either <string, long> IngestLogs()
        {
            try {
                _logger.LogInformation("looking for previous processed logs");
                var linesProcessed = GetLinesProcessed();

                _logger.LogInformation("the following logs have been already processed: {0}", linesProcessed);

                _logger.LogInformation("getting logs from file");

                var textLogs  = GetLogs(linesProcessed);
                var entryLogs = _accessLogParser.ParseLogs(textLogs);

                _logger.LogInformation("storing logs into DB");

                var entities = BuildAccessLog(entryLogs);

                _dbContext.AccessLogs.AddRange(entities);
                _dbContext.SaveChanges();

                var processedLogs = entryLogs.Count();
                _logger.LogInformation("logs processed: {0}", processedLogs);

                return(processedLogs);
            }
            catch (Exception ex)
            {
                _logger.LogError("can't process logs - ", ex);
                return(string.Format("Can't process log resource: {0}", _accessLog.GetLogResource()));
            }
        }