Ejemplo n.º 1
0
        /// <summary>
        /// Prepare <see cref="InMessage"/> as a message that has yet to be determined what it's endpoint will be.
        /// This is used for (quick) saving the incoming message but process the message on a later time.
        /// </summary>
        /// <returns></returns>
        public InMessage BuildAsToBeProcessed()
        {
            if (_messageUnit == null)
            {
                throw new InvalidDataException("Builder needs a Message Unit for building an InMessage");
            }

            var inMessage = new InMessage(_messageUnit.MessageId)
            {
                EbmsRefToMessageId = _messageUnit.RefToMessageId,
                ContentType        = _contentType,
                InsertionTime      = DateTimeOffset.Now,
                ModificationTime   = DateTimeOffset.Now,
                MessageLocation    = _location,
                EbmsMessageType    = DetermineMessageType(_messageUnit),
                MEP       = _mep,
                Operation = Operation.NotApplicable
            };

            inMessage.SetPModeInformation(_pmode);
            inMessage.SetStatus(InStatus.Received);
            inMessage.AssignAS4Properties(_messageUnit);

            return(inMessage);
        }
Ejemplo n.º 2
0
        private void InsertToBeForwardedInMessage(string pmodeId, MessageExchangePattern mep, AS4Message tobeForwarded)
        {
            foreach (MessageUnit m in tobeForwarded.MessageUnits)
            {
                string location =
                    Registry.Instance
                    .MessageBodyStore
                    .SaveAS4Message(
                        _as4Msh.GetConfiguration().InMessageStoreLocation,
                        tobeForwarded);

                var inMessage = new InMessage(m.MessageId)
                {
                    Intermediary = true,
                    Operation    =
                        m.MessageId == tobeForwarded.PrimaryMessageUnit.MessageId
                            ? Operation.ToBeForwarded
                            : Operation.NotApplicable,
                    MessageLocation = location,
                    MEP             = mep,
                    ContentType     = tobeForwarded.ContentType
                };

                ReceivingProcessingMode forwardPMode =
                    _as4Msh.GetConfiguration()
                    .GetReceivingPModes()
                    .First(p => p.Id == pmodeId);

                inMessage.SetPModeInformation(forwardPMode);
                inMessage.SetStatus(InStatus.Received);
                inMessage.AssignAS4Properties(m);
                _databaseSpy.InsertInMessage(inMessage);
            }
        }
            public async Task PModeInformationIsCorrectlyRetrieved()
            {
                const string messageId = "messageId";
                const string pmodeId   = "TestPModeId";

                using (var db = GetDataStoreContext())
                {
                    var inMessage = new InMessage(messageId)
                    {
                        MessageLocation = "test"
                    };
                    inMessage.SetPModeInformation(new SendingProcessingMode()
                    {
                        Id = pmodeId
                    });

                    db.InMessages.Add(inMessage);

                    await db.SaveChangesAsync();
                }

                using (var db = GetDataStoreContext())
                {
                    var inMessage = db.InMessages.FirstOrDefault(m => m.EbmsMessageId == messageId);
                    Assert.NotNull(inMessage);
                    Assert.False(String.IsNullOrWhiteSpace(inMessage.PModeId));
                    Assert.False(String.IsNullOrWhiteSpace(inMessage.PMode));
                }
            }
        public async Task PModeInformationIsCorrectlyPersisted()
        {
            long savedId;

            const string pmodeId      = "pmodeId";
            const string pmodeContent = "<pmode><id>pmodeId</id></pmode>";

            using (var db = GetDataStoreContext())
            {
                var message = new InMessage("some-message-id");
                message.SetPModeInformation(pmodeId, pmodeContent);

                db.InMessages.Add(message);

                await db.SaveChangesAsync();

                savedId = message.Id;
            }

            using (var db = this.GetDataStoreContext())
            {
                var message = db.InMessages.FirstOrDefault(i => i.Id == savedId);

                Assert.NotNull(message);
                Assert.Equal(pmodeId, message.PModeId);
                Assert.Equal(pmodeContent, message.PMode);
            }
        }
Ejemplo n.º 5
0
        private static async Task <MessagingContext> PrepareAS4MessageForDeliveryAsync(AS4Message msg, ReceivingProcessingMode pmode)
        {
            var transformer = new DeliverMessageTransformer();

            var entity = new InMessage(msg.GetPrimaryMessageId());

            entity.SetPModeInformation(pmode);

            return(await transformer.TransformAsync(new ReceivedEntityMessage(entity, msg.ToStream(), msg.ContentType)));
        }
Ejemplo n.º 6
0
        private static InMessage CreateInMessageRepresentingUserMessage(
            string ebmsMessageId,
            AS4Message as4Message,
            IPMode pmode)
        {
            var inMessage = new InMessage(ebmsMessageId)
            {
                ContentType     = as4Message.ContentType,
                EbmsMessageType = MessageType.UserMessage,
                MEP             = MessageExchangePattern.Push,
                Operation       = Operation.ToBeDelivered,
                MessageLocation =
                    Registry.Instance
                    .MessageBodyStore
                    .SaveAS4Message(@"file:///.\database\as4messages\in", as4Message)
            };

            inMessage.SetPModeInformation(pmode);
            return(inMessage);
        }
Ejemplo n.º 7
0
        public async Task Create_DeliverMessages_From_UserMessages()
        {
            // Arrange
            string partId1      = $"part-{Guid.NewGuid()}";
            var    userMessage1 = new UserMessage(
                $"user-{Guid.NewGuid()}",
                new CollaborationInfo(
                    new Service($"service-{Guid.NewGuid()}"),
                    $"action-{Guid.NewGuid()}"),
                new Party("Sender", new PartyId($"id-{Guid.NewGuid()}")),
                new Party("Receiver", new PartyId($"id-{Guid.NewGuid()}")),
                new[] { new PartInfo($"cid:{partId1}") },
                new MessageProperty[0]);

            string partId2      = $"part-{Guid.NewGuid()}";
            var    userMessage2 = new UserMessage(
                $"user-{Guid.NewGuid()}",
                new CollaborationInfo(
                    new Service($"service-{Guid.NewGuid()}"),
                    $"action-{Guid.NewGuid()}"),
                new Party("Sender", new PartyId($"id-{Guid.NewGuid()}")),
                new Party("Receiver", new PartyId($"id-{Guid.NewGuid()}")),
                new[] { new PartInfo($"cid:{partId2}") },
                new MessageProperty[0]);

            AS4Message as4Message = AS4Message.Create(new [] { userMessage1, userMessage2 });

            as4Message.AddAttachment(new Attachment(partId1));
            as4Message.AddAttachment(new Attachment(partId2));

            var receivingPMode = new ReceivingProcessingMode {
                Id = "deliver-pmode"
            };
            var entity1 = new InMessage(userMessage1.MessageId);

            entity1.SetPModeInformation(receivingPMode);
            var entity2 = new InMessage(userMessage2.MessageId);

            entity2.SetPModeInformation(receivingPMode);

            var sut = new DeliverMessageTransformer();

            // Act
            MessagingContext result1 =
                await sut.TransformAsync(new ReceivedEntityMessage(entity1, as4Message.ToStream(), as4Message.ContentType));

            MessagingContext result2 =
                await sut.TransformAsync(new ReceivedEntityMessage(entity2, as4Message.ToStream(), as4Message.ContentType));

            // Assert
            IEnumerable <string> mappingFailures1 =
                DeliverMessageOriginateFrom(
                    userMessage1,
                    receivingPMode,
                    result1.DeliverMessage.Message);

            Assert.Empty(mappingFailures1);

            IEnumerable <string> mappingFailures2 =
                DeliverMessageOriginateFrom(
                    userMessage2,
                    receivingPMode,
                    result2.DeliverMessage.Message);

            Assert.Empty(mappingFailures2);
        }
Ejemplo n.º 8
0
        protected virtual void SetupDataStore()
        {
            using (datastoreContext = new DatastoreContext(options, StubConfig.Default))
            {
                string pmodeString = AS4XmlSerializer.ToString(pmode);
                string pmodeId     = pmode.Id;

                {
                    var message = new InMessage(ebmsMessageId: InEbmsMessageId1)
                    {
                        EbmsRefToMessageId = InEbmsRefToMessageId1,
                        InsertionTime      = DateTime.UtcNow.AddMinutes(-1),
                    };
                    message.SetStatus(InStatus.Created);
                    message.SetPModeInformation(pmodeId, pmodeString);
                    datastoreContext.InMessages.Add(message);
                }

                {
                    var message = new InMessage(ebmsMessageId: InEbmsMessageId2)
                    {
                        EbmsRefToMessageId = InEbmsRefToMessageId2,
                        InsertionTime      = DateTime.UtcNow.AddMinutes(-1)
                    };
                    message.SetStatus(InStatus.Received);
                    datastoreContext.InMessages.Add(message);
                }

                {
                    var message = new OutMessage(OutEbmsMessageId1)
                    {
                        EbmsRefToMessageId = OutEbmsRefToMessageId1,
                        InsertionTime      = DateTime.UtcNow.AddMinutes(-1)
                    };
                    message.SetStatus(OutStatus.Created);

                    datastoreContext.OutMessages.Add(message);
                }

                {
                    var message = new OutMessage(OutEbmsMessageId2)
                    {
                        EbmsRefToMessageId = OutEbmsRefToMessageId2,

                        InsertionTime = DateTime.UtcNow.AddMinutes(-1)
                    };
                    message.SetStatus(OutStatus.Created);
                    datastoreContext.OutMessages.Add(message);
                }

                InException inEx1 = Entities.InException.ForEbmsMessageId(InEbmsMessageId1, InException);
                inEx1.InsertionTime = DateTime.UtcNow.AddMinutes(-1);
                datastoreContext.InExceptions.Add(inEx1);

                InException inEx2 = Entities.InException.ForEbmsMessageId(InEbmsMessageId1, InException);
                inEx2.InsertionTime = DateTime.UtcNow.AddMinutes(-1);
                datastoreContext.InExceptions.Add(inEx2);

                InException inEx3 = Entities.InException.ForMessageBody(MessageLocation, InException);
                inEx3.InsertionTime = DateTime.UtcNow.AddMinutes(-1);
                datastoreContext.InExceptions.Add(inEx3);

                OutException outEx1 = Entities.OutException.ForEbmsMessageId(OutEbmsRefToMessageId1, InException);
                outEx1.InsertionTime = DateTime.UtcNow.AddMinutes(-1);
                datastoreContext.OutExceptions.Add(outEx1);

                OutException outEx2 = OutException.ForEbmsMessageId(InEbmsRefToMessageId1, Exception);
                outEx2.InsertionTime = DateTime.UtcNow.AddMinutes(-1);
                datastoreContext.OutExceptions.Add(outEx2);

                OutException outEx3 = OutException.ForMessageBody(MessageLocation, Exception);
                outEx3.InsertionTime = DateTime.UtcNow.AddMinutes(-1);
                datastoreContext.OutExceptions.Add(outEx3);

                datastoreContext.SaveChanges();

                foreach (var inMessage in datastoreContext.InMessages)
                {
                    inMessage.SetPModeInformation(pmodeId, pmodeString);
                }

                foreach (var outMessage in datastoreContext.OutMessages)
                {
                    outMessage.SetPModeInformation(pmodeId, pmodeString);
                }

                foreach (var inException in datastoreContext.InExceptions)
                {
                    inException.SetPModeInformation(pmodeId, pmodeString);
                }

                foreach (var outException in datastoreContext.OutExceptions)
                {
                    outException.SetPModeInformation(pmodeId, pmodeString);
                }

                datastoreContext.SaveChanges();
            }
        }