public virtual object MethodInvoke(MethodContext _methodContext) { object result = null; result = _methodContext.Invoke(); result = result ?? new Object(); return(result); }
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); }
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); }
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 { } }
public override void OnAfter(RealTypeResponseArgument param, MethodContext _methodContext) { this.OnAfterlogProcess(param.Value == null ? null : param, _methodContext); }
public override object OnBeforeWithReturnValue(MethodContext _methodContext) { return(this.OnBeforeWithReturnValueGetFromCache(_methodContext)); }
public override void OnAfter(RealTypeResponseArgument param, MethodContext _methodContext) { this.OnAfterAddToCache(param, _methodContext); }
public virtual object OnBeforeWithReturnValue(MethodContext _methodContext) { return(null); }
//JOIN POINTS ON BEFORE public virtual void OnBefore(MethodContext _methodContext) { }
//JOIN POINTS ON AFTER public virtual void OnAfter(RealTypeResponseArgument _param, MethodContext _methodContext) { }