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);
        }
Пример #2
0
        public dynamic Aggregates(dynamic pId)
        {
            // make sure the id is a valid integer
            int projectId = 0;

            if (!Int32.TryParse((pId ?? "").ToString(), out projectId))
            {
                return(HttpStatusCode.BadRequest);
            }

            IEnumerable <ProjectRequestAggregateModel> aggregates = _projectRequestAggregateRepo.GetByProject(projectId);

            return(this.Response.AsJson <IEnumerable <ProjectRequestAggregateModel> >(aggregates));
        }
Пример #3
0
        public void Aggregates_ValidProjectId_GetsAggregatesFromDatabase()
        {
            int projectId = new Random().Next(1, 1000);

            // setup
            var currentUser = new UserIdentity()
            {
                Id = Guid.NewGuid(), UserName = "******"
            };
            var browser = new Browser((bootstrapper) =>
                                      bootstrapper.Module(new ProjectModule(_dbContext, _projectValidator, _createProjectCommand, _deleteProjectCommand, _projectRepo, _logFileRepo, _requestRepo, _projectRequestAggregateRepo))
                                      .RequestStartup((container, pipelines, context) => {
                context.CurrentUser = currentUser;
            })
                                      );
            ProjectRequestAggregateModel pra1 = DataHelper.CreateProjectRequestAggregateModel();
            ProjectRequestAggregateModel pra2 = DataHelper.CreateProjectRequestAggregateModel();
            ProjectRequestAggregateModel pra3 = DataHelper.CreateProjectRequestAggregateModel();

            _projectRequestAggregateRepo.GetByProject(projectId).Returns(new ProjectRequestAggregateModel[] { pra1, pra2, pra3 });

            // execute
            var url      = Actions.Project.Aggregates(projectId);
            var response = browser.Post(url, (with) =>
            {
                with.HttpRequest();
                with.FormsAuth(currentUser.Id, new Nancy.Authentication.Forms.FormsAuthenticationConfiguration());
            });

            // assert
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            _projectRequestAggregateRepo.Received(1).GetByProject(projectId);

            IEnumerable <ProjectRequestAggregateModel> result = JsonConvert.DeserializeObject <IEnumerable <ProjectRequestAggregateModel> >(response.Body.AsString());

            Assert.AreEqual(3, result.Count());
        }