private async Task <MessagingContext> InsertReceivedAS4MessageAsync(MessagingContext messagingContext) { using (DatastoreContext context = _createDatastoreContext()) { MessageExchangePattern messageExchangePattern = messagingContext.Mode == MessagingContextMode.PullReceive ? MessageExchangePattern.Pull : MessageExchangePattern.Push; try { var service = new InMessageService(_config, new DatastoreRepository(context)); AS4Message as4Message = await service .InsertAS4MessageAsync( messagingContext.AS4Message, messagingContext.ReceivedMessage, messagingContext.SendingPMode, messageExchangePattern, _messageBodyStore) .ConfigureAwait(false); messagingContext.ModifyContext(as4Message); await context.SaveChangesAsync().ConfigureAwait(false); return(messagingContext); } catch (Exception ex) { return(new MessagingContext(ex)); } } }
/// <summary> /// Execute the step for a given <paramref name="messagingContext"/>. /// </summary> /// <param name="messagingContext">Message used during the step execution.</param> /// <returns></returns> public async Task <StepResult> ExecuteAsync(MessagingContext messagingContext) { if (messagingContext?.AS4Message == null) { throw new InvalidOperationException( $"{nameof(UpdateReceivedAS4MessageBodyStep)} requires an AS4Message to update but no AS4Message is present in the MessagingContext"); } Logger.Trace("Updating the received message body..."); using (DatastoreContext datastoreContext = _createDatastoreContext()) { var repository = new DatastoreRepository(datastoreContext); var service = new InMessageService(_configuration, repository); service.UpdateAS4MessageForMessageHandling( messagingContext.AS4Message, messagingContext.SendingPMode, messagingContext.ReceivingPMode, _messageBodyStore); await datastoreContext.SaveChangesAsync().ConfigureAwait(false); } if (messagingContext.ReceivedMessageMustBeForwarded) { // When the Message has to be forwarded, the remaining Steps must not be executed. // The MSH must answer with a HTTP Accepted status-code, so an empty context must be returned. messagingContext.ModifyContext(AS4Message.Empty); Logger.Info( "Stops execution to return empty SOAP envelope to the orignal sender. " + "This happens when the message must be forwarded"); return(StepResult.Success(messagingContext).AndStopExecution()); } return(StepResult.Success(messagingContext)); }