Ejemplo n.º 1
0
        private void SerializeDatabaseMessage(DatabaseMessage message)
        {
            JsonDataTransferMessage dtm = ProduceDataTransferMessage(message);
            string json = JsonSerializer.Serialize(dtm);

            message.MessageBytes = Encoding.UTF8.GetBytes(json);
        }
Ejemplo n.º 2
0
        private void ConfigureMessageProperties(DatabaseMessage message, IBasicProperties properties)
        {
            properties.AppId     = message.Sender;
            properties.Type      = message.MessageType;
            properties.MessageId = message.Uuid.ToString();

            if (properties.Headers == null)
            {
                properties.Headers = new Dictionary <string, object>();
            }
            else
            {
                properties.Headers.Clear();
            }

            SetOperationTypeHeader(message, properties);

            if (Settings.MessageBrokerSettings.ExchangeRole == 0)
            {
                SetAggregatorCopyHeader(message, properties);
            }
            else
            {
                SetDispatcherCopyHeader(message, properties);
            }
        }
Ejemplo n.º 3
0
        private void SetDispatcherCopyHeader(DatabaseMessage message, IBasicProperties properties)
        {
            if (string.IsNullOrWhiteSpace(message.Recipients))
            {
                return;
            }

            string header = (Settings.MessageBrokerSettings.CopyType == 0 ? "CC" : "BCC");

            properties.Headers.Add(header, message.Recipients.Split(',', StringSplitOptions.RemoveEmptyEntries));
        }
Ejemplo n.º 4
0
        private void SetAggregatorCopyHeader(DatabaseMessage message, IBasicProperties properties)
        {
            if (string.IsNullOrWhiteSpace(message.Sender))
            {
                return;
            }

            string header = (Settings.MessageBrokerSettings.CopyType == 0 ? "CC" : "BCC");

            properties.Headers.Add(header, new string[] { message.Sender });
        }
Ejemplo n.º 5
0
        private void PublishMessage(ProducerChannel channel, DatabaseMessage message)
        {
            string exchange = Settings.MessageBrokerSettings.TopicExchange;

            string routingKey = message.MessageType;

            byte[] messageBytes = Encoding.UTF8.GetBytes(message.MessageBody);

            ConfigureMessageProperties(message, channel.Properties);

            channel.Channel.BasicPublish(exchange, routingKey, channel.Properties, messageBytes);
        }
Ejemplo n.º 6
0
        private DatabaseMessage CreateDatabaseMessage(DbDataReader reader)
        {
            DatabaseMessage message = new DatabaseMessage();

            message.Code          = reader.IsDBNull(0) ? 0 : (long)reader.GetDecimal(0);
            message.Uuid          = reader.IsDBNull(1) ? Guid.Empty : new Guid((byte[])reader[1]);
            message.DateTimeStamp = reader.IsDBNull(2) ? DateTime.MinValue : reader.GetDateTime(2);
            message.Sender        = reader.IsDBNull(3) ? string.Empty : reader.GetString(3);
            message.Recipients    = reader.IsDBNull(4) ? string.Empty : reader.GetString(4);
            message.OperationType = reader.IsDBNull(5) ? string.Empty : reader.GetString(5);
            message.MessageType   = reader.IsDBNull(6) ? string.Empty : reader.GetString(6);
            message.MessageBody   = reader.IsDBNull(7) ? string.Empty : reader.GetString(7);
            return(message);
        }
        private DatabaseMessage CreateDatabaseMessage(DbDataReader reader)
        {
            DatabaseMessage message = new DatabaseMessage();

            message.Code          = reader.IsDBNull(0) ? 0 : (long)reader.GetDecimal("МоментВремени");
            message.Uuid          = reader.IsDBNull(1) ? Guid.Empty : new Guid((byte[])reader["Идентификатор"]);
            message.DateTimeStamp = reader.IsDBNull(2) ? DateTime.MinValue : reader.GetDateTime("ДатаВремя").AddYears(-YearOffset);
            message.Sender        = reader.IsDBNull(3) ? string.Empty : reader.GetString("Отправитель");
            message.Recipients    = reader.IsDBNull(4) ? string.Empty : reader.GetString("Получатели");
            message.OperationType = reader.IsDBNull(5) ? string.Empty : reader.GetString("ТипОперации");
            message.MessageType   = reader.IsDBNull(6) ? string.Empty : reader.GetString("ТипСообщения");
            message.MessageBody   = reader.IsDBNull(7) ? string.Empty : reader.GetString("ТелоСообщения");
            return(message);
        }
Ejemplo n.º 8
0
        private JsonDataTransferMessage ProduceDataTransferMessage(DatabaseMessage data)
        {
            JsonDataTransferMessage message = new JsonDataTransferMessage()
            {
                Sender = data.Sender
            };

            message.Objects.Add(new JsonDataTransferObject()
            {
                Type      = data.MessageType,
                Body      = data.MessageBody,
                Operation = data.OperationType
            });
            return(message);
        }
Ejemplo n.º 9
0
        private void SetOperationTypeHeader(DatabaseMessage message, IBasicProperties properties)
        {
            if (string.IsNullOrWhiteSpace(message.OperationType))
            {
                return;
            }

            if (properties.Headers == null)
            {
                properties.Headers = new Dictionary <string, object>();
            }

            if (!properties.Headers.TryAdd("OperationType", message.OperationType))
            {
                properties.Headers["OperationType"] = message.OperationType;
            }
        }
Ejemplo n.º 10
0
 private string[] GetRecipients(DatabaseMessage message)
 {
     return(message.Recipients.Split(',', StringSplitOptions.RemoveEmptyEntries));
 }