예제 #1
0
파일: LockData.cs 프로젝트: Eden33/Sync
 public bool Equals(LockData d)
 {
     if ((object)d == null)
     {
         return false;
     }
     return (login.Equals(d.login)) && (mode.Equals(d.mode));
 }
예제 #2
0
파일: LockManager.cs 프로젝트: Eden33/Sync
 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;
 }
예제 #3
0
파일: LockManager.cs 프로젝트: Eden33/Sync
        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;
        }