/// <summary> /// Maps from a XML representation with an optional routing usermessage to a domain model representation of an AS4 receipt. /// </summary> /// <param name="xml">The XML representation to convert.</param> /// <param name="routingM">The optional routing usermessage element to include in the to be created receipt.</param> public static Receipt Convert(Xml.SignalMessage xml, Maybe <RoutingInputUserMessage> routingM) { if (xml == null) { throw new ArgumentNullException(nameof(xml)); } if (routingM == null) { throw new ArgumentNullException(nameof(routingM)); } if (xml.Receipt == null) { throw new ArgumentException( @"Cannot create Receipt domain model from a XML representation without a Receipt element", nameof(xml.Receipt)); } string messageId = xml.MessageInfo?.MessageId; string refToMessageId = xml.MessageInfo?.RefToMessageId; DateTimeOffset timestamp = xml.MessageInfo?.Timestamp.ToDateTimeOffset() ?? DateTimeOffset.Now; Maybe <NonRepudiationInformation> nriM = GetNonRepudiationFromXml(xml.Receipt); Maybe <UserMessage> userM = GetUserMessageFromXml(xml.Receipt); Maybe <Receipt> routingNriReceiptM = routingM.Zip(nriM, (routing, nri) => new Receipt(messageId, refToMessageId, timestamp, nri, routing)); Maybe <Receipt> routingUserReceiptM = routingM.Zip(userM, (routing, user) => new Receipt(messageId, refToMessageId, timestamp, user, routing)); Maybe <Receipt> routingReceipt = routingM.Select(routing => new Receipt(messageId, refToMessageId, timestamp, includedUserMessage: null, routedUserMessage: routing)); Maybe <Receipt> nriReceipt = nriM.Select(nri => new Receipt(messageId, refToMessageId, timestamp, nri, routedUserMessage: null)); Maybe <Receipt> userReceipt = userM.Select(user => new Receipt(messageId, refToMessageId, timestamp, user, routedUserMessage: null)); return(routingNriReceiptM .OrElse(routingUserReceiptM) .OrElse(routingReceipt) .OrElse(nriReceipt) .OrElse(userReceipt) .GetOrElse(() => new Receipt(messageId, refToMessageId, timestamp, includedUserMessage: null, routedUserMessage: null))); }
/// <summary> /// Maps from a XML representation to a domain model representation of an AS4 pull request. /// </summary> /// <param name="xml">The XML representation to convert.</param> internal static Model.Core.PullRequest Convert(Xml.SignalMessage xml) { if (xml == null) { throw new ArgumentNullException(nameof(xml)); } if (xml.PullRequest == null) { throw new ArgumentException( @"Cannot create PullRequest domain model from a XML representation without a PullRequest element", nameof(xml.PullRequest)); } return(new Model.Core.PullRequest(xml.MessageInfo?.MessageId, xml.PullRequest?.mpc)); }