/// <summary>
        /// Sets retry properties on a pipeline message.
        /// </summary>
        /// <param name="message">The pipeline message.</param>
        /// <param name="directive">The resolver directive.</param>
        /// <returns>A pipeline message with retry properties.</returns>
        public static IBaseMessage SetRetryProperties(this IBaseMessage message, Directive directive)
        {
            // If retry level is other than level zero, do not process further.
            if (directive.RetryLevel != 0)
            {
                return(message);
            }

            // [fvar] RetryCount BizTalk property.
            var retryCount = ExtensionMethodsGeneral.AsCachedVar(() => new RetryCount());

            // [fvar] RetryInterval BizTalk property.
            var retryInterval = ExtensionMethodsGeneral.AsCachedVar(() => new RetryInterval());

            // [fvar] Message with retry count property set, as required.
            Func <IBaseMessage> messageWithRetryCountProp =
                () =>
                directive.RetryCount > 0
                          ? message.SetProperty(
                    retryCount().Name.Name,
                    retryCount().Name.Namespace,
                    directive.RetryCount)
                          : message;

            // Return message with retry count and retry interval properties set, as required.
            return(directive.RetryInterval > 0
                       ? messageWithRetryCountProp().SetProperty(
                       retryInterval().Name.Name,
                       retryInterval().Name.Namespace,
                       directive.RetryInterval)
                       : messageWithRetryCountProp());
        }
        /// <summary>
        /// Set the transport type and location properties on a pipeline message.
        /// </summary>
        /// <param name="message">The pipeline message.</param>
        /// <param name="directive">the resolver directive.</param>
        /// <returns>The pipeline message with transport type and location properties.</returns>
        public static IBaseMessage SetDynamicPortProperties(this IBaseMessage message, Directive directive)
        {
            // [fvar] The outbound transport type BizTalk property.
            var outboundTransportType = ExtensionMethodsGeneral.AsCachedVar(() => new OutboundTransportType());

            // [fvar] The outbound transport location BizTalk property.
            var outboundTransportLocation = ExtensionMethodsGeneral.AsCachedVar(() => new OutboundTransportLocation());

            // [fvar] The message with the dynamic port TransportType property, as required.
            Func <IBaseMessage> messageWithOutboundTransportProperty =
                () =>
                !string.IsNullOrEmpty(directive.TransportType)
                    ? message.SetProperty(
                    outboundTransportType().Name.Name,
                    outboundTransportType().Name.Namespace,
                    directive.TransportType)
                    : message;

            // Return the message with the dynamic port TransportType and TransportLocation properties, as required.
            return(!string.IsNullOrEmpty(directive.EndPoint)
                       ? messageWithOutboundTransportProperty().SetProperty(
                       outboundTransportLocation().Name.Name,
                       outboundTransportLocation().Name.Namespace,
                       directive.EndPoint)
                       : messageWithOutboundTransportProperty());
        }
        /// <summary>
        /// Sets the SOAP action property on the message.  Sets properties for legacy
        /// SOAP adapter, WSE adapter and WCF adapter.
        /// </summary>
        /// <param name="message">The pipeline message.</param>
        /// <param name="directive">The resolver directive.</param>
        /// <returns>The pipeline message with SOAP action properties set.</returns>
        public static IBaseMessage SetSoapAction(this IBaseMessage message, Directive directive)
        {
            // [fvar] The cached BizTalk legacy SOAP adapter Action property.
            var btsSoapAction = ExtensionMethodsGeneral.AsCachedVar(() => new SOAPAction());

            // [fvar] The cached BizTalk legacy WSE adapter Action property
            var wcfSoapAction = ExtensionMethodsGeneral.AsCachedVar(() => new Action());

            // Return the message with the legacy SOAP, legacy WSE 2.0 and WCF adapter SOAP action properties.
            return(string.IsNullOrEmpty(directive.SoapAction)
                ? message
                : message.SetProperty(btsSoapAction().Name.Name, btsSoapAction().Name.Namespace, directive.SoapAction)
                   .SetProperty("SoapAction", Resources.UriWseProperties, directive.SoapAction)
                   .SetProperty(wcfSoapAction().Name.Name, wcfSoapAction().Name.Namespace, directive.SoapAction));
        }