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))); }
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(); } }
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))); }
public FileLockChangedMessage(string fileId, FileLockDto newLock) { FileId = fileId; NewLock = newLock; }