public override async Task <WopiResponse> RenameFile(RenameFileRequest renameFileRequest) { WopiResponse wopiResponse = null; var file = DocumentDBRepository <DetailedFileModel> .GetItem("Files", i => i.id.ToString() == renameFileRequest.ResourceId); // Check for null file if (file != null) { // Make sure the X-WOPI-RequestedName header is included if (renameFileRequest.RequestedName != null) { // Ensure the file isn't locked if (String.IsNullOrEmpty(file.LockValue) || (file.LockExpires != null && file.LockExpires < DateTime.Now)) { // Update the file with a LockValue and LockExpiration file.LockValue = renameFileRequest.Lock; file.LockExpires = DateTime.Now.AddMinutes(30); file.BaseFileName = renameFileRequest.RequestedName; await DocumentDBRepository <FileModel> .UpdateItemAsync("Files", file.id.ToString(), (FileModel)file); // Return success 200 wopiResponse = renameFileRequest.ResponseOK(renameFileRequest.RequestedName); } else if (file.LockValue == renameFileRequest.Lock) { // File lock matches existing lock, so we can change the name file.LockExpires = DateTime.Now.AddMinutes(30); file.BaseFileName = renameFileRequest.RequestedName; await DocumentDBRepository <FileModel> .UpdateItemAsync("Files", file.id.ToString(), (FileModel)file); // Return success 200 wopiResponse = renameFileRequest.ResponseOK(renameFileRequest.RequestedName); } else { // The file is locked by someone else...return mismatch wopiResponse = renameFileRequest.ResponseLockConflict(file.LockValue, String.Format("File locked by {0}", file.LockValue)); } } else { // X-WOPI-RequestedName header wasn't included wopiResponse = renameFileRequest.ResponseBadRequest("X-WOPI-RequestedName header wasn't included in request"); } } else { wopiResponse = renameFileRequest.ResponseNotFound(); } return(wopiResponse); }
public override async Task <WopiResponse> RenameFile(RenameFileRequest renameFileRequest) { var userId = WopiSecurity.GetIdentityNameFromToken(renameFileRequest.AccessToken); var wopiFileRepository = new WopiFileRepository(); var response = await wopiFileRepository.RenameFile(renameFileRequest.ResourceId, userId, renameFileRequest.Lock, renameFileRequest.RequestedName); if (response.Item1 == HttpStatusCode.NotFound) { return(renameFileRequest.ResponseNotFound()); } else if (response.Item1 == HttpStatusCode.Conflict) { return(renameFileRequest.ResponseLockConflict(response.Item2)); } else if (response.Item1 == HttpStatusCode.BadRequest) { return(renameFileRequest.ResponseBadRequest(response.Item2)); } else if (response.Item1 == HttpStatusCode.OK) { return(renameFileRequest.ResponseOK(response.Item2)); } else { return(renameFileRequest.ResponseServerError(string.Format("Unknown HTTPStatusCode from WopiFileRepository.RenameFile: {0}", response.Item1))); } }