public static ILockMechanism RestoreDefaultLockMechanism() { ILockMechanism previous = Default; Default = _originalDefaultLockMechanism; return(previous); }
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); } } }
public static void SetDefaultLockMechanism(ILockMechanism defaultLockMechanism) { if (defaultLockMechanism == null) { throw new ArgumentNullException("defaultLockMechanism"); } Default = defaultLockMechanism; }
static Locks() { SetDefaultLockMechanism(Standard); _originalDefaultLockMechanism = Default; }
public LockMechanismException(LockMechanismStage stage, ILockMechanism lockMechanism, Exception innerException) : base(string.Format("{0} ({1})", stage, lockMechanism.GetType().FullName), innerException) { }