/// <summary>
        /// Transform a given <see cref="ReceivedMessage"/> to a Canonical <see cref="MessagingContext"/> instance.
        /// </summary>
        /// <param name="message">Given message to transform.</param>
        /// <returns></returns>
        public async Task <MessagingContext> TransformAsync(ReceivedMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            var transformer = new AS4MessageTransformer();
            MessagingContext sendContext = await transformer.TransformAsync(message);

            return(new MessagingContext(
                       sendContext.AS4Message,
                       sendContext.ReceivedMessage,
                       MessagingContextMode.Forward));
        }
예제 #2
0
        /// <summary>
        /// Transform a given <see cref="ReceivedMessage"/> to a Canonical <see cref="MessagingContext"/> instance.
        /// </summary>
        /// <param name="message">Given message to transform.</param>
        /// <returns></returns>
        public async Task <MessagingContext> TransformAsync(ReceivedMessage message)
        {
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            if (!(message is ReceivedEntityMessage receivedMessage))
            {
                throw new NotSupportedException(
                          $"Incoming message stream from {message.Origin} that must be transformed should be of type {nameof(ReceivedEntityMessage)}");
            }

            if (receivedMessage.Entity is ExceptionEntity ex)
            {
                string ebmsMessageId = IdentifierFactory.Instance.Create();
                Error  error         = Error.FromErrorResult(
                    ebmsMessageId,
                    ex.EbmsRefToMessageId,
                    new ErrorResult(ex.Exception, ErrorAlias.Other));

                NotifyMessageEnvelope notifyEnvelope =
                    await CreateNotifyMessageEnvelopeAsync(AS4Message.Create(error), ebmsMessageId, ex.GetType());

                return(new MessagingContext(notifyEnvelope, receivedMessage));
            }

            if (receivedMessage.Entity is MessageEntity me)
            {
                var as4Transformer   = new AS4MessageTransformer();
                MessagingContext ctx = await as4Transformer.TransformAsync(receivedMessage);

                // Normally the message shouldn't have any attachments
                // but to be sure we should dispose them since we don't need attachments for notifying.
                ctx.AS4Message.CloseAttachments();

                NotifyMessageEnvelope notifyEnvelope =
                    await CreateNotifyMessageEnvelopeAsync(ctx.AS4Message, me.EbmsMessageId, me.GetType());

                ctx.ModifyContext(notifyEnvelope, receivedMessage.Entity.Id);

                return(ctx);
            }

            throw new InvalidOperationException();
        }
        /// <summary>
        /// Transform a given <see cref="ReceivedMessage"/> to a Canonical <see cref="MessagingContext"/> instance.
        /// </summary>
        /// <param name="message">Given message to transform.</param>
        /// <returns></returns>
        public async Task <MessagingContext> TransformAsync(ReceivedMessage message)
        {
            var receivedEntityMessage = message as ReceivedEntityMessage;

            if (receivedEntityMessage == null)
            {
                throw new NotSupportedException(
                          $"Minder Notify Transformer only supports transforming instances of type {typeof(ReceivedEntityMessage)}");
            }

            var as4Transformer       = new AS4MessageTransformer();
            MessagingContext context = await as4Transformer.TransformAsync(message);

            NotifyMessageEnvelope notifyMessage =
                await CreateNotifyMessageEnvelope(
                    context.AS4Message,
                    context.AS4Message.GetPrimaryMessageId(),
                    receivedEntityMessage.Entity.GetType());

            context.ModifyContext(notifyMessage);

            return(context);
        }