private async Task UpdateRetryStatusForMessageAsync(MessagingContext ctx, SendResult result) { if (ctx.MessageEntityId.HasValue) { using (DatastoreContext db = _createDatastore()) { var repository = new DatastoreRepository(db); var service = new MarkForRetryService(repository); service.UpdateAS4MessageForSendResult( messageId: ctx.MessageEntityId.Value, status: result); await db.SaveChangesAsync() .ConfigureAwait(false); } } if (ctx.AS4Message?.IsPullRequest == true) { using (DatastoreContext db = _createDatastore()) { var service = new PiggyBackingService(db); service.ResetSignalMessagesToBePiggyBacked(ctx.AS4Message.SignalMessages, result); await db.SaveChangesAsync() .ConfigureAwait(false); } } }
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); } } }
/// <summary> /// Execute the step on a given <paramref name="messagingContext"/>. /// </summary> /// <param name="messagingContext"><see cref="MessagingContext"/> on which the step must be executed.</param> /// <returns></returns> public async Task <StepResult> ExecuteAsync(MessagingContext messagingContext) { if (messagingContext == null) { throw new ArgumentNullException(nameof(messagingContext)); } if (messagingContext.AS4Message == null) { throw new InvalidOperationException( $"{nameof(BundleSignalMessageToPullRequestStep)} requires a AS4Message to possible bundle a " + "SignalMessage to the PullRequest but there's not a AS4Message present in the MessagingContext"); } if (messagingContext.SendingPMode == null) { throw new InvalidOperationException( $"{nameof(BundleSignalMessageToPullRequestStep)} requires a SendingPMode to select the right " + "SignalMessages for piggybacking but there's not a SendingPMode present in the MessagingContext"); } if (!(messagingContext.AS4Message.PrimaryMessageUnit is PullRequest pullRequest)) { throw new InvalidOperationException( $"{nameof(BundleSignalMessageToPullRequestStep)} requires a PullRequest as primary message unit in the " + "AS4Message but there's not a PullRequest present in the MessagingContext"); } using (DatastoreContext db = _createContext()) { var service = new PiggyBackingService(db); IEnumerable <SignalMessage> signals = await service.SelectToBePiggyBackedSignalMessagesAsync(pullRequest, messagingContext.SendingPMode, _bodyStore); foreach (SignalMessage signal in signals) { Logger.Info( $"PiggyBack the {signal.GetType().Name} \"{signal.MessageId}\" which reference " + $"UserMessage \"{signal.RefToMessageId}\" to the PullRequest"); messagingContext.AS4Message.AddMessageUnit(signal); } return(StepResult.Success(messagingContext)); } }
/// <summary> /// Handle the given <paramref name="response" />, but delegate to the next handler if you can't. /// </summary> /// <param name="response"></param> /// <returns></returns> public async Task <StepResult> HandleResponse(IAS4Response response) { if (response == null) { throw new ArgumentNullException(nameof(response)); } MessagingContext request = response.OriginalRequest; if (request?.AS4Message?.IsPullRequest == true) { bool pullRequestWasPiggyBacked = request.AS4Message.SignalMessages.Any(s => !(s is PullRequest)); if (pullRequestWasPiggyBacked) { using (DatastoreContext ctx = _createContext()) { SendResult result = response.StatusCode == HttpStatusCode.Accepted || response.StatusCode == HttpStatusCode.OK ? SendResult.Success : SendResult.RetryableFail; var service = new PiggyBackingService(ctx); service.ResetSignalMessagesToBePiggyBacked(request.AS4Message.SignalMessages, result); await ctx.SaveChangesAsync().ConfigureAwait(false); } } bool isEmptyChannelWarning = (response.ReceivedAS4Message?.FirstSignalMessage as Error)?.IsPullRequestWarning == true; if (isEmptyChannelWarning) { request.ModifyContext(response.ReceivedAS4Message, MessagingContextMode.Send); return(StepResult.Success(response.OriginalRequest).AndStopExecution()); } } return(await _nextHandler.HandleResponse(response)); }