public async Task <bool> AddBatch(Batch batch) { if (batch == null) { throw new ArgumentNullException(nameof(batch)); } BatchHistory history; base.AddGeneric(batch); if (await SaveChangesAsync() && batch.BatchId > 0) { history = new BatchHistory { BatchId = batch.BatchId, Units = batch.DeliveredUnits, Description = $"Order of {batch.DeliveredUnits} units delivered" }; base.AddGeneric(history); if (await SaveChangesAsync() && history.BatchHistoryId > 0) { return(true); } else { base.DeleteGeneric(batch); return(await SaveChangesAsync()); } } else { return(false); } }
private BosiStatusModel CreateBosiStatusModel(ExternalSystem system, BatchHistory batch, Severity severity) { var defaultDate = DateTime.Parse("01/01/1970"); var count = EventLogger.CountLogEntriesWithStatus(system.Id, severity, batch == null ? defaultDate : batch.RunEnd); return(count > 0 ? new BosiStatusModel(system, severity, batch) { LogCount = count } : null); }
public async Task CreateBatchHistory(BatchHistory batchHistory) { var queryParameters = new DynamicParameters(); queryParameters.Add("@BatchGroupId", batchHistory.GroupId); queryParameters.Add("@BatchActionId", batchHistory.ActionId); queryParameters.Add("@StartTime", batchHistory.StartTime); queryParameters.Add("@EndTime", batchHistory.EndTime); queryParameters.Add("@BatchStatusId", (int)batchHistory.Status); queryParameters.Add("@Message", batchHistory.Message); await ExecuteNonQueryAsync(StoredProcedureNames.CreateBatchHistory, queryParameters); }
public static BatchHistory CreateBatchHistory( int id, int systemId, DateTime runStart, DateTime runEnd, string filename = null, string message = "Success", BatchOutcome outcome = BatchOutcome.Success ) { var entity = new BatchHistory { Id = id, SystemId = systemId, RunStart = runStart, RunEnd = runEnd, Filename = filename, Message = message, Outcome = (int)outcome }; return(entity); }
public BosiStatusModel(ExternalSystem system, Severity severity, BatchHistory lastBatch) { var defaultDate = DateTime.Parse("01/01/1970"); SystemId = system.Id; SystemName = system.Name; Direction = (ExternalSystemDirection)system.Direction; Severity = (int)severity; SeverityName = LogEntry.GetSeverityName(severity); if (lastBatch == null) { LastAction = defaultDate; Outcome = BatchOutcome.Success; Message = "Success"; } else { LastAction = lastBatch.RunEnd; Outcome = BatchOutcome.DataError; Message = lastBatch.Message; } }
public async Task <Unit> Handle(ExecuteBatchCommand request, CancellationToken cancellationToken) { var batchGroup = await _batchGroupRepository.GetBatchGroupById(request.GroupId); if (batchGroup == null) { throw new NotFoundException("BatchGroup", request.GroupId); } var batchConfig = await _batchGroupRepository.GetBatchConfig(request.GroupId, request.ActionId); if (batchConfig != null && !batchConfig.IsEnabled) { _logger.LogInformation("Batch action {Atlas_BatchActionId} is not enabled for group {Atlas_BatchGroupId} is disabled.", request.ActionId, request.GroupId); return(Unit.Value); } if (!batchGroup.Companies.Any()) { _logger.LogWarning("No companies configured for batch group {Atlas_BatchGroupId}.", request.GroupId); return(Unit.Value); } var batchHistory = new BatchHistory { GroupId = request.GroupId, ActionId = request.ActionId, StartTime = DateTime.UtcNow }; try { if (request.ActionId == (int)BatchAction.CleanupAudit) { await CleanUpAudit(batchGroup.Companies); } else if (request.ActionId == (int)BatchAction.CleanupProcessMessages) { await CleanUpProcessMessages(batchGroup.Companies); } else if (request.ActionId == (int)BatchAction.CleanupSsrsPredicate) { await CleanUpSsrsPredicates(batchGroup.Companies); } else if (request.ActionId == (int)BatchAction.CreateDailyFreeze) { await CreateFreeze(batchGroup.Companies, DataVersionType.Daily); } else if (request.ActionId == (int)BatchAction.CreateMonthlyFreeze) { await CreateFreeze(batchGroup.Companies, DataVersionType.Monthly); } else if (request.ActionId == (int)BatchAction.PostingProcess) { await ExecutePostingProcess(batchGroup.Companies); } else if (request.ActionId == (int)BatchAction.SettleFxDeal) { await ExecuteFXSettlements(batchGroup.Companies); } else if (request.ActionId == (int)BatchAction.SyncADStatusProcess) { await SyncADStatus(batchGroup.Companies); } _logger.LogInformation("Batch action {Atlas_BatchActionId} has been executed for group {Atlas_BatchGroupId}.", request.ActionId, request.GroupId); batchHistory.Status = BatchExecutionStatus.Completed; batchHistory.Message = "Batch done."; return(Unit.Value); } catch (Exception e) { batchHistory.Status = BatchExecutionStatus.Failed; batchHistory.Message = e.ToString(); throw; } finally { batchHistory.EndTime = DateTime.UtcNow; await _batchGroupRepository.CreateBatchHistory(batchHistory); } }