/// <summary> /// <para> /// Sets the serializer to an instance of <see cref="BinaryFileMessageSerializer" /> (or /// <see cref="BinaryFileMessageSerializer{TModel}" />) to wrap the consumed binary files into a /// <see cref="BinaryFileMessage" />. /// </para> /// <para> /// This settings will force the <see cref="BinaryFileMessageSerializer" /> to be used regardless of /// the message type header. /// </para> /// </summary> /// <remarks> /// This replaces the <see cref="IMessageSerializer" /> and the endpoint will only be able to deal with /// binary files. /// </remarks> /// <typeparam name="TBuilder"> /// The actual builder type. /// </typeparam> /// <param name="endpointBuilder"> /// The endpoint builder. /// </param> /// <param name="serializerBuilderAction"> /// An optional <see cref="Action{T}" /> that takes the <see cref="IBinaryFileMessageSerializerBuilder" /> /// and configures it. /// </param> /// <returns> /// The endpoint builder so that additional calls can be chained. /// </returns> public static TBuilder ConsumeBinaryFiles <TBuilder>( this IConsumerEndpointBuilder <TBuilder> endpointBuilder, Action <IBinaryFileMessageSerializerBuilder>?serializerBuilderAction = null) where TBuilder : IConsumerEndpointBuilder <TBuilder> { Check.NotNull(endpointBuilder, nameof(endpointBuilder)); var serializerBuilder = new BinaryFileMessageSerializerBuilder(); serializerBuilderAction?.Invoke(serializerBuilder); endpointBuilder.DeserializeUsing(serializerBuilder.Build()); return((TBuilder)endpointBuilder); }
/// <summary> /// <para> /// Sets the serializer to an instance of <see cref="NewtonsoftJsonMessageSerializer" /> (or /// <see cref="NewtonsoftJsonMessageSerializer{TMessage}" />) to deserialize the consumed JSON. /// </para> /// <para> /// By default this serializer relies on the message type header to determine the type of the message /// to be deserialized. This behavior can be changed using the builder action and specifying a fixed /// message type. /// </para> /// </summary> /// <typeparam name="TBuilder"> /// The actual builder type. /// </typeparam> /// <param name="endpointBuilder"> /// The endpoint builder. /// </param> /// <param name="serializerBuilderAction"> /// An optional <see cref="Action{T}" /> that takes the /// <see cref="INewtonsoftJsonMessageSerializerBuilder" /> and configures it. /// </param> /// <returns> /// The endpoint builder so that additional calls can be chained. /// </returns> public static TBuilder DeserializeJsonUsingNewtonsoft <TBuilder>( this IConsumerEndpointBuilder <TBuilder> endpointBuilder, Action <INewtonsoftJsonMessageSerializerBuilder>?serializerBuilderAction = null) where TBuilder : IConsumerEndpointBuilder <TBuilder> { Check.NotNull(endpointBuilder, nameof(endpointBuilder)); var serializerBuilder = new NewtonsoftJsonMessageSerializerBuilder(); serializerBuilderAction?.Invoke(serializerBuilder); endpointBuilder.DeserializeUsing(serializerBuilder.Build()); return((TBuilder)endpointBuilder); }
/// <summary> /// Specifies that the AES algorithm has to be used to decrypt the messages. /// </summary> /// <typeparam name="TBuilder"> /// The actual builder type. /// </typeparam> /// <param name="endpointBuilder"> /// The endpoint builder. /// </param> /// <param name="key"> /// The secret key for the symmetric algorithm. /// </param> /// <param name="initializationVector"> /// The optional initialization vector (IV) for the symmetric algorithm. If <c>null</c> it is expected /// that the IV is prepended to the actual encrypted message. /// </param> /// <returns> /// The endpoint builder so that additional calls can be chained. /// </returns> public static TBuilder DecryptUsingAes <TBuilder>( this IConsumerEndpointBuilder <TBuilder> endpointBuilder, byte[] key, byte[]?initializationVector = null) where TBuilder : IConsumerEndpointBuilder <TBuilder> { Check.NotNull(endpointBuilder, nameof(endpointBuilder)); endpointBuilder.Decrypt( new SymmetricEncryptionSettings { AlgorithmName = "AES", Key = key, InitializationVector = initializationVector }); return((TBuilder)endpointBuilder); }
/// <summary> /// Specifies that the AES algorithm has to be used to decrypt the messages. /// </summary> /// <typeparam name="TBuilder"> /// The actual builder type. /// </typeparam> /// <param name="endpointBuilder"> /// The endpoint builder. /// </param> /// <param name="decryptionKeyCallback"> /// The function to be used to retrieve the encryption key according to the encryption key identifier passed /// in the header (see <see cref="DefaultMessageHeaders.EncryptionKeyId" />). /// </param> /// <param name="initializationVector"> /// The optional initialization vector (IV) for the symmetric algorithm. If <c>null</c> it is expected /// that the IV is prepended to the actual encrypted message. /// </param> /// <returns> /// The endpoint builder so that additional calls can be chained. /// </returns> public static TBuilder DecryptUsingAes <TBuilder>( this IConsumerEndpointBuilder <TBuilder> endpointBuilder, Func <string?, byte[]> decryptionKeyCallback, byte[]?initializationVector = null) where TBuilder : IConsumerEndpointBuilder <TBuilder> { Check.NotNull(endpointBuilder, nameof(endpointBuilder)); endpointBuilder.Decrypt( new SymmetricDecryptionSettings { AlgorithmName = "AES", KeyProvider = decryptionKeyCallback, InitializationVector = initializationVector }); return((TBuilder)endpointBuilder); }