예제 #1
0
        public static ILockMechanism RestoreDefaultLockMechanism()
        {
            ILockMechanism previous = Default;

            Default = _originalDefaultLockMechanism;
            return(previous);
        }
예제 #2
0
        public static void Do(object syncRoot, ILockMechanism lockMechanism, Action action)
        {
            if (lockMechanism == null)
            {
                throw new ArgumentNullException("lockMechanism");
            }

            object workingSyncRoot = null;

            try
            {
                workingSyncRoot = lockMechanism.OnBegin(syncRoot, action);
            }
            catch (Exception beginEx)
            {
                throw new LockMechanismException(LockMechanismStage.OnBegin, lockMechanism, beginEx);
            }

            try
            {
                action();
            }
            finally
            {
                try
                {
                    lockMechanism.OnEnd(workingSyncRoot);
                }
                catch (Exception endEx)
                {
                    throw new LockMechanismException(LockMechanismStage.OnEnd, lockMechanism, endEx);
                }
            }
        }
예제 #3
0
        public static void SetDefaultLockMechanism(ILockMechanism defaultLockMechanism)
        {
            if (defaultLockMechanism == null)
            {
                throw new ArgumentNullException("defaultLockMechanism");
            }

            Default = defaultLockMechanism;
        }
예제 #4
0
 static Locks()
 {
     SetDefaultLockMechanism(Standard);
     _originalDefaultLockMechanism = Default;
 }
예제 #5
0
 public LockMechanismException(LockMechanismStage stage, ILockMechanism lockMechanism, Exception innerException)
     : base(string.Format("{0} ({1})", stage, lockMechanism.GetType().FullName), innerException)
 {
 }