public async Task <RfqPauseErrorCode> AddAsync(string operationId, PauseSource source, Initiator initiator) { if (string.IsNullOrEmpty(operationId)) { throw new ArgumentNullException(nameof(operationId)); } var locker = _lock.GetOrAdd(operationId, new SemaphoreSlim(1, 1)); await locker.WaitAsync(); try { var existingPause = (await _pauseRepository.FindAsync( operationId, SpecialLiquidationSaga.OperationName, NotCancelledPredicate)) .SingleOrDefault(); if (existingPause != null) { await _log.WriteWarningAsync(nameof(RfqPauseService), nameof(AddAsync), $"There is already pause with state [{existingPause.State}] for operation with id [{operationId}]"); return(RfqPauseErrorCode.AlreadyExists); } var executionInfo = await _executionInfoRepository .GetAsync <SpecialLiquidationOperationData>(SpecialLiquidationSaga.OperationName, operationId); if (executionInfo == null) { return(RfqPauseErrorCode.NotFound); } if (!AllowedOperationStatesToPauseIn.Contains(executionInfo.Data.State)) { await _log.WriteWarningAsync(nameof(RfqPauseService), nameof(AddAsync), $"There was an attempt to pause special liquidation with id {operationId} and state {executionInfo.Data.State}. Pause is possible in [{string.Join(',', AllowedOperationStatesToPauseIn)}] states only"); return(RfqPauseErrorCode.InvalidOperationState); } var pause = Pause.Create( operationId, SpecialLiquidationSaga.OperationName, source, initiator, _dateService.Now()); await _pauseRepository.AddAsync(pause); // todo: add audit log } finally { locker.Release(); } return(RfqPauseErrorCode.None); }
public Task <IEnumerable <Pause> > FindAsync(string operationId, string operationName, Func <Pause, bool> filter = null) { return(_decoratee.FindAsync(operationId, operationName, filter)); }