Exemple #1
0
        public void BeforeInvoke(InvocationContext invocationContext)
        {
            try
            {
                var argsDictionary = new Dictionary <string, object>();
                var args           = invocationContext.GetExecutingMethodInfo().GetParameters();
                for (var i = 0; i < args.Length; i++)
                {
                    var argumentValue = invocationContext.GetParameterValue(i);
                    var argumentName  = args[i].Name;
                    argsDictionary.Add(argumentName, argumentValue);
                }

                _cacheKey = invocationContext.GetExecutingMethodInfo().GetParameters().Length > 0
                    ? CacheKeyGenerator.GenerateCacheKey(invocationContext.GetExecutingMethodInfo(), argsDictionary)
                    : invocationContext.GetExecutingMethodInfo().Name;


                var doesCacheExist = _cacheProvider.Get(_cacheKey);

                if (doesCacheExist != null)
                {
                    invocationContext.OverrideMethodReturnValue(doesCacheExist);
                    invocationContext.BypassInvocation();
                }
            }
            catch (Exception ex)
            {
                _logger.ErrorException(ex.Message, ex);
                throw;
            }
        }
Exemple #2
0
 public List <TestEntity> GetByFirstName(string firstName)
 {
     try
     {
         var result = QueryFactory.Query(TableName).Where("FirstName", firstName).Get <TestEntity>();
         return(result.ToList());
     }
     catch (Exception ex)
     {
         _logger.ErrorException(ex.Message, ex);
         throw;
     }
 }
Exemple #3
0
 public virtual void Start(JobSetting jobSetting)
 {
     try
     {
         _scheduler.Start().ConfigureAwait(false).GetAwaiter().GetResult();
         ScheduleJobs(jobSetting);
     }
     catch (Exception ex)
     {
         _logger.ErrorException(ex.Message, ex);
         throw;
     }
 }
Exemple #4
0
 public List <TestEntity> GetByFirstName(string firstName)
 {
     try
     {
         BRule.Assert(!string.IsNullOrEmpty(firstName), "Firstname is invalid");
         var result = Repository.GetByFirstName(firstName);
         return(result);
     }
     catch (Exception ex)
     {
         _logger.ErrorException(ex.Message, ex);
         throw;
     }
 }
Exemple #5
0
        public void AfterInvoke(InvocationContext invocationContext, object methodResult)
        {
            try
            {
                var endDate       = DateTime.Now;
                var executionTime = (int)((endDate - _startTime).TotalMilliseconds);

                var argsDictionary = new Dictionary <string, object>();
                var args           = invocationContext.GetExecutingMethodInfo().GetParameters();
                for (var i = 0; i < args.Length; i++)
                {
                    var argumentValue = invocationContext.GetParameterValue(i);
                    var argumentName  = args[i].Name;
                    argsDictionary.Add(argumentName, argumentValue);
                }

                var methodInfo = invocationContext.GetExecutingMethodInfo();

                var auditEntity = new Audit
                {
                    Id            = Guid.NewGuid(),
                    Input         = JsonConvert.SerializeObject(argsDictionary),
                    Output        = JsonConvert.SerializeObject(methodResult),
                    ClassName     = methodInfo.Module.ToString(),
                    MethodName    = methodInfo.Name,
                    StartTime     = _startTime,
                    EndTime       = endDate,
                    ExecutionTime = executionTime
                };

                _auditorProvider.Save(auditEntity);
            }
            catch (Exception ex)
            {
                _logger.ErrorException(ex.Message, ex);
                throw;
            }
        }