public static List <string> UnicastAddresses(this IOutgoingLogicalMessageContext context)
 {
     return(context.RoutingStrategies
            .OfType <UnicastRoutingStrategy>()
            .Select(x => ((UnicastAddressTag)x.Apply(emptyDictionary)).Destination)
            .ToList());
 }
 public EncryptedValue Encrypt(string value, IOutgoingLogicalMessageContext context)
 {
     return(new EncryptedValue
     {
         EncryptedBase64Value = new string(value.Reverse().ToArray())
     });
 }
 /// <summary>
 /// The serializer should skip serializing the message.
 /// </summary>
 public static bool ShouldSkipSerialization(this IOutgoingLogicalMessageContext context)
 {
     Guard.AgainstNull(nameof(context), context);
     if (context.Extensions.TryGet("MessageSerialization.Skip", out bool shouldSkipSerialization))
     {
         return(shouldSkipSerialization);
     }
     return(false);
 }
 public static IOutgoingLogicalMessageContext StorePipelineContextToOutgoingMessageHeader
     (this IOutgoingLogicalMessageContext context,
     string headerName)
 {
     if (context.Extensions.TryGet(headerName, out string headerValue))
     {
         context.Headers[headerName] = headerValue;
     }
     return(context);
 }
Example #5
0
        /// <summary>
        /// The serializer should skip serializing the message.
        /// </summary>
        public static bool ShouldSkipSerialization(this IOutgoingLogicalMessageContext context)
        {
            bool shouldSkipSerialization;

            if (context.Extensions.TryGet("MessageSerialization.Skip", out shouldSkipSerialization))
            {
                return(shouldSkipSerialization);
            }
            return(false);
        }
Example #6
0
    public static bool TryReadTransaction(this IOutgoingLogicalMessageContext context, out Transaction transaction)
    {
        if (context.Extensions.TryGet <TransportTransaction>(out var transportTransaction))
        {
            return(transportTransaction.TryGet(out transaction));
        }

        transaction = null;
        return(false);
    }
Example #7
0
        /// <summary>
        /// Tries to retrieves an instance of <typeparamref name="T"/> from a <see cref="IOutgoingLogicalMessageContext"/>.
        /// </summary>
        public static bool TryGetDeliveryConstraint <T>(this IOutgoingLogicalMessageContext context, out T constraint) where T : DeliveryConstraint
        {
            List <DeliveryConstraint> constraints;

            if (context.Extensions.TryGet(out constraints))
            {
                return(constraints.TryGet(out constraint));
            }
            constraint = null;
            return(false);
        }
        public static MessageIntentEnum GetMessageIntent(this IOutgoingLogicalMessageContext message)
        {
            var messageIntent = default(MessageIntentEnum);

            if (message.Headers.TryGetValue(Headers.MessageIntent, out var messageIntentString))
            {
                Enum.TryParse(messageIntentString, true, out messageIntent);
            }

            return(messageIntent);
        }
    public static string GetDestinationForUnicastMessages(this IOutgoingLogicalMessageContext context)
    {
        var sendAddressTags = context.RoutingStrategies
                              .OfType <UnicastRoutingStrategy>()
                              .Select(urs => urs.Apply(context.Headers))
                              .Cast <UnicastAddressTag>().ToList();

        if (sendAddressTags.Count != 1)
        {
            return(null);
        }

        return(sendAddressTags.First().Destination);
    }
Example #10
0
        public EncryptedValue Encrypt(string value, IOutgoingLogicalMessageContext context)
        {
            var encrypted = _client.EncryptAsync(new EncryptRequest
            {
                KeyId     = _encryptionKeyIdentifier,
                Plaintext = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(value))
            }).GetAwaiter().GetResult();

            string base64Value = encrypted != null?Convert.ToBase64String(encrypted.CiphertextBlob.ToArray())  : null;

            context.Headers[EncryptionHeaders.RijndaelKeyIdentifier] = _encryptionKeyIdentifier;

            return(new EncryptedValue
            {
                EncryptedBase64Value = base64Value
            });
        }
        public EncryptedValue Encrypt(string value, IOutgoingLogicalMessageContext context)
        {
            if (string.IsNullOrEmpty(encryptionKeyIdentifier))
            {
                throw new InvalidOperationException("It is required to set the rijndael key identifier.");
            }

            AddKeyIdentifierHeader(context);

            using (var rijndael = new RijndaelManaged())
            {
                rijndael.Key = encryptionKey;
                rijndael.Mode = CipherMode.CBC;
                ConfigureIV(rijndael);

                using (var encryptor = rijndael.CreateEncryptor())
                {
                    using (var memoryStream = new MemoryStream())
                    {
                        using (var cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))
                        {
                            using (var writer = new StreamWriter(cryptoStream))
                            {
                                writer.Write(value);
                                writer.Flush();
                                cryptoStream.Flush();
                                cryptoStream.FlushFinalBlock();
                                return new EncryptedValue
                                {
                                    EncryptedBase64Value = Convert.ToBase64String(memoryStream.ToArray()),
                                    Base64Iv = Convert.ToBase64String(rijndael.IV)
                                };
                            }
                        }
                    }
                }
            }
        }
        public EncryptedValue Encrypt(string value, IOutgoingLogicalMessageContext context)
        {
            if (string.IsNullOrEmpty(encryptionKeyIdentifier))
            {
                throw new InvalidOperationException("It is required to set the rijndael key identifier.");
            }

            AddKeyIdentifierHeader(context);

            using (var rijndael = new RijndaelManaged())
            {
                rijndael.Key  = encryptionKey;
                rijndael.Mode = CipherMode.CBC;
                ConfigureIV(rijndael);

                using (var encryptor = rijndael.CreateEncryptor())
                {
                    using (var memoryStream = new MemoryStream())
                    {
                        using (var cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))
                        {
                            using (var writer = new StreamWriter(cryptoStream))
                            {
                                writer.Write(value);
                                writer.Flush();
                                cryptoStream.Flush();
                                cryptoStream.FlushFinalBlock();
                                return(new EncryptedValue
                                {
                                    EncryptedBase64Value = Convert.ToBase64String(memoryStream.ToArray()),
                                    Base64Iv = Convert.ToBase64String(rijndael.IV)
                                });
                            }
                        }
                    }
                }
            }
        }
 protected virtual void AddKeyIdentifierHeader(IOutgoingLogicalMessageContext context)
 {
     context.Headers[Headers.RijndaelKeyIdentifier] = encryptionKeyIdentifier;
 }
 protected virtual void AddKeyIdentifierHeader(IOutgoingLogicalMessageContext context)
 {
     context.Headers[Headers.RijndaelKeyIdentifier] = encryptionKeyIdentifier;
 }
 public static string MessageIntent(this IOutgoingLogicalMessageContext context) =>
 MessageIntent(context.Headers);
 public static string MessageIntent(this IOutgoingLogicalMessageContext context)
 {
     return(MessageIntent(context.Headers));
 }
        /// <summary>
        /// Returns the incoming physical message if there is one currently processed.
        /// </summary>
        public static bool TryGetIncomingPhysicalMessage(this IOutgoingLogicalMessageContext context, out IncomingMessage message)
        {
            Guard.AgainstNull(nameof(context), context);

            return(context.Extensions.TryGet(out message));
        }
Example #18
0
 string ReturnDefaultConversationId(IOutgoingLogicalMessageContext context)
 {
     return(ConversationId.Default.Value);
 }
Example #19
0
        public static void EncryptValue(this IEncryptionService encryptionService, ref string stringToEncrypt, IOutgoingLogicalMessageContext context)
        {
            var encryptedValue = encryptionService.Encrypt(stringToEncrypt, context);

            stringToEncrypt = $"{encryptedValue.EncryptedBase64Value}@{encryptedValue.Base64Iv}";
        }
 public static void EncryptValue(this IEncryptionService encryptionService, EncryptedString encryptedString, IOutgoingLogicalMessageContext context)
 {
     encryptedString.EncryptedValue = encryptionService.Encrypt(encryptedString.Value, context);
     encryptedString.Value          = null;
 }
 public static void EncryptValue(this IEncryptionService encryptionService, WireEncryptedString wireEncryptedString, IOutgoingLogicalMessageContext context)
 {
     wireEncryptedString.EncryptedValue = encryptionService.Encrypt(wireEncryptedString.Value, context);
     wireEncryptedString.Value = null;
 }
 public EncryptedValue Encrypt(string value, IOutgoingLogicalMessageContext context)
 {
     throw new System.NotImplementedException();
 }
 public static Guid GetMessageId(this IOutgoingLogicalMessageContext context)
 {
     return((context.Message.Instance as IEvent)?.EventId ??
            (context.Message.Instance as IPaymentsCommand)?.CommandId ?? Guid.Empty);
 }
 public static string GetMessageName(this IOutgoingLogicalMessageContext context)
 {
     return(context.Message.Instance.GetType().Name);
 }
Example #25
0
 /// <summary>
 /// Adds a <see cref="DeliveryConstraint"/> to a <see cref="IOutgoingLogicalMessageContext"/>.
 /// </summary>
 public static void AddDeliveryConstraint(this IOutgoingLogicalMessageContext context, DeliveryConstraint constraint)
 {
     AddDeliveryConstraintInternal(context, constraint);
 }
 public EncryptedValue Encrypt(string value, IOutgoingLogicalMessageContext context)
 {
     throw new NotImplementedException();
 }
        public static void EncryptValue(this IEncryptionService encryptionService, ref string stringToEncrypt, IOutgoingLogicalMessageContext context)
        {
            var encryptedValue = encryptionService.Encrypt(stringToEncrypt, context);

            stringToEncrypt = $"{encryptedValue.EncryptedBase64Value}@{encryptedValue.Base64Iv}";
        }
Example #28
0
 /// <summary>
 /// Requests the serializer to skip serializing the message.
 /// </summary>
 /// <remarks>
 /// This can be used by an extension point needs to take control of the serialization.
 /// For example the Callbacks implementation that skips serialization and instead uses
 /// headers for passing the enum or int value.
 /// </remarks>
 public static void SkipSerialization(this IOutgoingLogicalMessageContext context)
 {
     context.Extensions.Set("MessageSerialization.Skip", true);
 }
Example #29
0
 public OutgoingPhysicalMessageContext(byte[] body, IReadOnlyCollection <RoutingStrategy> routingStrategies, IOutgoingLogicalMessageContext parentContext)
     : base(parentContext.MessageId, parentContext.Headers, parentContext)
 {
     Body = body;
     RoutingStrategies = routingStrategies;
 }
 public EncryptedValue Encrypt(string value, IOutgoingLogicalMessageContext context)
 {
     return(hardcodedValue);
 }
 protected internal override void AddKeyIdentifierHeader(IOutgoingLogicalMessageContext context)
 {
     OutgoingKeyIdentifierSet = true;
 }
 public OutgoingPhysicalMessageContext(byte[] body, IReadOnlyCollection<RoutingStrategy> routingStrategies, IOutgoingLogicalMessageContext parentContext)
     : base(parentContext.MessageId, parentContext.Headers, parentContext)
 {
     Body = body;
     RoutingStrategies = routingStrategies;
 }
 public EncryptedValue Encrypt(string value, IOutgoingLogicalMessageContext context)
 {
     return hardcodedValue;
 }
 protected override void AddKeyIdentifierHeader(IOutgoingLogicalMessageContext context)
 {
     OutgoingKeyIdentifierSet = true;
 }
        /// <summary>
        /// Creates a <see cref="IOutgoingPhysicalMessageContext" /> based on the current context.
        /// </summary>
        public static IOutgoingPhysicalMessageContext CreateOutgoingPhysicalMessageContext(this StageConnector <IOutgoingLogicalMessageContext, IOutgoingPhysicalMessageContext> stageConnector, byte[] messageBody, IReadOnlyCollection <RoutingStrategy> routingStrategies, IOutgoingLogicalMessageContext sourceContext)
        {
            Guard.AgainstNull(nameof(messageBody), messageBody);
            Guard.AgainstNull(nameof(routingStrategies), routingStrategies);
            Guard.AgainstNull(nameof(sourceContext), sourceContext);

            return(new OutgoingPhysicalMessageContext(messageBody, routingStrategies, sourceContext));
        }
Example #36
0
 /// <summary>
 /// Requests the serializer to skip serializing the message.
 /// </summary>
 /// <remarks>
 /// This can be used by an extension point needs to take control of the serialization.
 /// For example the Callbacks implementation that skips serialization and instead uses
 /// headers for passing the enum or int value.
 /// </remarks>
 public static void SkipSerialization(this IOutgoingLogicalMessageContext context)
 {
     Guard.AgainstNull(nameof(context), context);
     context.Extensions.Set("MessageSerialization.Skip", true);
 }
        /// <summary>
        /// Creates a <see cref="IOutgoingPhysicalMessageContext" /> based on the current context.
        /// </summary>
        public static IOutgoingPhysicalMessageContext CreateOutgoingPhysicalMessageContext(this StageConnector<IOutgoingLogicalMessageContext, IOutgoingPhysicalMessageContext> stageConnector, byte[] messageBody, IReadOnlyCollection<RoutingStrategy> routingStrategies, IOutgoingLogicalMessageContext sourceContext)
        {
            Guard.AgainstNull(nameof(messageBody), messageBody);
            Guard.AgainstNull(nameof(routingStrategies), routingStrategies);
            Guard.AgainstNull(nameof(sourceContext), sourceContext);

            return new OutgoingPhysicalMessageContext(messageBody, routingStrategies, sourceContext);
        }