public override async Task <WopiResponse> UnlockAndRelock(UnlockAndRelockRequest unlockAndRelockRequest) { var userId = WopiSecurity.GetIdentityNameFromToken(unlockAndRelockRequest.AccessToken); var wopiFileRepository = new WopiFileRepository(); var response = await wopiFileRepository.LockFile(unlockAndRelockRequest.ResourceId, userId, unlockAndRelockRequest.Lock, unlockAndRelockRequest.OldLock); if (response.Item1 == HttpStatusCode.BadRequest) { return(unlockAndRelockRequest.ResponseBadRequest()); } // Check for file not found or no permissions else if (response.Item1 == HttpStatusCode.NotFound) { return(unlockAndRelockRequest.ResponseNotFound()); } // Ensure the file isn't already locked else if (response.Item1 == HttpStatusCode.Conflict) { return(unlockAndRelockRequest.ResponseLockConflict(response.Item2)); } // File successfully locked else if (response.Item1 == HttpStatusCode.OK) { return(unlockAndRelockRequest.ResponseOK()); } else { return(unlockAndRelockRequest.ResponseServerError(string.Format("Unknown HTTPStatusCode from WopiFileRepository.LockFile: {0}", response.Item1))); } }
public override async Task <WopiResponse> UnlockAndRelock(UnlockAndRelockRequest unlockAndRelockRequest) { WopiResponse wopiResponse = null; var file = DocumentDBRepository <DetailedFileModel> .GetItem("Files", i => i.id.ToString() == unlockAndRelockRequest.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 = unlockAndRelockRequest.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 = unlockAndRelockRequest.ResponseLockConflict(String.Empty, "File isn't locked"); } else if (unlockAndRelockRequest.OldLock != file.LockValue) { // File lock mismatch...pass Lock in mismatch response wopiResponse = unlockAndRelockRequest.ResponseLockConflict(file.LockValue, "Lock mismatch"); } else { // Update the file with a LockValue and LockExpiration file.LockValue = unlockAndRelockRequest.Lock; file.LockExpires = DateTime.Now.AddMinutes(30); await DocumentDBRepository <FileModel> .UpdateItemAsync("Files", file.id.ToString(), (FileModel)file); // Return success 200 wopiResponse = unlockAndRelockRequest.ResponseOK(); } } else { wopiResponse = wopiResponse = unlockAndRelockRequest.ResponseNotFound(); } return(wopiResponse); }
public abstract Task <WopiResponse> UnlockAndRelock(UnlockAndRelockRequest unlockRequest);