コード例 #1
0
        public void Handle(AcquireFileLockCommand command)
        {
            File file = fileRepository.GetById(command.FileId).EnsureFound(command.FileId);

            User currentUser = currentUserSource.GetCurrentUser();

            if (!file.CanBeModifiedBy(currentUser))
            {
                throw new PermissionException($"The user doesn't have a permission to lock the file with id {command.FileId}");
            }

            fileLockingService.Lock(file, currentUser);
            UserDto lockOwner = fileLockingService.GetLockOwner(file);

            eventBus.PublishAfterCommit <FileLockChangedEvent, FileLockChangedMessage>(
                new FileLockChangedMessage(command.FileId, FileLockDto.ForUser(lockOwner)));
        }
コード例 #2
0
        private void ProcessLockExpiry(object sender, ElapsedEventArgs e)
        {
            logger.LogDebug($"ProcessLockExpiry");
            lock (@lock)
            {
                if (!expiryDatesByFileId.Any() || expiryDatesByFileId.First.ExpiryDate > DateTime.UtcNow)
                {
                    ResetInterval();
                    return;
                }

                var expiredLockInfo = expiryDatesByFileId.Dequeue();
                eventBus.Publish <FileLockChangedEvent, FileLockChangedMessage>(
                    new FileLockChangedMessage(expiredLockInfo.FileId, FileLockDto.NoLock()));
                ResetInterval();
            }
        }
コード例 #3
0
        public void Handle(RemoveFileLockCommand command)
        {
            File file = fileRepository.GetById(command.FileId);

            UserDto lockOwner = fileLockingService.GetRequiredLockOwner(file);

            if (lockOwner.Id != currentUser.Id)
            {
                throw new PermissionException("The current user is not the lock owner");
            }

            fileLockingService.Unlock(file, currentUser.ToDomainUser());

            UserDto newLockOwner = fileLockingService.GetLockOwner(file);

            eventBus.PublishAfterCommit <FileLockChangedEvent, FileLockChangedMessage>(
                new FileLockChangedMessage(command.FileId, FileLockDto.ForUser(newLockOwner)));
        }
コード例 #4
0
 public FileLockChangedMessage(string fileId, FileLockDto newLock)
 {
     FileId  = fileId;
     NewLock = newLock;
 }