public ProjectRequestAggregateModel Execute(ProjectRequestAggregateModel projectRequestAggregate)
        {
            // validate
            ValidationResult result = _projectRequestAggregateValidator.Validate(projectRequestAggregate);

            if (!result.Success)
            {
                throw new ValidationException(result.Messages);
            }

            // insert new record
            string sql = @"INSERT INTO ProjectRequestAggregates (ProjectId, RegularExpression, AggregateTarget, CreateDate) VALUES (@ProjectId, @RegularExpression, @AggregateTarget, @CreateDate)";

            _dbContext.ExecuteNonQuery(sql, projectRequestAggregate);

            // update the id
            sql = @"select last_insert_rowid()";
            projectRequestAggregate.Id = _dbContext.ExecuteScalar <int>(sql);

            // register jobs so all log files are reprocessed
            IEnumerable <LogFileModel> logFiles = _logFileRepo.GetByProject(projectRequestAggregate.ProjectId);

            foreach (LogFileModel logFile in logFiles)
            {
                _setLogFileUnprocessedCommand.Execute(logFile.Id);
            }

            return(projectRequestAggregate);
        }
        public void Execute_OnExecution_RunsQueriesAndRegistersJob()
        {
            int logFileId = new Random().Next(100, 1000);

            // execute
            _setLogFileUnprocessedCommand.Execute(logFileId);

            // assert
            _dbContext.Received(1).ExecuteNonQuery(Arg.Any <string>(), Arg.Any <object>());
            _jobRegistrationService.Received(1).RegisterAggregateRequestJob(logFileId);
        }
示例#3
0
        public void Execute(int id)
        {
            // load the record up
            ProjectRequestAggregateModel projectRequestAggregate = _projectRequestAggregateRepo.GetById(id);

            if (projectRequestAggregate == null)
            {
                throw new InvalidOperationException(String.Format("No project aggregate request found with id {0}", id));
            }

            // insert new record
            string sql = @"DELETE FROM ProjectRequestAggregates WHERE Id = @Id";

            _dbContext.ExecuteNonQuery(sql, new { Id = id });

            // register jobs so all log files are reprocessed
            IEnumerable <LogFileModel> logFiles = _logFileRepo.GetByProject(projectRequestAggregate.ProjectId);

            foreach (LogFileModel logFile in logFiles)
            {
                _setLogFileUnprocessedCommand.Execute(logFile.Id);
            }
        }