private SmpConfiguration FindSmpResponseForToParty(Model.Core.Party party) { using (DatastoreContext context = _createDatastore()) { string primaryPartyType = party.PartyIds .FirstOrNothing() .SelectMany(x => x.Type) .GetOrElse(() => null); SmpConfiguration foundConfiguration = context.SmpConfigurations .FirstOrDefault( sc => sc.PartyRole == party.Role && sc.ToPartyId == party.PrimaryPartyId && sc.PartyType == primaryPartyType); if (foundConfiguration == null) { throw new ConfigurationErrorsException( "No SMP Response found for the given " + $"'Role': {party.Role}, 'PartyId': {party.PrimaryPartyId}, and 'PartyType': {primaryPartyType}"); } return(foundConfiguration); } }
/// <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) { if (party == null) { throw new ArgumentNullException(nameof(party)); } if (party.PrimaryPartyId == null || party.PartyIds.FirstOrDefault()?.Type == null || party.Role == null) { throw new InvalidOperationException( "Given invalid 'ToParty', requires 'Role', 'PartyId', and 'PartyType'"); } SmpConfiguration configuration = FindSmpResponseForToParty(party); string xml = AS4XmlSerializer.ToString(configuration); var document = new XmlDocument(); document.LoadXml(xml); return(Task.FromResult(document)); }