/// <summary> /// Execute the step for a given <paramref name="messagingContext"/>. /// </summary> /// <param name="messagingContext">The Message used during the step execution.</param> /// <returns></returns> public async Task <StepResult> ExecuteAsync(MessagingContext messagingContext) { if (messagingContext?.AS4Message == null) { throw new InvalidOperationException( $"{nameof(StoreAS4MessageStep)} requires an AS4Message to save but no AS4Message is present in the MessagingContext"); } Logger.Trace("Storing the AS4Message with Operation=ToBeProcessed..."); using (DatastoreContext context = _createContext()) { var repository = new DatastoreRepository(context); var service = new OutMessageService(_config, repository, _messageBodyStore); service.InsertAS4Message( messagingContext.AS4Message, messagingContext.SendingPMode, messagingContext.ReceivingPMode); try { await context.SaveChangesAsync().ConfigureAwait(false); } catch { messagingContext.ErrorResult = new ErrorResult( "Unable to store the received message due to an exception occured during the saving operation", ErrorAlias.Other); throw; } } Logger.Trace("Stored the AS4Message with Operation=ToBeProcesed"); return(await StepResult.SuccessAsync(messagingContext)); }
private async Task InsertRespondSignalToDatastore(MessagingContext messagingContext) { using (DatastoreContext dataContext = _createDatastoreContext()) { var repository = new DatastoreRepository(dataContext); var outMsgService = new OutMessageService(_config, repository, _messageBodyStore); IEnumerable <OutMessage> insertedMessageUnits = outMsgService.InsertAS4Message( messagingContext.AS4Message, messagingContext.SendingPMode, messagingContext.ReceivingPMode); await dataContext.SaveChangesAsync() .ConfigureAwait(false); ReplyHandling replyHandling = messagingContext.ReceivingPMode?.ReplyHandling; ReplyPattern? replyPattern = replyHandling?.ReplyPattern; if (replyPattern == ReplyPattern.PiggyBack && replyHandling?.PiggyBackReliability?.IsEnabled == true) { var piggyBackService = new PiggyBackingService(dataContext); piggyBackService.InsertRetryForPiggyBackedSignalMessages( insertedMessageUnits, messagingContext.ReceivingPMode?.ReplyHandling?.PiggyBackReliability); await dataContext.SaveChangesAsync() .ConfigureAwait(false); } } }