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); } } } }
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"); }
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); } } } }
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"); }