示例#1
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
            });
        }
示例#2
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
            });
        }