Exemplo n.º 1
0
        private async Task <FileUpdateResult> UpdateFile(Domain.Models.File dbFile, Domain.Models.File file)
        {
            var result = new FileUpdateResult();

            result.LockResult = await _lockService.GetFileLock(dbFile.Id).LockAsync(0);

            // Don't need to update or throw error if contents haven't changed
            if (!dbFile.Content.Equals(file.Content))
            {
                if (!result.LockResult.AcquiredLock)
                {
                    result.UnableToLock = true;
                    result.FileUpdated  = false;
                }
                else if (dbFile.CanLock(_userId, _isAdmin))
                {
                    dbFile.Content = file.Content;
                    dbFile.Save(
                        _userId,
                        _isAdmin,
                        bypassLock: true);

                    result.FileUpdated  = true;
                    result.UnableToLock = false;
                }
                else
                {
                    result.FileUpdated  = false;
                    result.UnableToLock = true;
                }
            }

            return(result);
        }
Exemplo n.º 2
0
            protected override async Task PerformOperation(Domain.Models.File file)
            {
                var isAdmin = await _identityResolver.IsAdminAsync();

                var userId             = _user.GetId();
                var isNotAlreadyLocked = (userId != file.LockedById);

                if (isNotAlreadyLocked)
                {
                    file.Lock(userId, isAdmin);
                }

                try
                {
                    file.Name = _request.Name;
                    file.Save(userId, isAdmin);
                }
                finally
                {
                    if (isNotAlreadyLocked)
                    {
                        file.Unlock(userId);
                    }
                }
            }
Exemplo n.º 3
0
            protected override async Task PerformOperation(Domain.Models.File file)
            {
                await ValidateEntities(file, _request.DirectoryId, _request.WorkspaceId);

                file = _mapper.Map(_request, file);
                file.Save(_user.GetId(), isAdmin: (await _identityResolver.IsAdminAsync()));
            }
Exemplo n.º 4
0
            protected override async Task PerformOperation(Domain.Models.File file)
            {
                var isAdmin = await _identityResolver.IsAdminAsync();

                var userId             = _user.GetId();
                var isNotAlreadyLocked = (userId != file.LockedById);

                if (isNotAlreadyLocked)
                {
                    try
                    {
                        file.Lock(userId, isAdmin);
                    }
                    catch (FileConflictException)
                    {
                        throw new FileConflictException("Cannot rename a file while it's being edited or locked by another user.");
                    }
                }

                try
                {
                    file.Name = _request.Name;
                    file.Save(userId, isAdmin);
                }
                finally
                {
                    if (isNotAlreadyLocked)
                    {
                        file.Unlock(userId);
                    }
                }
            }