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);
                }
            }
        }
Esempio n. 2
0
        /// <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));
        }
        /// <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(SetMessageToBeSentStep)} requires an AS4Message to mark for sending but no AS4Message is present in the MessagingContext");
            }

            Logger.Trace($"{messagingContext.LogTag} Set the message's Operation=ToBeSent");
            if (messagingContext.MessageEntityId == null)
            {
                throw new InvalidOperationException(
                          $"{messagingContext.LogTag} MessagingContext does not contain the ID of the OutMessage that must be set to ToBeSent");
            }

            using (DatastoreContext context = _createContext())
            {
                var repository = new DatastoreRepository(context);
                var service    = new OutMessageService(repository, _messageStore);

                service.UpdateAS4MessageToBeSent(
                    messagingContext.MessageEntityId.Value,
                    messagingContext.AS4Message,
                    messagingContext.SendingPMode?.Reliability?.ReceptionAwareness);

                await context.SaveChangesAsync().ConfigureAwait(false);
            }

            return(StepResult.Success(messagingContext));
        }
Esempio n. 4
0
        private async Task <IEnumerable <AS4Message> > GetReferencedUserMessagesAsync(IEnumerable <Receipt> receipts)
        {
            using (DatastoreContext context = _storeExpression())
            {
                var service = new OutMessageService(
                    repository: new DatastoreRepository(context),
                    messageBodyStore: _bodyStore);

                return(await service.GetNonIntermediaryAS4UserMessagesForIds(
                           receipts.Select(r => r.RefToMessageId)));
            }
        }