public IActionResult ProcessLock(string id) { log.Info($"ProcessLock file id: {id}, WopiOverrideHeader: {WopiOverrideHeader}"); string oldLock = Request.Headers[WopiHeaders.OldLock]; string newLock = Request.Headers[WopiHeaders.Lock]; lock (FileLockHelper.LockStorage) { bool lockAcquired = FileLockHelper.TryGetLock(id, out var existingLock); log.Info($"ProcessLock lockAcquired: {lockAcquired}, oldLock: {oldLock}, newLock: {newLock}"); switch (WopiOverrideHeader) { case "GET_LOCK": if (lockAcquired) { Response.Headers[WopiHeaders.Lock] = existingLock.Lock; } return(new OkResult()); case "LOCK": case "PUT": if (string.IsNullOrEmpty(oldLock)) { // Lock / put if (lockAcquired) { log.Info($"ProcessLock existingLock: {existingLock.Lock}"); if (existingLock.Lock == newLock) { // File is currently locked and the lock ids match, refresh lock FileLockHelper.SetLock(id, newLock, _hostingEnvironment.ContentRootPath); return(new OkResult()); } else { // There is a valid existing lock on the file return(ReturnLockMismatch(Response, existingLock.Lock)); } } else { // The file is not currently locked, create and store new lock information FileLockHelper.SetLock(id, newLock, _hostingEnvironment.ContentRootPath); return(new OkResult()); } } else { // Unlock and relock (http://wopi.readthedocs.io/projects/wopirest/en/latest/files/UnlockAndRelock.html) if (lockAcquired) { log.Info($"ProcessLock existingLock: {existingLock.Lock}"); if (existingLock.Lock == oldLock) { // Replace the existing lock with the new one FileLockHelper.SetLock(id, newLock, _hostingEnvironment.ContentRootPath); return(new OkResult()); } else { // The existing lock doesn't match the requested one. Return a lock mismatch error along with the current lock return(ReturnLockMismatch(Response, existingLock.Lock)); } } else { // The requested lock does not exist which should result in a lock mismatch error. return(ReturnLockMismatch(Response, reason: "File not locked")); } } case "UNLOCK": if (lockAcquired) { if (existingLock.Lock == newLock) { // Remove valid lock FileLockHelper.SetLock(id, null, _hostingEnvironment.ContentRootPath); log.Info($"ProcessLock UNLOCK: OkResult"); return(new OkResult()); } else { // The existing lock doesn't match the requested one. Return a lock mismatch error along with the current lock return(ReturnLockMismatch(Response, existingLock.Lock)); } } else { // The requested lock does not exist. return(ReturnLockMismatch(Response, reason: "File not locked")); } case "REFRESH_LOCK": if (lockAcquired) { if (existingLock.Lock == newLock) { // Extend the lock timeout FileLockHelper.SetLock(id, newLock, _hostingEnvironment.ContentRootPath); return(new OkResult()); } else { // The existing lock doesn't match the requested one. Return a lock mismatch error along with the current lock return(ReturnLockMismatch(Response, existingLock.Lock)); } } else { // The requested lock does not exist. That's also a lock mismatch error. return(ReturnLockMismatch(Response, reason: "File not locked")); } } } return(new OkResult()); }