private IRedisClient TrackInstance(MethodBase callingMethodType, string method, IRedisClient instance) { // track var frame = new TrackingFrame() { Id = Guid.NewGuid(), Initialised = DateTime.Now, ProvidedToInstanceOfType = callingMethodType.DeclaringType, }; lock (this.trackingFrames) { this.trackingFrames.Add(frame); } // proxy var proxy = new TrackingRedisClientProxy(instance, frame.Id); proxy.BeforeInvoke += (sender, args) => { if (string.Compare("Dispose", args.MethodInfo.Name, StringComparison.InvariantCultureIgnoreCase) != 0) { return; } lock (this.trackingFrames) { this.trackingFrames.Remove(frame); } var duration = DateTime.Now - frame.Initialised; Logger.DebugFormat("{0,18} Disposed {1} released from instance of type {2} checked out for {3}", method, frame.Id, frame.ProvidedToInstanceOfType.FullName, duration); }; Logger.DebugFormat("{0,18} Tracking {1} allocated to instance of type {2}", method, frame.Id, frame.ProvidedToInstanceOfType.FullName); return(proxy.GetTransparentProxy() as IRedisClient); }
private IRedisClient TrackInstance(MethodBase callingMethodType, string method, IRedisClient instance) { // track var frame = new TrackingFrame() { Id = Guid.NewGuid(), Initialised = DateTime.Now, ProvidedToInstanceOfType = callingMethodType.DeclaringType, }; lock (this.trackingFrames) { this.trackingFrames.Add(frame); } // proxy var proxy = new TrackingRedisClientProxy(instance, frame.Id); proxy.BeforeInvoke += (sender, args) => { if (string.Compare("Dispose", args.MethodInfo.Name, StringComparison.InvariantCultureIgnoreCase) != 0) { return; } lock (this.trackingFrames) { this.trackingFrames.Remove(frame); } var duration = DateTime.Now - frame.Initialised; Logger.DebugFormat("{0,18} Disposed {1} released from instance of type {2} checked out for {3}", method, frame.Id, frame.ProvidedToInstanceOfType.FullName, duration); }; Logger.DebugFormat("{0,18} Tracking {1} allocated to instance of type {2}", method, frame.Id, frame.ProvidedToInstanceOfType.FullName); return proxy.GetTransparentProxy() as IRedisClient; }