Exemplo n.º 1
0
        public async Task <ICommandResponse> HandleAsync(TCommand command)
        {
//            const string DurationMS = "DurationMS";
//            const string CommandSuccessful = "CommandSuccessful";

            var stopWatch = Stopwatch.StartNew();

            _logger.LogInformation(string.Format("{0} Started", command.GetType().Name));

            var response = await CommmandHandler.HandleAsync(command);

            stopWatch.Stop();

            var originalLogInfo = command.ToLog();

            var formattedTime = string.Format("{0:mm\\:ss\\:fff}", stopWatch.Elapsed);
            var template      = formattedTime + " {CommandName:l} - " + originalLogInfo.LogMessageTemplate;

            var properties = new List <object> {
                command.GetType().Name
            };

            properties.AddRange(originalLogInfo.LogMessageParameters);

//            var newLogInfo = new LogInfo(template, properties.ToArray());

//            var log = new Log(command.GetType().Name, newLogInfo);
//            log.AddContextProperty(DurationMS, stopWatch.ElapsedMilliseconds);
//            log.AddContextProperty(CommandSuccessful, response.Successful);
            _logger.LogInformation(template, properties.ToArray());

            return(response);
        }
Exemplo n.º 2
0
        public async Task <ICommandResponse> HandleAsync(TCommand command)
        {
            ICommandResponse retVal;
            var attribute = (TransactionCommandAttribute)TypeDescriptor.GetAttributes(command)[typeof(TransactionCommandAttribute)];

            if (attribute != null)
            {
                TransactionScopeOption?transactionScopeOption = TransactionManager.GetTransactionScopeFromObject <ICommandWithTransactionScopeOptionOverride>(command) ?? attribute.TransactionScopeOption;
                IsolationLevel?        isolationLevel         = TransactionManager.GetIsolationLevelFromObject <ICommandWithTransactionIsolationLevelOverride>(command) ?? attribute.IsolationLevel;

                using (var transactionScope = TransactionManager.CreateTransactionScope(transactionScopeOption, isolationLevel))
                {
                    TransactionManager.LogTransactionStarting(_logger, command);

                    retVal = await CommmandHandler.HandleAsync(command);

                    transactionScope.Complete();

                    TransactionManager.LogTransactionComplete(_logger, command);
                }
            }
            else
            {
                retVal = await CommmandHandler.HandleAsync(command);
            }

            return(retVal);
        }
Exemplo n.º 3
0
 public async Task <ICommandResponse> HandleAsync(TCommand command)
 {
     try
     {
         return(await CommmandHandler.HandleAsync(command));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, ex.Message);
         throw new CommandHandlerException <TCommand>("CommandHandlerException: " + command, ex, command);
     }
 }