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);
            }
        }
Ejemplo n.º 3
0
        private async Task TestExecutionException(
            Operation expected,
            MessagingContext context,
            Func <IAgentExceptionHandler, Func <Exception, MessagingContext, Task <MessagingContext> > > getExercise)
        {
            // Arrange
            var inMessage = new InMessage(ebmsMessageId: _expectedId);

            inMessage.SetStatus(InStatus.Received);

            GetDataStoreContext.InsertInMessage(inMessage);

            IAgentExceptionHandler sut = CreateInboundExceptionHandler();
            var exercise = getExercise(sut);

            // Act
            await exercise(new Exception(), context);

            // Assert
            GetDataStoreContext.AssertInMessage(_expectedId, m => Assert.Equal(InStatus.Exception, m.Status.ToEnum <InStatus>()));
            GetDataStoreContext.AssertInException(
                _expectedId,
                ex =>
            {
                Assert.Equal(expected, ex.Operation);
                Assert.Null(ex.MessageLocation);
            });
        }
        public async Task InMessageStatusIsCorrectlyPersisted()
        {
            long savedInMessageId;

            using (var db = this.GetDataStoreContext())
            {
                var inMessage = new InMessage(Guid.NewGuid().ToString());
                inMessage.SetStatus(InStatus.Notified);

                db.InMessages.Add(inMessage);

                await db.SaveChangesAsync();

                savedInMessageId = inMessage.Id;

                Assert.NotEqual(default(long), savedInMessageId);
            }

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

                Assert.NotNull(inMessage);
                Assert.Equal(InStatus.Notified, inMessage.Status.ToEnum <InStatus>());
            }
        }
        private static InMessage CreateInMessage(string id, InStatus status, Operation operation)
        {
            var m = new InMessage(id);

            m.SetStatus(status);
            m.Operation = operation;

            return(m);
        }
Ejemplo n.º 6
0
        private InMessage InsertInMessage(string id)
        {
            var inMsg = new InMessage(id);

            inMsg.SetStatus(InStatus.Received);
            inMsg.Operation = Operation.Delivering;

            return(GetDataStoreContext.InsertInMessage(inMsg));
        }
        private static InMessage CreateInMessageFor(AS4Message receiptMessage)
        {
            var inMessage = new InMessage(receiptMessage.FirstSignalMessage.MessageId)
            {
                ContentType        = Constants.ContentTypes.Soap,
                EbmsRefToMessageId = receiptMessage.FirstSignalMessage.RefToMessageId
            };

            inMessage.SetStatus(InStatus.Received);
            inMessage.Operation       = Operation.ToBeNotified;
            inMessage.EbmsMessageType = MessageType.Receipt;

            return(inMessage);
        }
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();
            }
        }