public bool Equals(LockData d) { if ((object)d == null) { return false; } return (login.Equals(d.login)) && (mode.Equals(d.mode)); }
private bool ReleaseLocks(String login, LockMode mode, LockItem item) { bool allLocksReleased = true; foreach(int id in item.IDsToLock) { List<LockData> currentLocks = locks.GetLocksForItem(id, item.ItemType); LockData release = new LockData(login, mode); if(currentLocks.Contains(release)) { currentLocks.Remove(release); locks.UpdateLocksForItem(id, item.ItemType, currentLocks); } else { //this should never be the case! allLocksReleased = false; } } return allLocksReleased; }
private bool SetLocks(String login, LockBatch batch, LockMode mode, LockItem item) { foreach (int id in item.IDsToLock) { List<LockData> currentLocks = locks.GetLocksForItem(id, item.ItemType); LockData newLock = new LockData(login, mode); // for future write-lock development // we have to pass currentLocks as a whole to assure that ll // for this user are present in currentLocks // write locks can only be set if the ll for this user are set foreach(LockData lockData in currentLocks) { if(newLock.Equals(lockData) == false && !LockMatrix.IsModeCompatible(lockData.mode, mode)) { Console.WriteLine("Lock conflict, rollback locks for user: {0}", login); Unlock(login, batch, mode); return false; } } if(currentLocks.Contains(newLock) == false) { currentLocks.Add(newLock); locks.UpdateLocksForItem(id, item.ItemType, currentLocks); } } return true; }