Ejemplo n.º 1
0
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        /// <exception cref="ArgumentException"></exception>
        internal DataStream(
            IDataStreamStructureBuilder streamStructureBuilder,
            int blockSize,
            IFileSystemLockReleaseManager lockingManager,
            Guid idOfLockBeingHeld)
        {
            try
            {
                if (streamStructureBuilder == null)
                {
                    throw new ArgumentNullException("streamStructureBuilder");
                }
                if (lockingManager == null)
                {
                    throw new ArgumentNullException("lockingManager");
                }
                MethodArgumentValidator.ThrowIfIsDefault(idOfLockBeingHeld, "idOfLockBeingHeld");
                MethodArgumentValidator.ThrowIfNegative(blockSize, "blockSize");

                _streamStructureBuilder = streamStructureBuilder;
                _blockSize           = blockSize;
                _lockingManager      = lockingManager;
                _idOfLockBeingHeld   = idOfLockBeingHeld;
                _diskBlockEnumerator = streamStructureBuilder.CreateEnumerator();
            }
            catch (Exception)
            {
                GC.SuppressFinalize(this);

                throw;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <exception cref="LockNotFoundException"></exception>
        /// <exception cref="ArgumentNullException"></exception>
        public void ReleaseLock(Guid associatedLockId)
        {
            MethodArgumentValidator.ThrowIfIsDefault <Guid>(associatedLockId, "associatedLockId");
            bool removedSuccessfully = _idsOfAssociatedFileLocks.Remove(associatedLockId);

            if (!removedSuccessfully)
            {
                throw new LockNotFoundException("Блокировка с идентификатором {0} не найдена.".FormatWith(associatedLockId));
            }
        }
Ejemplo n.º 3
0
        public FolderNode(string name, Guid id, int diskBlockIndex, int parentFolderBlockReference, DataStreamDefinition fileReferencesStreamDefinition, DataStreamDefinition folderReferencesStreamDefinition, DateTime creationTime, Guid version)
            : base(name, id, diskBlockIndex, version, creationTime)
        {
            MethodArgumentValidator.ThrowIfNull(fileReferencesStreamDefinition, "fileReferencesStream");
            MethodArgumentValidator.ThrowIfNull(folderReferencesStreamDefinition, "folderReferencesStream");
            MethodArgumentValidator.ThrowIfNegative(parentFolderBlockReference, "parentFolderBlockReference");
            MethodArgumentValidator.ThrowIfNegative(diskBlockIndex, "diskBlockIndex");
            MethodArgumentValidator.ThrowIfIsDefault(id, "id");

            _fileReferencesStreamDefinition   = fileReferencesStreamDefinition;
            _folderReferencesStreamDefinition = folderReferencesStreamDefinition;
            _parentFolderBlockReference       = parentFolderBlockReference;
        }
Ejemplo n.º 4
0
        public FileNode(string name, Guid id, int diskBlockIndex, DataStreamDefinition fileContentsStreamDefinition, DateTime lastModificationTimeUtc, DateTime creationTimeUtc, Guid version)
            : base(name, id, diskBlockIndex, version, creationTimeUtc)
        {
            if (fileContentsStreamDefinition == null)
            {
                throw new ArgumentNullException("fileContentsStreamDefinition");
            }
            MethodArgumentValidator.ThrowIfIsDefault <DateTime>(lastModificationTimeUtc, "lastModificationTimeUtc");
            MethodArgumentValidator.ThrowIfDateIsNonUtc(lastModificationTimeUtc, "lastModificationTimeUtc");

            _fileContentsStreamDefinition = fileContentsStreamDefinition;
            _lastModificationTimeUtc      = lastModificationTimeUtc;
        }
Ejemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <param name="id"></param>
        /// <param name="diskBlockIndex"></param>
        /// <param name="version"></param>
        /// <param name="creationTimeUtc"></param>
        /// <exception cref="InvalidNameException"></exception>
        protected Node(string name, Guid id, int diskBlockIndex, Guid version, DateTime creationTimeUtc)
        {
            MethodArgumentValidator.ThrowIfIsDefault <Guid>(version, "version");
            MethodArgumentValidator.ThrowIfIsDefault <Guid>(id, "id");
            MethodArgumentValidator.ThrowIfIsDefault <DateTime>(creationTimeUtc, "creationTimeUtc");
            MethodArgumentValidator.ThrowIfDateIsNonUtc(creationTimeUtc, "creationTimeUtc");

            this.InitializeValidator();

            _nameValidator.Validate(name);

            _creationTimeUtc = creationTimeUtc;
            _diskBlockIndex  = diskBlockIndex;
            _id      = id;
            _version = version;
            _name    = name;
        }
Ejemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="associatedFileLock"></param>
        /// <param name="lockId"></param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="LockAlreadyHeldException"></exception>
        /// <exception cref="ArgumentException"></exception>
        public void AddLock(FileLockable associatedFileLock, Guid lockId)
        {
            if (associatedFileLock == null)
            {
                throw new ArgumentNullException("associatedFileLock");
            }
            MethodArgumentValidator.ThrowIfIsDefault <Guid>(lockId, "lockId");

            if (_idsOfAssociatedFileLocks.Contains(lockId))
            {
                throw new LockAlreadyHeldException("Блокировка с идентификатором {0} уже привязана к блокировке папки.".FormatWith(associatedFileLock.FileId));
            }

            if (!associatedFileLock.IdsOfParentFoldersUpToRoot.Contains(_idOfLockedNode))
            {
                throw new ArgumentException("Папка (идентификатор - {0}) не содержится в списке зависимых для файловой блокировки, которую вы хотите связать с блокировкой этой папки.".FormatWith(_idOfLockedNode));
            }

            _idsOfAssociatedFileLocks.Add(lockId);
        }
Ejemplo n.º 7
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));
                }
            }
        }