Esempio n. 1
0
        public void SharedLock_Unlock_Missing()
        {
            var node         = CreateTestFolder();
            var nodeId       = node.Id;
            var existingLock = "LCK_" + Guid.NewGuid();

            // ACTION
            SharedLock.Unlock(nodeId, existingLock);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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));
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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));
        }
Esempio n. 7
0
        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
            });
        }
Esempio n. 8
0
        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
            });
        }