public override async Task <WopiResponse> RefreshLock(RefreshLockRequest refreshLockRequest)
        {
            var userId = WopiSecurity.GetIdentityNameFromToken(refreshLockRequest.AccessToken);

            var wopiFileRepository = new WopiFileRepository();
            var response           = await wopiFileRepository.LockFile(refreshLockRequest.ResourceId, userId, refreshLockRequest.Lock, null);

            if (response.Item1 == HttpStatusCode.BadRequest)
            {
                return(refreshLockRequest.ResponseBadRequest());
            }
            // Check for file not found or no permissions
            else if (response.Item1 == HttpStatusCode.NotFound)
            {
                return(refreshLockRequest.ResponseNotFound());
            }
            // Ensure the file isn't already locked
            else if (response.Item1 == HttpStatusCode.Conflict)
            {
                return(refreshLockRequest.ResponseLockConflict(response.Item2));
            }
            // File successfully locked
            else if (response.Item1 == HttpStatusCode.OK)
            {
                return(refreshLockRequest.ResponseOK());
            }
            else
            {
                return(refreshLockRequest.ResponseServerError(string.Format("Unknown HTTPStatusCode from WopiFileRepository.LockFile: {0}", response.Item1)));
            }
        }
        public override async Task <WopiResponse> RefreshLock(RefreshLockRequest refreshLockRequest)
        {
            WopiResponse wopiResponse = null;
            var          file         = DocumentDBRepository <DetailedFileModel> .GetItem("Files", i => i.id.ToString() == refreshLockRequest.ResourceId);

            // Check for null file
            if (file != null)
            {
                // Ensure the file has a valid lock
                if (String.IsNullOrEmpty(file.LockValue))
                {
                    // File isn't locked...pass empty Lock in mismatch response
                    wopiResponse = refreshLockRequest.ResponseLockConflict(String.Empty, "File isn't locked");
                }
                else if (file.LockExpires != null && file.LockExpires < DateTime.Now)
                {
                    // File lock expired, so clear it out
                    file.LockValue   = null;
                    file.LockExpires = null;
                    await DocumentDBRepository <FileModel> .UpdateItemAsync("Files", file.id.ToString(), (FileModel)file);

                    // File isn't locked...pass empty Lock in mismatch response
                    wopiResponse = refreshLockRequest.ResponseLockConflict(String.Empty, "File isn't locked");
                }
                else if (refreshLockRequest.Lock != file.LockValue)
                {
                    // File lock mismatch...pass Lock in mismatch response
                    wopiResponse = refreshLockRequest.ResponseLockConflict(file.LockValue, "Lock mismatch");
                }
                else
                {
                    // Extend the expiration
                    file.LockExpires = DateTime.Now.AddMinutes(30);
                    await DocumentDBRepository <FileModel> .UpdateItemAsync("Files", file.id.ToString(), (FileModel)file);

                    // Return success 200
                    wopiResponse = refreshLockRequest.ResponseOK();
                }
            }
            else
            {
                wopiResponse = refreshLockRequest.ResponseNotFound();
            }
            return(wopiResponse);
        }
 public abstract Task <WopiResponse> RefreshLock(RefreshLockRequest refreshLock);