Ejemplo n.º 1
0
        /// <summary>
        /// Creates an <see cref="UserMessage"/> entirely from the given <paramref name="sendingPMode"/> information.
        /// </summary>
        /// <param name="sendingPMode">
        ///     The pmode from which the values in the <see cref="Model.PMode.SendingProcessingMode.MessagePackaging"/> will be used to create an <see cref="UserMessage"/>.
        /// </param>
        /// <param name="parts">The optional list of part references for attachments in the <see cref="AS4Message"/>.</param>
        internal static UserMessage CreateUserMessage(Model.PMode.SendingProcessingMode sendingPMode, params PartInfo[] parts)
        {
            if (sendingPMode == null)
            {
                throw new ArgumentNullException(nameof(sendingPMode));
            }

            IEnumerable <MessageProperty> properties =
                sendingPMode.MessagePackaging
                ?.MessageProperties
                ?.Where(p => p != null)
                .Select(p => new MessageProperty(p.Name, p.Value, p.Type))
                .ToArray() ?? Enumerable.Empty <MessageProperty>();

            return(new UserMessage(
                       IdentifierFactory.Instance.Create(),
                       sendingPMode.MessagePackaging?.Mpc,
                       new CollaborationInfo(
                           ResolveAgreementReference(sendingPMode),
                           ResolveService(sendingPMode),
                           ResolveAction(sendingPMode),
                           CollaborationInfo.DefaultConversationId),
                       ResolveSender(sendingPMode.MessagePackaging?.PartyInfo?.FromParty),
                       ResolveReceiver(sendingPMode.MessagePackaging?.PartyInfo?.ToParty),
                       parts ?? Enumerable.Empty <PartInfo>(),
                       properties));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Resolves the <see cref="AgreementReference"/> from the <see cref="Model.PMode.SendingProcessingMode.MessagePackaging"/> element.
        /// </summary>
        /// <param name="pmode">The pmode to retrieve the agreement reference from.</param>
        internal static Maybe <AgreementReference> ResolveAgreementReference(Model.PMode.SendingProcessingMode pmode)
        {
            var pmodeAgreement =
                pmode?.MessagePackaging
                ?.CollaborationInfo
                ?.AgreementReference;

            string value = pmodeAgreement?.Value;

            if (value == null)
            {
                return(Maybe <AgreementReference> .Nothing);
            }

            Maybe <string> type =
                (pmodeAgreement.Type != null)
                .ThenMaybe(pmodeAgreement.Type);

            Maybe <string> pmodeId =
                (pmodeAgreement.PModeId != null)
                .ThenMaybe(pmodeAgreement.PModeId)
                .Where(_ => pmode.MessagePackaging.IncludePModeId);

            return(Maybe.Just(new AgreementReference(value, type, pmodeId)));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Resolves the Action from the  <see cref="Model.PMode.SendingProcessingMode.MessagePackaging"/> element.
        /// </summary>
        /// <param name="pmode">The pmode to retrieve the action from.</param>
        internal static string ResolveAction(Model.PMode.SendingProcessingMode pmode)
        {
            var pmodeCollaboration = pmode?.MessagePackaging?.CollaborationInfo;

            if (String.IsNullOrEmpty(pmodeCollaboration?.Action))
            {
                return(Constants.Namespaces.TestAction);
            }

            return(pmodeCollaboration.Action);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Resolves the <see cref="Service"/> from the <see cref="Model.PMode.SendingProcessingMode.MessagePackaging"/> element.
        /// </summary>
        /// <param name="pmode">The pmode to retrieve the service from.</param>
        internal static Service ResolveService(Model.PMode.SendingProcessingMode pmode)
        {
            if (pmode?.MessagePackaging?.CollaborationInfo?.Service != null)
            {
                var pmodeService = pmode.MessagePackaging.CollaborationInfo.Service;
                if (String.IsNullOrEmpty(pmodeService.Value))
                {
                    return(Service.TestService);
                }

                if (pmodeService.Type == null)
                {
                    return(new Service(pmodeService.Value));
                }

                return(new Service(pmodeService.Value, pmodeService.Type));
            }

            return(Service.TestService);
        }