Пример #1
0
        private void ReportToAllFolderNodesLockableThatTheyHaveANewLock(NodeWithSurroundingsResolvingResult <FileNode> fileToLock, FileLockable fileLockable, Guid newLockId)
        {
            foreach (FolderNode node in fileToLock.FoldersPassedWhileResolving)
            {
                FolderNodeLockable folderNodeLockableToAdjust;

                if (_nodeIdsToLocks.ContainsKey(node.Id))
                {
                    folderNodeLockableToAdjust = _nodeIdsToLocks[node.Id];
                }
                else
                {
                    folderNodeLockableToAdjust = new FolderNodeLockable(node);
                    _nodeIdsToLocks[node.Id]   = folderNodeLockableToAdjust;
                }

                folderNodeLockableToAdjust.AddLock(fileLockable, newLockId);
            }
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="lockId"></param>
        /// <exception cref="ArgumentException"></exception>
        /// <exception cref="LockNotFoundException"></exception>
        public void ReleaseLock(Guid lockId)
        {
            MethodArgumentValidator.ThrowIfIsDefault <Guid>(lockId, "lockId");

            lock (_operationExecutionCriticalSection)
            {
                if (_lockIdsToLocks.ContainsKey(lockId))
                {
                    FileLockable fileLockable = _lockIdsToLocks[lockId];

                    fileLockable.ReleaseLock(lockId);

                    if (fileLockable.IsFreeForTaking)
                    {
                        _fileIdsToLocks.Remove(fileLockable.FileId); // все: файл разблокирован
                    }

                    // еще и все ветки отпускаем - если их больше ничто не держит.
                    foreach (Guid nodeId in fileLockable.IdsOfParentFoldersUpToRoot)
                    {
                        FolderNodeLockable folderNodeLockable = _nodeIdsToLocks[nodeId];

                        folderNodeLockable.ReleaseLock(lockId);

                        if (!folderNodeLockable.IsLocked)
                        {
                            _nodeIdsToLocks.Remove(folderNodeLockable.IdOfLockedNode);
                        }
                    }

                    _lockIdsToLocks.Remove(lockId);
                }
                else
                {
                    throw new LockNotFoundException("Не найдена блокировка с идентификатором {0}".FormatWith(lockId));
                }
            }
        }