public void SharedLock_Unlock_Missing() { var node = CreateTestFolder(); var nodeId = node.Id; var existingLock = "LCK_" + Guid.NewGuid(); // ACTION SharedLock.Unlock(nodeId, existingLock); }
public void SharedLock_Unlock_TimedOut() { var node = CreateTestFolder(); var nodeId = node.Id; var existingLock = Guid.NewGuid().ToString(); SharedLock.Lock(nodeId, existingLock); SetSharedLockCreationDate(nodeId, DateTime.UtcNow.AddHours(-1.0d)); // ACTION SharedLock.Unlock(nodeId, existingLock); }
public void SharedLock_Unlock_Different() { var node = CreaeTestContent(); var nodeId = node.Id; var existingLock = "LCK_" + Guid.NewGuid(); SharedLock.Lock(nodeId, existingLock); // ACTION var actualLock = SharedLock.Unlock(nodeId, "DifferentLock"); Assert.AreEqual(existingLock, actualLock); }
public void SharedLock_Unlock() { var node = CreaeTestContent(); var nodeId = node.Id; var existingLock = "LCK_" + Guid.NewGuid(); SharedLock.Lock(nodeId, existingLock); // ACTION SharedLock.Unlock(nodeId, existingLock); Assert.IsNull(SharedLock.GetLock(nodeId)); }
public void SharedLock_Unlock_Different() { var node = CreateTestFolder(); var nodeId = node.Id; var existingLock = "LCK_" + Guid.NewGuid(); SharedLock.Lock(nodeId, existingLock, CancellationToken.None); // ACTION var actualLock = SharedLock.Unlock(nodeId, "DifferentLock", CancellationToken.None); Assert.AreEqual(existingLock, actualLock); }
public void SharedLock_Unlock() { var node = CreateTestFolder(); var nodeId = node.Id; var existingLock = "LCK_" + Guid.NewGuid(); SharedLock.Lock(nodeId, existingLock, CancellationToken.None); // ACTION SharedLock.Unlock(nodeId, existingLock, CancellationToken.None); Assert.IsNull(SharedLock.GetLock(nodeId, CancellationToken.None)); }
private async Task <WopiResponse> ProcessUnlockRequestAsync(UnlockRequest wopiRequest, CancellationToken cancellationToken) { if (!int.TryParse(wopiRequest.FileId, out var contentId)) { return new WopiResponse { StatusCode = HttpStatusCode.NotFound } } ; if (!(await Node.LoadNodeAsync(contentId, cancellationToken).ConfigureAwait(false) is File file)) { return new WopiResponse { StatusCode = HttpStatusCode.NotFound } } ; var existingLock = SharedLock.GetLock(file.Id, CancellationToken.None); if (existingLock == null) { return(new WopiResponse { StatusCode = HttpStatusCode.Conflict, Headers = new Dictionary <string, string> { { WopiHeader.Lock, string.Empty }, { WopiHeader.LockFailureReason, "Unlocked" } } }); } if (existingLock != wopiRequest.Lock) { return(new WopiResponse { StatusCode = HttpStatusCode.Conflict, Headers = new Dictionary <string, string> { { WopiHeader.Lock, existingLock }, { WopiHeader.LockFailureReason, "LockedByAnother" } } }); } SharedLock.Unlock(contentId, existingLock, CancellationToken.None); return(new WopiResponse { StatusCode = HttpStatusCode.OK }); }
private WopiResponse ProcessUnlockRequest(UnlockRequest wopiReq) { if (!int.TryParse(wopiReq.FileId, out var contentId)) { return new WopiResponse { StatusCode = HttpStatusCode.NotFound } } ; if (!(Node.LoadNode(contentId) is File file)) { return new WopiResponse { StatusCode = HttpStatusCode.NotFound } } ; var existingLock = SharedLock.GetLock(file.Id); if (existingLock == null) { return(new WopiResponse { StatusCode = HttpStatusCode.Conflict, Headers = new Dictionary <string, string> { { WopiHeader.Lock, string.Empty }, { WopiHeader.LockFailureReason, "Unlocked" } } }); } if (existingLock != wopiReq.Lock) { return(new WopiResponse { StatusCode = HttpStatusCode.Conflict, Headers = new Dictionary <string, string> { { WopiHeader.Lock, existingLock }, { WopiHeader.LockFailureReason, "LockedByAnother" } } }); } SharedLock.Unlock(contentId, existingLock); return(new WopiResponse { StatusCode = HttpStatusCode.OK }); }