예제 #1
0
        /// <summary>
        /// Adds a <see cref="ValidatingSender"/> decorator that ensures messages are valid
        /// CloudEvents.
        /// <para>
        /// The <typeparamref name="TCloudEvent"/> type <em>must</em> define a public static method
        /// named "Validate" with the exact parameters <c>(<see cref="SenderMessage"/>, <see cref=
        /// "IProtocolBinding"/>)</c>. A <see cref="MissingMemberException"/> is immediately thrown if
        /// the class does not define such a method.
        ///  </para>
        /// </summary>
        /// <typeparam name="TCloudEvent">The type of CloudEvent used to apply validation.</typeparam>
        /// <param name="builder">The <see cref="ISenderBuilder"/>.</param>
        /// <param name="protocolBinding">
        /// The <see cref="IProtocolBinding"/> used to map CloudEvent attributes to <see cref="SenderMessage"/>
        /// headers.
        /// </param>
        /// <returns>The same <see cref="ISenderBuilder"/>.</returns>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="builder"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="MissingMemberException">
        /// If the <typeparamref name="TCloudEvent"/> class does not define a public static method
        /// named "Validate" with the exact parameters <c>(<see cref="SenderMessage"/>, <see cref=
        /// "IProtocolBinding"/>)</c>.
        /// </exception>
        public static ISenderBuilder AddValidation <TCloudEvent>(this ISenderBuilder builder, IProtocolBinding protocolBinding = null)
            where TCloudEvent : CloudEvent
        {
            if (builder is null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var validateMethod = _validateMethods.GetOrAdd(typeof(TCloudEvent), ValidateMethod.Create)
                                 ?? throw MissingValidateMethod(typeof(TCloudEvent));

            return(builder.AddValidation(message => validateMethod.Invoke(message, protocolBinding)));
        }
예제 #2
0
 public void Init()
 {
     _builderFactory = new BuilderFactoryHelper().BuilderFactory;
     _senderBuilder  = _builderFactory.CreateSenderBuilder().SetBookmakerId(9985).SetLimitId(90).SetCurrency("EUR").SetSenderChannel(SenderChannel.Internet);
     _sender         = _senderBuilder.SetEndCustomer(_builderFactory.CreateEndCustomerBuilder()
                                                     .SetId("customer-client-" + SR.I1000)
                                                     .SetConfidence(12039203)
                                                     .SetIp(IPAddress.Loopback)
                                                     .SetLanguageId("en")
                                                     .SetDeviceId("123")
                                                     .Build())
                       .Build();
 }
예제 #3
0
        /// <summary>
        /// Adds a <see cref="ValidatingSender"/> decorator that ensures all messages are valid according
        /// to the <paramref name="validateMessage"/> parameter.
        /// </summary>
        /// <param name="builder">The <see cref="ISenderBuilder"/>.</param>
        /// <param name="validateMessage">
        /// A delegate that will be invoked before each message is sent. The delegate should throw an exception
        /// if header values are invalid or if required headers are missing. Delegates may also add missing
        /// headers that can be calculated at runtime.
        /// </param>
        /// <returns>The same <see cref="ISenderBuilder"/>.</returns>
        public static ISenderBuilder AddValidation(this ISenderBuilder builder, Action <SenderMessage> validateMessage)
        {
            if (builder is null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (validateMessage is null)
            {
                throw new ArgumentNullException(nameof(validateMessage));
            }

            return(builder.AddDecorator((sender, serviceProvider) =>
                                        new ValidatingSender(sender.Name, sender, validateMessage)));
        }