Esempio n. 1
0
        public void Execute(RabbitMQDataModel model)
        {
            try
            {
                List <SqlCommand> commands = null;

                switch (model.AuditType)
                {
                case AuditType.Insert:
                    commands = _queryBuilderService.CreateInsertQuery(model as RabbitMQInsertModel);
                    break;

                case AuditType.Update:
                    commands = _queryBuilderService.CreateUpdateQuery(model as RabbitMQUpdateModel);
                    break;

                case AuditType.SoftDelete:
                    commands = _queryBuilderService.CreateSoftDeleteQuery(model as RabbitMQSoftDeleteModel);
                    break;

                case AuditType.HardDelete:
                    commands = _queryBuilderService.CreateHardDeleteQuery(model as RabbitMQHardDeleteModel);
                    break;
                }

                foreach (var item in commands)
                {
                    using (item.Connection)
                    {
                        try
                        {
                            var count = item.Connection.Execute(item.CommandText);

                            if (count > 0)
                            {
                                Log.Information($"MessageId: {model.MessageId} --> Query executed successfully.");
                            }
                            else
                            {
                                Log.Warning($"MessageId: {model.MessageId} --> Query executed successfully but no records affected.");
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.Error($"Error running query\n" +
                                      $"\tMessageId: {model.MessageId}" +
                                      $"\tConnectionString: {item.Connection.ConnectionString}\n" +
                                      $"\tMessage: {ex.Message}");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error($"Error running query: {JsonConvert.SerializeObject(ex)}");
            }
        }
Esempio n. 2
0
        private RabbitMQDataModel ValidateModel(string json)
        {
            var               dataModel = JsonConvert.DeserializeObject <RabbitMQDataModel>(json);
            QueueModel        data      = null;
            RabbitMQDataModel result    = null;

            switch (dataModel.AuditType)
            {
            case AuditType.Insert:
                data   = JsonConvert.DeserializeObject <InsertModel>(json);
                result = JsonConvert.DeserializeObject <RabbitMQInsertModel>(json);
                break;

            case AuditType.Update:
                data   = JsonConvert.DeserializeObject <UpdateModel>(json);
                result = JsonConvert.DeserializeObject <RabbitMQUpdateModel>(json);
                break;

            case AuditType.SoftDelete:
                data   = JsonConvert.DeserializeObject <SoftDeleteModel>(json);
                result = JsonConvert.DeserializeObject <RabbitMQSoftDeleteModel>(json);
                break;

            case AuditType.HardDelete:
                data   = JsonConvert.DeserializeObject <HardDeleteModel>(json);
                result = JsonConvert.DeserializeObject <RabbitMQHardDeleteModel>(json);
                break;
            }

            if (data == null || dataModel.HashedValue != SecurityHelper.Ecrypt(JsonConvert.SerializeObject(data)))
            {
                return(null);
            }

            Log.Information($"Message received: \n" +
                            $"\tExchange: {data.ExchangeName}" +
                            $"\tQueue: {data.QueueName}" +
                            $"\tMessageId: {dataModel.MessageId}\n" +
                            $"\tData: {JsonConvert.SerializeObject(data)}");

            return(result);
        }