public virtual object MethodInvoke(MethodContext _methodContext)
        {
            object result = null;

            result = _methodContext.Invoke();
            result = result ?? new Object();

            return(result);
        }
示例#2
0
        public virtual Object OnBeforeWithReturnValueGetFromCache(MethodContext _methodContext)
        {
            string cacheKey   = string.Format("{0}_{1}", _methodContext.MethodName, string.Join("_", _methodContext.Arguments));
            object cachedItem = MemoryCache.Default.Get(cacheKey);


            Console.WriteLine("{0} isimli cache key ile cache üzerinden geliyorum!", cacheKey);
            return(cachedItem);
        }
示例#3
0
        public virtual void OnAfterAddToCache(RealTypeResponseArgument param, MethodContext _methodContext)
        {
            string cacheKey = string.Format("{0}_{1}", _methodContext.MethodName, string.Join("_", _methodContext.Arguments));

            if (MemoryCache.Default.Get(cacheKey) == null && param.Value != null && param.IsRealTypeValue)
            {
                MemoryCache.Default.Add(cacheKey, param.Value, DateTimeOffset.Now.AddMinutes(DurationMinute));
            }
        }
        public override object OnBeforeWithReturnValue(MethodContext _methodContext)
        {
            object result = null;

            if (this.GetType().GetMethods().FirstOrDefault(x => x.Name == "MethodInvoke").DeclaringType
                == typeof(AspectExplorerTryCatch).GetMethods().FirstOrDefault(x => x.Name == "MethodInvoke").DeclaringType)
            {
                try
                {
                    result = this.MethodInvoke(_methodContext);
                }
                catch (Exception ex)
                {
                    result = ex;
                }
            }
            else
            {
                result = this.MethodInvoke(_methodContext);
            }

            return(result);
        }
示例#5
0
        public virtual void OnAfterlogProcess(RealTypeResponseArgument param, MethodContext _methodContext)
        {
            AspectExplorerLogAttributeModel _aspectLogModel = new AspectExplorerLogAttributeModel();

            _aspectLogModel.InvokeMethodName = _methodContext.MethodName;
            _aspectLogModel.InvokeStackTrace = "";
            _aspectLogModel.InvokeTime       = DateTime.Now;
            if (param != null)
            {
                _aspectLogModel.ResponseType = param.Value.GetType().ToString();
            }

            // _aspectLogModel.RequestTypes = _methodContext.MethodBase.Args

            //
            try
            {
                StringBuilder sbRequestTypes = new StringBuilder();
                StringBuilder sbRequestArgs  = new StringBuilder();
                foreach (var item in _methodContext.MethodBase.Args)
                {
                    sbRequestTypes.Append(item.GetType().ToString());

                    sbRequestArgs.Append(item.GetType().ToString()).Append(" : ");
                    foreach (PropertyInfo eachItem in item.GetType().GetProperties())
                    {
                        if (eachItem.GetValue(item) != null)
                        {
                            sbRequestArgs.Append(string.Format("{0} : {1}", eachItem.Name, eachItem.GetValue(item).ToString()));
                        }
                    }
                }
                _aspectLogModel.RequestTypes   = sbRequestTypes.ToString();
                _aspectLogModel.RequestArgsStr = sbRequestArgs.ToString();
            }
            catch { }
            //
            try
            {
                if (param != null)
                {
                    StringBuilder sbResponseValue = new StringBuilder();
                    foreach (PropertyInfo item in param.Value.GetType().GetProperties())
                    {
                        if (item.GetValue(param.Value) != null)
                        {
                            sbResponseValue.Append(string.Format("{0} : {1}", item.Name, item.GetValue(param.Value).ToString()));
                        }
                    }
                    _aspectLogModel.ResponseArgsStr = sbResponseValue.ToString();
                }
            }
            catch { }
            //

            //
            try
            {
                StringBuilder sbJsonResult = new StringBuilder();
                sbJsonResult.Append(" # ").Append(DateTime.Now.ToString()).Append(" : ");
                sbJsonResult.Append(new JavaScriptSerializer().Serialize(_aspectLogModel));

                string _directoryPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AspectExplorerLog/");
                if (!Directory.Exists(_directoryPath))
                {
                    Directory.CreateDirectory(_directoryPath);
                }
                File.AppendAllText(_directoryPath + DateTime.Now.ToString("yyyyMMdd") + "log.txt", sbJsonResult.ToString());
            }
            catch { }
        }
示例#6
0
 public override void OnAfter(RealTypeResponseArgument param, MethodContext _methodContext)
 {
     this.OnAfterlogProcess(param.Value == null ? null : param, _methodContext);
 }
示例#7
0
 public override object OnBeforeWithReturnValue(MethodContext _methodContext)
 {
     return(this.OnBeforeWithReturnValueGetFromCache(_methodContext));
 }
示例#8
0
 public override void OnAfter(RealTypeResponseArgument param, MethodContext _methodContext)
 {
     this.OnAfterAddToCache(param, _methodContext);
 }
示例#9
0
 public virtual object OnBeforeWithReturnValue(MethodContext _methodContext)
 {
     return(null);
 }
示例#10
0
 //JOIN POINTS ON BEFORE
 public virtual void OnBefore(MethodContext _methodContext)
 {
 }
示例#11
0
 //JOIN POINTS ON AFTER
 public virtual void OnAfter(RealTypeResponseArgument _param, MethodContext _methodContext)
 {
 }