private UserMessage CreateUserMessageFromMinderProperties(UserMessage userMessage, SignalMessage signalMessage)
        {
            var receiver =
                new Model.Core.Party(
                    role: $"{MinderUriPrefix}/testdriver",
                    partyId: new Model.Core.PartyId(id: "minder"));

            var collaboration = new CollaborationInfo(
                Maybe <AgreementReference> .Nothing,
                new Service(MinderUriPrefix),
                "Notify",
                CollaborationInfo.DefaultConversationId);

            IEnumerable <MessageProperty> props =
                signalMessage != null
                    ? new[]
            {
                new MessageProperty("RefToMessageId", signalMessage.RefToMessageId),
                new MessageProperty("SignalType", signalMessage.GetType().Name)
            }
                    : Enumerable.Empty <MessageProperty>();

            return(new UserMessage(
                       messageId: userMessage.MessageId,
                       refToMessageId: signalMessage != null ? signalMessage.RefToMessageId : userMessage.RefToMessageId,
                       mpc: userMessage.Mpc,
                       timestamp: DateTimeOffset.Now,
                       collaboration: collaboration,
                       sender: userMessage.Sender,
                       receiver: receiver,
                       partInfos: userMessage.PayloadInfo,
                       messageProperties: userMessage.MessageProperties.Concat(props)));
        }
        private static bool ArePartyIdsEqual(
            Model.PMode.Party pmodeParty,
            Model.Core.Party messageParty)
        {
            if (pmodeParty == null)
            {
                return(false);
            }

            return(messageParty.PartyIds.All(userPartyId => pmodeParty.PartyIds.Any(pmodePartyId =>
            {
                bool noType =
                    userPartyId.Type == Maybe <string> .Nothing &&
                    pmodePartyId?.Type == null;

                bool equalType =
                    userPartyId
                    .Type
                    .Select(t => StringComparer.OrdinalIgnoreCase.Equals(t, pmodePartyId?.Type))
                    .GetOrElse(false);

                bool equalId =
                    StringComparer
                    .OrdinalIgnoreCase
                    .Equals(userPartyId.Id, pmodePartyId?.Id);

                return equalId && (equalType || noType);
            })));
        }
        private static Xml.PartyInfo MapPartyInfo(Model.Core.Party sender, Model.Core.Party receiver)
        {
            Xml.PartyId[] MapPartyIds(IEnumerable <Model.Core.PartyId> ids)
            {
                if (!ids.Any())
                {
                    return(null);
                }

                return(ids.Select(i => new Xml.PartyId
                {
                    Value = i.Id,
                    type = i.Type.GetOrElse(() => null)
                }).ToArray());
            }

            return(new Xml.PartyInfo
            {
                From = new Xml.From
                {
                    Role = sender.Role,
                    PartyId = MapPartyIds(sender.PartyIds)
                },
                To = new Xml.To
                {
                    Role = receiver.Role,
                    PartyId = MapPartyIds(receiver.PartyIds)
                }
            });
        }
 private static Model.Common.Party CreateDeliverParty(Model.Core.Party p)
 {
     return(new Model.Common.Party
     {
         Role = p.Role,
         PartyIds = p.PartyIds.Select(id => new Model.Common.PartyId(id.Id, id.Type.GetOrElse(() => null))).ToArray()
     });
 }
        private static Uri CreateSmpServerUrl(Model.Core.Party party, ESensConfig config)
        {
            string hashedPartyId = CalculateMD5Hash(party.PrimaryPartyId);

            string host = $"b-{hashedPartyId}.{config.SmlScheme}.{config.SmpServerDomainName}";
            string path = $"{config.SmlScheme}::{party.PrimaryPartyId}/services/{DocumentIdentifierScheme}::{DocumentIdentifier}";


            var builder = new UriBuilder
            {
                Host = host,
                // DotNetBug: Colons need to be Percentage encoded in final Url for SMP lookup.
                // Uri/HttpClient.GetAsync components encodes # but not : so we need to do it manually.
                Path = HttpUtility.UrlEncode(path)
            };

            return(builder.Uri);
        }
        /// <summary>
        /// Retrieves the SMP meta data <see cref="XmlDocument"/> for a given <paramref name="party"/> using a given <paramref name="properties"/>.
        /// </summary>
        /// <param name="party">The party identifier to select the right SMP meta-data.</param>
        /// <param name="properties">The information properties specified in the <see cref="SendingProcessingMode"/> for this profile.</param>
        public async Task <XmlDocument> RetrieveSmpMetaDataAsync(
            Model.Core.Party party,
            IDictionary <string, string> properties)
        {
            if (party == null)
            {
                throw new ArgumentNullException(nameof(party));
            }

            if (properties == null)
            {
                throw new ArgumentNullException(nameof(properties));
            }

            if (party.PrimaryPartyId == null)
            {
                throw new InvalidOperationException("Given invalid 'ToParty'; requires a 'PartyId'");
            }

            Uri smpUrl = CreateSmpServerUrl(party, ESensConfig.From(properties));

            return(await RetrieveSmpMetaData(smpUrl));
        }
Exemple #7
0
 /// <summary>
 /// Retrieves the SMP meta data <see cref="XmlDocument"/> for a given <paramref name="party"/> using a given <paramref name="properties"/>.
 /// </summary>
 /// <param name="party">The party identifier to select the right SMP meta-data.</param>
 /// <param name="properties">The information properties specified in the <see cref="SendingProcessingMode"/> for this profile.</param>
 public Task <XmlDocument> RetrieveSmpMetaDataAsync(Model.Core.Party party, IDictionary <string, string> properties)
 {
     return(PeppolDynamicDiscoveryProfile.RetrieveSmpMetaDataAsync(party, properties));
 }