Beispiel #1
0
        public void Execute_InvalidFileFormat_MarksFileAsError()
        {
            LogFileModel logFile      = DataHelper.CreateLogFileModel();
            LogFileModel savedLogFile = null;

            string fileName = Path.GetRandomFileName() + ".log";
            string filePath = Path.Combine(AppContext.BaseDirectory, fileName);

            File.WriteAllText(filePath, "This is not a valid IIS file");

            _logFileRepo.GetById(logFile.Id).Returns(logFile);

            _dbContext.When(x => x.ExecuteNonQuery(Arg.Any <String>(), Arg.Any <LogFileModel>())).Do((c) => {
                savedLogFile = c.ArgAt <LogFileModel>(1);
            });

            // execute
            _processLogFileCommand.Execute(logFile.Id, filePath);

            // assert
            _createRequestBatchCommand.DidNotReceive().Execute(Arg.Any <int>(), Arg.Any <IEnumerable <W3CEvent> >());
            _jobRegistrationService.DidNotReceive().RegisterProcessLogFileJob(Arg.Any <int>(), Arg.Any <string>());
            _dbContext.Received(1).ExecuteNonQuery(Arg.Any <String>(), Arg.Any <LogFileModel>());

            Assert.IsNotNull(savedLogFile);
            Assert.AreEqual(LogFileStatus.Error, savedLogFile.Status);
            Assert.IsTrue(savedLogFile.ErrorMsg.Contains("File is not a valid IIS"));
        }
        public void Execute(int logFileId)
        {
            // load all the requests for the log file
            IEnumerable <RequestModel> requests = _requestRepo.GetByLogFile(logFileId);

            // only apply aggregates if we have requests!
            if (requests.Any())
            {
                // load all the aggregates for the project
                LogFileModel logFile = _logFileRepo.GetById(logFileId);
                IEnumerable <ProjectRequestAggregateModel> requestAggregates = _projectRequestAggregateRepo.GetByProject(logFile.ProjectId);

                // run through the requests and apply the configured aggregates - if the value changes then update in the database
                foreach (var req in requests)
                {
                    const string usql             = "UPDATE Requests SET UriStemAggregate = @UriStemAggregate WHERE Id = @RequestId";
                    string       uriStemAggregate = _requestAggregationService.GetAggregatedUriStem(req.UriStem, requestAggregates);
                    if (uriStemAggregate != req.UriStemAggregate)
                    {
                        _dbContext.ExecuteNonQuery(usql, new { UriStemAggregate = uriStemAggregate, RequestId = req.Id });
                    }
                }
            }

            // mark the log file as processed
            string sql = "UPDATE LogFiles SET Status = @Status WHERE Id = @LogFileId";

            _dbContext.ExecuteNonQuery(sql, new { LogFileId = logFileId, Status = LogFileStatus.Complete });
            _logger.Info("Marked LogFile {0} as Complete", logFileId);
        }
Beispiel #3
0
        public void Execute_RequestsFound_AggregatesLoadedAndLogFileMarkedAsProcessed()
        {
            int logFileId = new Random().Next(1, 1000);

            // setup
            RequestModel[] requests = { DataHelper.CreateRequestModel(logFileId), DataHelper.CreateRequestModel(logFileId) };
            _requestRepo.GetByLogFile(logFileId).Returns(requests);

            LogFileModel logFile = DataHelper.CreateLogFileModel();

            logFile.Id = logFileId;
            _logFileRepo.GetById(logFileId).Returns(logFile);

            // execute
            _resetRequestAggregateCommand.Execute(logFileId);

            // assert
            _requestRepo.Received(1).GetByLogFile(logFileId);
            _logFileRepo.Received(1).GetById(logFileId);
            _projectRequestAggregateRepo.Received(1).GetByProject(logFile.ProjectId);
        }
        public void Execute(int logFileId, string filePath)
        {
            LogFileModel logFile = _logFileRepo.GetById(logFileId);

            try
            {
                // load the contents of the file
                List <W3CEvent> logEvents;
                try
                {
                    logEvents = W3CEnumerable.FromFile(filePath).ToList();
                }
                catch (Exception)
                {
                    throw new FileFormatException("File is not a valid IIS log file");
                }


                // save the requests
                _createRequestBatchCommand.Execute(logFileId, logEvents);

                // update the record count of the log file
                const string sql = "UPDATE LogFiles SET RecordCount = @RecordCount WHERE Id = @Id";
                _dbContext.ExecuteNonQuery(sql, new { Id = logFileId, RecordCount = logEvents.Count });

                // delete the file
                _fileWrap.Delete(filePath);

                // register the job that marks the file as needing aggregate processing
                _jobRegistrationService.RegisterResetProcessedLogFileJob(logFile.Id);
            }
            catch (Exception ex)
            {
                // try and update the status of the log file record, the file will be marked as in an error state
                logFile.Status   = BLL.Lookup.LogFileStatus.Error;
                logFile.ErrorMsg = ex.Message;
                string sql = "UPDATE LogFiles SET Status = @Status, ErrorMsg = @ErrorMsg WHERE Id = @Id";
                _dbContext.ExecuteNonQuery(sql, logFile);
            }
        }