protected override void BeforeCall(InterceptCallInfo info) { if (!IsEnabled) return; IDictionary cache = GetCache(info); lock (cache.SyncRoot) { CompoundValue key = GetKey(info); CacheAspectItem item = GetItem(cache, key); if (item != null && !item.IsExpired) { info.InterceptResult = InterceptResult.Return; info.ReturnValue = item.ReturnValue; if (item.RefValues != null) { ParameterInfo[] pis = info.CallMethodInfo.Parameters; int n = 0; for (int i = 0; i < pis.Length; i++) if (pis[i].ParameterType.IsByRef) info.ParameterValues[i] = item.RefValues[n++]; } info.Cached = true; } else { info.Items["CacheKey"] = key; } } }
protected override void AfterCall(InterceptCallInfo info) { if (!IsEnabled) { return; } IDictionary cache = Cache; lock (cache.SyncRoot) { _object = info.Object; // BVChanges: adding _object field CompoundValue key = (CompoundValue)info.Items["CacheKey"]; if (key == null) { return; } int maxCacheTime = _instanceMaxCacheTime ?? MaxCacheTime; bool isWeak = _instanceIsWeak ?? IsWeak; CacheAspectItem item = new CacheAspectItem(); item.ReturnValue = info.ReturnValue; item.MaxCacheTime = maxCacheTime == int.MaxValue || maxCacheTime < 0? DateTime.MaxValue: DateTime.Now.AddMilliseconds(maxCacheTime); ParameterInfo[] pis = info.CallMethodInfo.Parameters; int n = 0; foreach (ParameterInfo pi in pis) { if (pi.ParameterType.IsByRef) { n++; } } if (n > 0) { item.RefValues = new object[n]; n = 0; for (int i = 0; i < pis.Length; i++) { if (pis[i].ParameterType.IsByRef) { item.RefValues[n++] = info.ParameterValues[i]; } } } cache[key] = isWeak? (object)new WeakReference(item): item; } }
public virtual void UnregisterCall(InterceptCallInfo info) { AddCall(DateTime.Now - info.BeginCallTime, info.Exception != null, info.Cached); lock (_currentCalls.SyncRoot) _currentCalls.Remove(info); }
private static ConfigParameters GetConfigParameters(InterceptCallInfo info) { ConfigParameters cp = info.CallMethodInfo.LogParameters; if (cp == null) { info.CallMethodInfo.LogParameters = cp = new ConfigParameters(); string[] ps = info.ConfigString.Split(';'); foreach (string p in ps) { string[] vs = p.Split('='); if (vs.Length == 2) { switch (vs[0].ToLower().Trim()) { case "filename": cp.FileName = vs[1].Trim(); break; case "mincalltime": cp.MinCallTime = int.Parse(vs[1].Trim()); break; case "logexceptions": cp.LogExceptions = bool.Parse(vs[1].Trim()); break; case "logparameters": cp.LogParameters = bool.Parse(vs[1].Trim()); break; } } } } return(cp); }
private static ConfigParameters GetConfigParameters(InterceptCallInfo info) { ConfigParameters cp = info.CallMethodInfo.CacheParameters; if (cp == null) { info.CallMethodInfo.CacheParameters = cp = new ConfigParameters(); string[] ps = info.ConfigString.Split(';'); foreach (string p in ps) { string[] vs = p.Split('='); if (vs.Length == 2) { switch (vs[0].ToLower().Trim()) { case "maxcachetime": cp.MaxCacheTime = int.Parse(vs[1].Trim()); break; case "isweak": cp.IsWeak = bool.Parse(vs[1].Trim()); break; } } } } return(cp); }
private static ConfigParameters GetConfigParameters(InterceptCallInfo info) { ConfigParameters cp = info.CallMethodInfo.LogParameters; if (cp == null) { info.CallMethodInfo.LogParameters = cp = new ConfigParameters(); string[] ps = info.ConfigString.Split(';'); foreach (string p in ps) { string[] vs = p.Split('='); if (vs.Length == 2) { switch (vs[0].ToLower().Trim()) { case "filename": cp.FileName = vs[1].Trim(); break; case "mincalltime": cp.MinCallTime = int. Parse(vs[1].Trim()); break; case "logexceptions": cp.LogExceptions = bool.Parse(vs[1].Trim()); break; case "logparameters": cp.LogParameters = bool.Parse(vs[1].Trim()); break; } } } } return cp; }
protected override void OnFinally(InterceptCallInfo info) { if (IsEnabled) { LogOperation(info); } }
protected override void BeforeCall(InterceptCallInfo info) { if (!IsEnabled) return; var cache = Cache; lock (cache.SyncRoot) { var key = GetKey(info); var item = GetItem(cache, key); if (item != null && !item.IsExpired) { info.InterceptResult = InterceptResult.Return; info.ReturnValue = item.ReturnValue; if (item.RefValues != null) { var pis = info.CallMethodInfo.Parameters; var n = 0; for (var i = 0; i < pis.Length; i++) if (pis[i].ParameterType.IsByRef) info.ParameterValues[i] = item.RefValues[n++]; } info.Cached = true; } else { info.Items["CacheKey"] = key; } } }
protected override void AfterCall(InterceptCallInfo info) { if (!IsEnabled) { return; } var cache = Cache; lock (cache.SyncRoot) { var key = (CompoundValue)info.Items["CacheKey"]; if (key == null) { return; } var maxCacheTime = _instanceMaxCacheTime ?? MaxCacheTime; var isWeak = _instanceIsWeak ?? IsWeak; var item = new CacheAspectItem { ReturnValue = info.ReturnValue, MaxCacheTime = maxCacheTime == int.MaxValue || maxCacheTime < 0 ? DateTime.MaxValue : DateTime.Now.AddMilliseconds(maxCacheTime), }; var pis = info.CallMethodInfo.Parameters; var n = 0; foreach (var pi in pis) { if (pi.ParameterType.IsByRef) { n++; } } if (n > 0) { item.RefValues = new object[n]; n = 0; for (var i = 0; i < pis.Length; i++) { if (pis[i].ParameterType.IsByRef) { item.RefValues[n++] = info.ParameterValues[i]; } } } cache[key] = isWeak? (object)new WeakReference(item): item; } }
protected override void BeforeCall(InterceptCallInfo info) { if (!IsEnabled || Thread.GetData(_counterSlot) != null) return; _counter.RegisterCall(info); Thread.SetData(_counterSlot, _counter); }
public void Intercept(InterceptCallInfo info) { switch (info.InterceptType) { case InterceptType.BeforeCall: BeforeCall(info); break; case InterceptType.AfterCall: AfterCall (info); break; case InterceptType.OnCatch: OnCatch (info); break; case InterceptType.OnFinally: OnFinally (info); break; } }
protected override void AfterCall(InterceptCallInfo info) { if (!IsEnabled) return; IDictionary cache = GetCache(info); lock (cache.SyncRoot) { CompoundValue key = (CompoundValue)info.Items["CacheKey"]; if (key == null) return; int maxCacheTime = MaxCacheTime; bool isWeak = IsWeak; if (!string.IsNullOrEmpty(info.ConfigString)) { ConfigParameters cp = GetConfigParameters(info); if (cp.MaxCacheTime != null) maxCacheTime = (int) cp.MaxCacheTime; if (cp.IsWeak != null) isWeak = (bool)cp.IsWeak; } CacheAspectItem item = new CacheAspectItem(); item.ReturnValue = info.ReturnValue; item.MaxCacheTime = maxCacheTime == int.MaxValue || maxCacheTime < 0? DateTime.MaxValue: DateTime.Now.AddMilliseconds(maxCacheTime); ParameterInfo[] pis = info.CallMethodInfo.Parameters; int n = 0; foreach (ParameterInfo pi in pis) if (pi.ParameterType.IsByRef) n++; if (n > 0) { item.RefValues = new object[n]; n = 0; for (int i = 0; i < pis.Length; i++) if (pis[i].ParameterType.IsByRef) item.RefValues[n++] = info.ParameterValues[i]; } cache[key] = isWeak? (object)new WeakReference(item): item; } }
protected override void BeforeCall(InterceptCallInfo info) { if (!IsEnabled || Thread.GetData(_counterSlot) != null) { return; } _counter.RegisterCall(info); Thread.SetData(_counterSlot, _counter); }
protected override void BeforeCall(InterceptCallInfo info) { if (!IsEnabled || Thread.GetData(counterSlot) != null) return; MethodCallCounter counter = GetCounter(info); lock (counter.CurrentCalls.SyncRoot) counter.CurrentCalls.Add(info); Thread.SetData(counterSlot, counter); }
protected override void OnFinally(InterceptCallInfo info) { if (IsEnabled) { _parameters.FileName = _instanceFileName ?? FileName; _parameters.MinCallTime = _instanceMinCallTime ?? MinCallTime; _parameters.LogExceptions = _instanceLogExceptions ?? LogExceptions; _parameters.LogParameters = _instanceLogParameters ?? LogParameters; LogOperation(info, _parameters); } }
protected override void OnFinally(InterceptCallInfo info) { if (IsEnabled) { _parameters.FileName = _instanceFileName ?? FileName; _parameters.MinCallTime = _instanceMinCallTime ?? MinCallTime; _parameters.LogExceptions = _instanceLogExceptions ?? LogExceptions; _parameters.LogParameters = _instanceLogParameters ?? LogParameters; LogOperation(info, _parameters); } }
public void Intercept(InterceptCallInfo info) { switch (info.InterceptType) { case InterceptType.BeforeCall: BeforeCall(info); break; case InterceptType.AfterCall: AfterCall(info); break; case InterceptType.OnCatch: OnCatch(info); break; case InterceptType.OnFinally: OnFinally(info); break; } }
protected override void BeforeCall(InterceptCallInfo info) { if (!IsEnabled || Thread.GetData(counterSlot) != null) { return; } MethodCallCounter counter = GetCounter(info); lock (counter.CurrentCalls.SyncRoot) counter.CurrentCalls.Add(info); Thread.SetData(counterSlot, counter); }
protected override void OnFinally(InterceptCallInfo info) { if (!IsEnabled) return; MethodCallCounter prev = (MethodCallCounter)Thread.GetData(_counterSlot); if (_counter == prev) { _counter.UnregisterCall(info); Thread.SetData(_counterSlot, null); } }
protected override void OnFinally(InterceptCallInfo info) { if (!IsEnabled) { return; } MethodCallCounter prev = (MethodCallCounter)Thread.GetData(_counterSlot); if (_counter == prev) { _counter.UnregisterCall(info); Thread.SetData(_counterSlot, null); } }
private static void LogOperationInternal(InterceptCallInfo info, Parameters parameters) { DateTime end = DateTime.Now; int time = (int)((end - info.BeginCallTime).TotalMilliseconds); if (info.Exception != null && parameters.LogExceptions || info.Exception == null && time >= parameters.MinCallTime) { string callParameters = null; int plen = info.ParameterValues.Length; if (parameters.LogParameters && plen > 0) { StringBuilder sb = new StringBuilder(); object[] values = info.ParameterValues; FormatParameter(values[0], sb); for (int i = 1; i < plen; i++) { FormatParameter(values[i], sb.Append(", ")); } callParameters = sb.ToString(); } string exText = null; if (info.Exception != null) { exText = string.Format( " with exception '{0}' - \"{1}\"", info.Exception.GetType().FullName, info.Exception.Message); } LogOutput( string.Format("{0}: {1}.{2}({3}) - {4} ms{5}{6}.", end, info.CallMethodInfo.MethodInfo.DeclaringType.FullName, info.CallMethodInfo.MethodInfo.Name, callParameters, time, info.Cached? " from cache": null, exText), parameters.FileName); } }
protected override void OnFinally(InterceptCallInfo info) { if (!IsEnabled) return; MethodCallCounter counter = GetCounter(info); MethodCallCounter prev = (MethodCallCounter)Thread.GetData(counterSlot); if (counter == prev) { counter.AddCall(DateTime.Now - info.BeginCallTime, info.Exception != null, info.Cached); lock (counter.CurrentCalls.SyncRoot) counter.CurrentCalls.Remove(info); Thread.SetData(counterSlot, null); } }
public void Test() { try { var info = new InterceptCallInfo(); info.ParameterValues = new object[2]; info.ParameterValues[0] = "123"; info.ParameterValues[1] = 123; throw new ApplicationException(); } catch (Exception ex) { Console.WriteLine(ex); Console.WriteLine(ex); throw; } }
protected override void OnFinally(InterceptCallInfo info) { if (!IsEnabled) { return; } MethodCallCounter counter = GetCounter(info); MethodCallCounter prev = (MethodCallCounter)Thread.GetData(counterSlot); if (counter == prev) { counter.AddCall(DateTime.Now - info.BeginCallTime, info.Exception != null, info.Cached); lock (counter.CurrentCalls.SyncRoot) counter.CurrentCalls.Remove(info); Thread.SetData(counterSlot, null); } }
protected override void BeforeCall(InterceptCallInfo info) { if (!IsEnabled) { return; } IDictionary cache = GetCache(info); lock (cache.SyncRoot) { CompoundValue key = GetKey(info); CacheAspectItem item = GetItem(cache, key); if (item != null && !item.IsExpired) { info.InterceptResult = InterceptResult.Return; info.ReturnValue = item.ReturnValue; if (item.RefValues != null) { ParameterInfo[] pis = info.CallMethodInfo.Parameters; int n = 0; for (int i = 0; i < pis.Length; i++) { if (pis[i].ParameterType.IsByRef) { info.ParameterValues[i] = item.RefValues[n++]; } } } info.Cached = true; } else { info.Items["CacheKey"] = key; } } }
protected override void BeforeCall(InterceptCallInfo info) { if (!IsEnabled) { return; } var cache = Cache; lock (cache.SyncRoot) { var key = GetKey(info); var item = GetItem(cache, key); if (item != null && !item.IsExpired) { info.InterceptResult = InterceptResult.Return; info.ReturnValue = item.ReturnValue; if (item.RefValues != null) { var pis = info.CallMethodInfo.Parameters; var n = 0; for (var i = 0; i < pis.Length; i++) { if (pis[i].ParameterType.IsByRef) { info.ParameterValues[i] = item.RefValues[n++]; } } } info.Cached = true; } else { info.Items["CacheKey"] = key; } } }
private static void SetReturnFromCache(InterceptCallInfo info, CacheAspectItem item) { info.InterceptResult = InterceptResult.Return; info.ReturnValue = item.ReturnValue; if (item.RefValues != null) { var pis = info.CallMethodInfo.Parameters; var n = 0; for (var i = 0; i < pis.Length; i++) { if (pis[i].ParameterType.IsByRef) { info.ParameterValues[i] = item.RefValues[n++]; } } } info.Cached = true; }
protected override void BeforeCall(InterceptCallInfo info) { if (!IsEnabled) { return; } var cache = Cache; var key = GetKey(info); var item = GetItem(cache, key); if (item != null && !item.IsExpired) { SetReturnFromCache(info, item); return; } try { Lock(); item = GetItem(cache, key); if (item != null && !item.IsExpired) { SetReturnFromCache(info, item); EndLock(); } else { info.Items["CacheKey"] = key; } } catch { EndLock(); throw; } }
private static MethodCallCounter GetCounter(InterceptCallInfo info) { if (info.CallMethodInfo.Counter == null) { lock (_counters.SyncRoot) if (info.CallMethodInfo.Counter == null) { foreach (MethodCallCounter c in _counters) { if (c.InterceptorID == info.InterceptorID) { return(info.CallMethodInfo.Counter = c); } } _counters.Add(info.CallMethodInfo.Counter = CreateCounter(info.CallMethodInfo)); info.CallMethodInfo.Counter.InterceptorID = info.InterceptorID; } } return(info.CallMethodInfo.Counter); }
// BVChanges: static -> virtual protected /*static*/ virtual CompoundValue GetKey(InterceptCallInfo info) { ParameterInfo[] parInfo = info.CallMethodInfo.Parameters; object[] parValues = info.ParameterValues; object[] keyValues = new object[parValues.Length]; bool[] cacheParams = info.CallMethodInfo.CacheableParameters; if (cacheParams == null) { info.CallMethodInfo.CacheableParameters = cacheParams = new bool[parInfo.Length]; for (int i = 0; i < parInfo.Length; i++) { cacheParams[i] = IsCacheableParameterType(parInfo[i].ParameterType); } } for (int i = 0; i < parValues.Length; i++) { keyValues[i] = cacheParams[i] ? parValues[i] : null; } return(new CompoundValue(keyValues)); }
protected static CompoundValue GetKey(InterceptCallInfo info) { var parInfo = info.CallMethodInfo.Parameters; var parValues = info.ParameterValues; var keyValues = new object[parValues.Length]; var cacheParams = info.CallMethodInfo.CacheableParameters; if (cacheParams == null) { info.CallMethodInfo.CacheableParameters = cacheParams = new bool[parInfo.Length]; for (var i = 0; i < parInfo.Length; i++) { cacheParams[i] = IsCacheableParameterType(parInfo[i].ParameterType); } } for (var i = 0; i < parValues.Length; i++) { keyValues[i] = cacheParams[i] ? parValues[i] : null; } return(new CompoundValue(keyValues)); }
public virtual void RegisterCall(InterceptCallInfo info) { lock (_currentCalls.SyncRoot) _currentCalls.Add(info); }
protected override void OnFinally(InterceptCallInfo info) { if (IsEnabled) LogOperation(info); }
protected virtual CacheAspectItem CreateCacheItem(InterceptCallInfo info) { return(new CacheAspectItem()); }
protected override void BeforeCall(InterceptCallInfo info) { info.Items["ReturnValue"] = info.ReturnValue; }
protected virtual CacheAspectItem CreateCacheItem(InterceptCallInfo info) { return new CacheAspectItem(); }
protected override void OnFinally(InterceptCallInfo info) { EndLock(); base.OnFinally(info); }
private static void LogOperationInternal(InterceptCallInfo info, Parameters parameters) { DateTime end = DateTime.Now; int time = (int)((end - info.BeginCallTime).TotalMilliseconds); if (info.Exception != null && parameters.LogExceptions || info.Exception == null && time >= parameters.MinCallTime) { string callParameters = null; int plen = info.ParameterValues.Length; if (parameters.LogParameters && plen > 0) { StringBuilder sb = new StringBuilder(); object[] values = info.ParameterValues; FormatParameter(values[0], sb); for (int i = 1; i < plen; i++) { FormatParameter(values[i], sb.Append(", ")); } callParameters = sb.ToString(); } string exText = null; if (info.Exception != null) exText = string.Format( " with exception '{0}' - \"{1}\"", info.Exception.GetType().FullName, info.Exception.Message); LogOutput( string.Format("{0}: {1}.{2}({3}) - {4} ms{5}{6}.", end, info.CallMethodInfo.MethodInfo.DeclaringType.FullName, info.CallMethodInfo.MethodInfo.Name, callParameters, time, info.Cached? " from cache": null, exText), parameters.FileName); } }
private static MethodCallCounter GetCounter(InterceptCallInfo info) { if (info.CallMethodInfo.Counter == null) lock (_counters.SyncRoot) if (info.CallMethodInfo.Counter == null) { foreach (MethodCallCounter c in _counters) if (c.InterceptorID == info.InterceptorID) return info.CallMethodInfo.Counter = c; _counters.Add(info.CallMethodInfo.Counter = CreateCounter(info.CallMethodInfo)); info.CallMethodInfo.Counter.InterceptorID = info.InterceptorID; } return info.CallMethodInfo.Counter; }
protected virtual void OnFinally(InterceptCallInfo info) { }
protected override void AfterCall(InterceptCallInfo info) { if (!IsEnabled) return; var cache = Cache; lock (cache.SyncRoot) { var key = (CompoundValue)info.Items["CacheKey"]; if (key == null) return; var maxCacheTime = _instanceMaxCacheTime ?? MaxCacheTime; var isWeak = _instanceIsWeak ?? IsWeak; var item = new CacheAspectItem { ReturnValue = info.ReturnValue, MaxCacheTime = maxCacheTime == int.MaxValue || maxCacheTime < 0 ? DateTime.MaxValue : DateTime.Now.AddMilliseconds(maxCacheTime), }; var pis = info.CallMethodInfo.Parameters; var n = 0; foreach (var pi in pis) if (pi.ParameterType.IsByRef) n++; if (n > 0) { item.RefValues = new object[n]; n = 0; for (var i = 0; i < pis.Length; i++) if (pis[i].ParameterType.IsByRef) item.RefValues[n++] = info.ParameterValues[i]; } cache[key] = isWeak? (object)new WeakReference(item): item; } }
public virtual void UnregisterCall(InterceptCallInfo info) { AddCall(DateTime.Now - info.BeginCallTime, info.Exception != null, info.Cached); lock (_currentCalls.SyncRoot) _currentCalls.Remove(info); }
protected static CompoundValue GetKey(InterceptCallInfo info) { var parInfo = info.CallMethodInfo.Parameters; var parValues = info.ParameterValues; var keyValues = new object[parValues.Length]; var cacheParams = info.CallMethodInfo.CacheableParameters; if (cacheParams == null) { info.CallMethodInfo.CacheableParameters = cacheParams = new bool[parInfo.Length]; for (var i = 0; i < parInfo.Length; i++) cacheParams[i] = IsCacheableParameterType(parInfo[i].ParameterType); } for (var i = 0; i < parValues.Length; i++) keyValues[i] = cacheParams[i] ? parValues[i] : null; return new CompoundValue(keyValues); }
public virtual void RegisterCall(InterceptCallInfo info) { lock (_currentCalls.SyncRoot) _currentCalls.Add(info); }
protected virtual IDictionary GetCache(InterceptCallInfo info) { return info.CallMethodInfo.MethodCallCache; }
private static void SetReturnFromCache(InterceptCallInfo info, CacheAspectItem item) { info.InterceptResult = InterceptResult.Return; info.ReturnValue = item.ReturnValue; if (item.RefValues != null) { var pis = info.CallMethodInfo.Parameters; var n = 0; for (var i = 0; i < pis.Length; i++) if (pis[i].ParameterType.IsByRef) info.ParameterValues[i] = item.RefValues[n++]; } info.Cached = true; }
protected override void BeforeCall(InterceptCallInfo info) { if (!IsEnabled) return; var cache = Cache; var key = GetKey(info); var item = GetItem(cache, key); if (item != null && !item.IsExpired) { SetReturnFromCache(info, item); return; } try { Lock(); item = GetItem(cache, key); if (item != null && !item.IsExpired) { SetReturnFromCache(info, item); EndLock(); } else { info.Items["CacheKey"] = key; } } catch { EndLock(); throw; } }
protected override void AfterCall(InterceptCallInfo info) { info.ReturnValue = (int)info.ReturnValue + (int)info.Items["ReturnValue"]; }
private static void LogOperationInternal(InterceptCallInfo info) { string fileName = FileName; int minCallTime = MinCallTime; bool logExceptions = LogExceptions; bool logParameters = LogParameters; if (!string.IsNullOrEmpty(info.ConfigString)) { ConfigParameters cp = GetConfigParameters(info); if (cp.FileName != null) fileName = cp.FileName.ToString(); if (cp.MinCallTime != null) minCallTime = (int) cp.MinCallTime; if (cp.LogExceptions != null) logExceptions = (bool)cp.LogExceptions; if (cp.LogParameters != null) logParameters = (bool)cp.LogParameters; } DateTime end = DateTime.Now; int time = (int)((end - info.BeginCallTime).TotalMilliseconds); if (info.Exception != null && logExceptions || info.Exception == null && time >= minCallTime) { string parameters = null; int plen = info.ParameterValues.Length; if (logParameters && plen > 0) { string[] pvs = new string[plen]; object[] values = info.ParameterValues; for (int i = 0; i < plen; i++) { object o = values[i]; pvs[i] = o == null? "<null>": o is string? "\"" + o + "\"": o is char? "'" + o + "'": o.ToString(); } parameters = string.Join(", ", pvs); } string exText = null; if (info.Exception != null) exText = string.Format( " with exception '{0}' - \"{1}\"", info.Exception.GetType().FullName, info.Exception.Message); LogOutput( string.Format("{0}: {1}.{2}({3}) - {4} ms{5}.", end, info.CallMethodInfo.MethodInfo.DeclaringType.FullName, info.CallMethodInfo.MethodInfo.Name, parameters, time, exText), fileName); } }
protected virtual void OnFinally (InterceptCallInfo info) {}
private static ConfigParameters GetConfigParameters(InterceptCallInfo info) { ConfigParameters cp = info.CallMethodInfo.CacheParameters; if (cp == null) { info.CallMethodInfo.CacheParameters = cp = new ConfigParameters(); string[] ps = info.ConfigString.Split(';'); foreach (string p in ps) { string[] vs = p.Split('='); if (vs.Length == 2) { switch (vs[0].ToLower().Trim()) { case "maxcachetime": cp.MaxCacheTime = int. Parse(vs[1].Trim()); break; case "isweak": cp.IsWeak = bool.Parse(vs[1].Trim()); break; } } } } return cp; }
protected virtual void AfterCall (InterceptCallInfo info) {}
protected virtual void BeforeCall(InterceptCallInfo info) { }
protected virtual void AfterCall(InterceptCallInfo info) { }
private static void LogOperationInternal(InterceptCallInfo info) { string fileName = FileName; int minCallTime = MinCallTime; bool logExceptions = LogExceptions; bool logParameters = LogParameters; if (!string.IsNullOrEmpty(info.ConfigString)) { ConfigParameters cp = GetConfigParameters(info); if (cp.FileName != null) { fileName = cp.FileName.ToString(); } if (cp.MinCallTime != null) { minCallTime = (int)cp.MinCallTime; } if (cp.LogExceptions != null) { logExceptions = (bool)cp.LogExceptions; } if (cp.LogParameters != null) { logParameters = (bool)cp.LogParameters; } } DateTime end = DateTime.Now; int time = (int)((end - info.BeginCallTime).TotalMilliseconds); if (info.Exception != null && logExceptions || info.Exception == null && time >= minCallTime) { string parameters = null; int plen = info.ParameterValues.Length; if (logParameters && plen > 0) { string[] pvs = new string[plen]; object[] values = info.ParameterValues; for (int i = 0; i < plen; i++) { object o = values[i]; pvs[i] = o == null? "<null>": o is string? "\"" + o + "\"" : o is char? "'" + o + "'" : o.ToString(); } parameters = string.Join(", ", pvs); } string exText = null; if (info.Exception != null) { exText = string.Format( " with exception '{0}' - \"{1}\"", info.Exception.GetType().FullName, info.Exception.Message); } LogOutput( string.Format("{0}: {1}.{2}({3}) - {4} ms{5}.", end, info.CallMethodInfo.MethodInfo.DeclaringType.FullName, info.CallMethodInfo.MethodInfo.Name, parameters, time, exText), fileName); } }
protected virtual void OnCatch(InterceptCallInfo info) { }
protected virtual void OnCatch (InterceptCallInfo info) {}
protected virtual IDictionary GetCache(InterceptCallInfo info) { return(info.CallMethodInfo.MethodCallCache); }
protected override void OnFinally(InterceptCallInfo info) { EndLock(); base.OnFinally(info); }
protected override void AfterCall(InterceptCallInfo info) { if (!IsEnabled) { return; } IDictionary cache = GetCache(info); lock (cache.SyncRoot) { CompoundValue key = (CompoundValue)info.Items["CacheKey"]; if (key == null) { return; } int maxCacheTime = MaxCacheTime; bool isWeak = IsWeak; if (!string.IsNullOrEmpty(info.ConfigString)) { ConfigParameters cp = GetConfigParameters(info); if (cp.MaxCacheTime != null) { maxCacheTime = (int)cp.MaxCacheTime; } if (cp.IsWeak != null) { isWeak = (bool)cp.IsWeak; } } CacheAspectItem item = new CacheAspectItem(); item.ReturnValue = info.ReturnValue; item.MaxCacheTime = maxCacheTime == int.MaxValue || maxCacheTime < 0? DateTime.MaxValue: DateTime.Now.AddMilliseconds(maxCacheTime); ParameterInfo[] pis = info.CallMethodInfo.Parameters; int n = 0; foreach (ParameterInfo pi in pis) { if (pi.ParameterType.IsByRef) { n++; } } if (n > 0) { item.RefValues = new object[n]; n = 0; for (int i = 0; i < pis.Length; i++) { if (pis[i].ParameterType.IsByRef) { item.RefValues[n++] = info.ParameterValues[i]; } } } cache[key] = isWeak? (object)new WeakReference(item): item; } }