Ejemplo n.º 1
0
        private static UserMessage CreateMultihopUserMessage(string receivePModeId, SendingProcessingMode pmode)
        {
            var collaboration =
                new Model.Core.CollaborationInfo(
                    new Model.Core.AgreementReference(
                        value: "http://agreements.europa.org/agreement",
                        pmodeId: receivePModeId),
                    service: new Model.Core.Service(
                        value: "Forward_Push_Service",
                        type: "eu:europa:services"),
                    action: "Forward_Push_Action",
                    conversationId: "eu:europe:conversation");

            IEnumerable <MessageProperty> properties =
                pmode.MessagePackaging?.MessageProperties?.Select(
                    p => new MessageProperty(p.Name, p.Value, p.Type)) ?? new MessageProperty[0];

            Party p1 = pmode.MessagePackaging?.PartyInfo.FromParty;
            Party p2 = pmode.MessagePackaging?.PartyInfo.ToParty;

            return(new UserMessage(
                       $"multihop-message-id-{Guid.NewGuid()}",
                       collaboration,
                       SendingPModeMap.ResolveSender(p1),
                       SendingPModeMap.ResolveSender(p2),
                       new Model.Core.PartInfo[0],
                       properties));
        }
Ejemplo n.º 2
0
        private static AS4Party ResolveSubmitOrPModeReceiverParty(
            SubmitParty submitParty,
            PModeParty pmodeParty,
            bool allowOverride)
        {
            if (allowOverride == false &&
                submitParty != null &&
                pmodeParty != null &&
                submitParty.Equals(pmodeParty) == false)
            {
                throw new NotSupportedException(
                          "SubmitMessage is not allowed by the SendingPMode to override ToParty");
            }

            if (submitParty == null && pmodeParty == null)
            {
                throw new InvalidOperationException(
                          "Either the SubmitMessage or the SendingPMode is required to have a " +
                          "ToParty configured for dynamic discovery in a non-Forwarding scenario");
            }

            if (submitParty != null)
            {
                Logger.Debug(
                    "Resolve ToParty in non-Forwarding scenario from SubmitMessage "
                    + "because SendingPMode allows overriding {AllowOverride = true}");

                return(CreateToPartyFrom(
                           "SubmitMessage",
                           submitParty.Role,
                           (submitParty.PartyIds ?? Enumerable.Empty <SubmitPartyId>())
                           .Select(p => new PartyId(p?.Id, p?.Type.AsMaybe()))));
            }

            if (pmodeParty?.PartyIds.Any() == false)
            {
                Logger.Error(
                    "Cannot retrieve SMP metadata because SendingPMode must contain at lease one "
                    + "<ToPartyId/> element in the MessagePackaging.PartyInfo.ToParty element");

                throw new ConfigurationErrorsException(
                          "Cannot retrieve SMP metadata because the message is referencing an incomplete SendingPMode");
            }

            Logger.Debug("Resolve ToParty in non-Forwarding scenario from SendingPMode because SubmitMessage has none");
            return(CreateToPartyFrom(
                       "SendingPMode",
                       pmodeParty.Role,
                       (pmodeParty.PartyIds ?? Enumerable.Empty <PModePartyId>())
                       .Select(p => new PartyId(p?.Id, p?.Type.AsMaybe()))));
        }
        private static void DifferentiatePartyInfo(ReceivePMode pmode)
        {
            const string fromId = "from-Id";
            const string toId   = "to-Id";

            var fromParty = new Party {
                Role = fromId, PartyIds = { new PartyId {
                                                Id = fromId
                                            } }
            };
            var toParty = new Party {
                Role = toId, PartyIds = { new PartyId {
                                              Id = toId
                                          } }
            };

            pmode.MessagePackaging.PartyInfo = new PartyInfo {
                FromParty = fromParty, ToParty = toParty
            };
        }
Ejemplo n.º 4
0
        private static (bool, AS4Party) ExerciseDynamicDiscovery(
            SubmitParty submitParty,
            PModeParty pmodeParty,
            bool allowOverride)
        {
            var context = new MessagingContext(
                new SubmitMessage
            {
                PartyInfo = { ToParty = submitParty }
            })
            {
                SendingPMode = new SendingProcessingMode
                {
                    AllowOverride    = allowOverride,
                    DynamicDiscovery = new DynamicDiscoveryConfiguration(),
                    MessagePackaging = { PartyInfo   = new PartyInfo {
                                             ToParty = pmodeParty
                                         } }
                }
            };

            try
            {
                var spy = new SpyToPartyDynamicDiscoveryProfile();
                var sut = new DynamicDiscoveryStep(_ => spy);
                sut.ExecuteAsync(context)
                .GetAwaiter()
                .GetResult();

                return(true, spy.ToParty);
            }
            catch
            {
                return(false, null);
            }
        }