public override void OnInvoke(PostSharp.Aspects.MethodInterceptionArgs args)
        {
            LockObject t = null;

            if (_typeLock.TryGetValue(instanceType, out t))
            {
                if (Monitor.TryEnter(t, _acquireLockTimeout))
                {
                    try
                    {
                        Debug.WriteLine("Entering for " + instanceType + " Lock: " + t.Guid.ToString());
                        args.Proceed();
                    }
                    finally
                    {
                        Debug.WriteLine("Completed blocking" + instanceType + " Lock: " + t.Guid.ToString());
                        Monitor.Exit(t);
                    }
                }
            }
            else
            {
                throw new InvalidOperationException("Lock object not found for " + instanceType);
            }
        }
コード例 #2
0
        public override void OnInvoke(PostSharp.Aspects.MethodInterceptionArgs args)
        {
            string exContext = string.Format(System.Globalization.CultureInfo.InvariantCulture, _context, args.Arguments.ToArray());

            using (log4net.ThreadContext.Stacks[Zieschang.Net.Projects.PostsharpAspects.Utilities.LogHelper.DefaultLoggerContextStack].Push(exContext))
            {
                args.Proceed();
            }
        }
コード例 #3
0
        public override void OnInvoke(PostSharp.Aspects.MethodInterceptionArgs args)
        {
            int    counter  = 0;
            object instance = args.Instance;

            log4net.ILog lg = null;
            if (_staticInstanceField == null)
            {
                lg = InternalFieldFinder.Instance.GetInstance <log4net.ILog>(args.Method, instance);
            }
            else
            {
                lg = _staticInstanceField;
            }
            do
            {
                //delay on each cycle before continue
                //in future use a strategy
                if (counter > 0 && RetryDelay > 0)
                {
                    System.Threading.Thread.Sleep(RetryDelay);
                }
                counter++;
                try
                {
                    args.Proceed();
                    counter = Int32.MaxValue;
                }
                catch (Exception ex)
                {
                    if (ExceptionFilterType == null || ExceptionFilterType.IsAssignableFrom(ex.GetType()))
                    {
                        if (counter < _maxRetries)
                        {
                            lg.Info(string.Format(System.Globalization.CultureInfo.InvariantCulture, _retryMessage, counter), ex);
                        }
                        else
                        {
                            string msg = string.Format(System.Globalization.CultureInfo.InvariantCulture, _failureMessage, counter);
                            if (!string.IsNullOrEmpty(_message))
                            {
                                msg = Message + " " + msg;
                            }
                            lg.Error(msg, ex);
                            if (_raiseAfterRetries)
                            {
                                throw;
                            }
                        }
                    }
                }
            } while (counter < _maxRetries);
        }