Пример #1
0
        private void AuditExecution(IAuthenticationOutput userTokenFromCache,
                                    CommandInput input, ICommand commandObject)
        {
            // Audit an AUTH Command
            if (CurrentHostContext.Default.Audit.Enabled)
            {
                var authCommand = commandObject as IAuditCommand;
                if (authCommand != null)
                {
                    var auditRecord = authCommand.GetAuditCommand(input);

                    if (auditRecord != null)
                    {
                        Task.Factory.StartNew(() =>
                        {
                            var auditInput = new CommandInput(new CommandArgs("AddAudit"));
                            auditInput.Add("record", auditRecord.ToJson());

                            if (userTokenFromCache != null) // enrich with UserId
                            {
                                auditInput.AssociateUserId(userTokenFromCache.UserId.GetValueOrDefault(-1));
                            }

                            ExecuteCommandInternal(auditInput, _auditCommand);
                        })
                        .ContinueWith(task =>
                                      CurrentHostContext.Default.Log.ErrorFormat("Error adding audit record {0}",
                                                                                 task.Exception.GetDetails()), TaskContinuationOptions.OnlyOnFaulted);
                    }
                }
            }
        }
Пример #2
0
        public ServiceCommandOutput <object> ExecuteCommand(string command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            if (_authenticationOutput == null)
            {
                _authenticationOutput = AuthenticateUser(_configuration.Runtime.User.Username,
                                                         _configuration.Runtime.User.Password);
            }

            if (_authenticationOutput != null && _authenticationOutput.IsAuthenticated)
            {
                ServiceCommandOutput <object> commandOutput;

                if (CurrentContext.Default.Cache.Enabled)
                {
                    commandOutput = CurrentContext.Default.Cache.Get(command, () =>
                                                                     ExecuteCommandInternal(command));
                }
                else
                {
                    commandOutput = ExecuteCommandInternal(command);
                }

                return(commandOutput);
            }

            throw new InvalidOperationException("Could not authenticate user");
        }
Пример #3
0
        private void AuditExecution(IAuthenticationOutput userTokenFromCache,
            CommandInput input, ICommand commandObject)
        {
            // Audit an AUTH Command
            if (CurrentHostContext.Default.Audit.Enabled)
            {
                var authCommand = commandObject as IAuditCommand;
                if (authCommand != null)
                {
                    var auditRecord = authCommand.GetAuditCommand(input);

                    if (auditRecord != null)
                    {
                        Task.Factory.StartNew(() =>
                        {
                            var auditInput = new CommandInput(new CommandArgs("AddAudit"));
                            auditInput.Add("record", auditRecord.ToJson());

                            if (userTokenFromCache != null) // enrich with UserId
                                auditInput.AssociateUserId(userTokenFromCache.UserId.GetValueOrDefault(-1));

                            ExecuteCommandInternal(auditInput, _auditCommand);
                        })
                            .ContinueWith(task =>
                                CurrentHostContext.Default.Log.ErrorFormat("Error adding audit record {0}",
                                    task.Exception.GetDetails()), TaskContinuationOptions.OnlyOnFaulted);
                    }
                }
            }
        }
Пример #4
0
        public ServiceCommandOutput<object> ExecuteCommand(string command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            if (_authenticationOutput == null)
            {
                _authenticationOutput = AuthenticateUser(_configuration.Runtime.User.Username,
                    _configuration.Runtime.User.Password);
            }

            if (_authenticationOutput != null && _authenticationOutput.IsAuthenticated)
            {
                ServiceCommandOutput<object> commandOutput;

                if (CurrentContext.Default.Cache.Enabled)
                {
                    commandOutput = CurrentContext.Default.Cache.Get(command, () =>
                        ExecuteCommandInternal(command));
                }
                else
                {
                    commandOutput = ExecuteCommandInternal(command);
                }

                return commandOutput;
            }

            throw new InvalidOperationException("Could not authenticate user");
        }