Example #1
0
        private async Task <WopiResponse> ProcessLockRequestAsync(LockRequest 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)
            {
                if (!file.Locked)
                {
                    SharedLock.Lock(file.Id, wopiRequest.Lock, CancellationToken.None);
                    return(new WopiResponse {
                        StatusCode = HttpStatusCode.OK
                    });
                }
                return(new WopiResponse
                {
                    StatusCode = HttpStatusCode.Conflict,
                    Headers = new Dictionary <string, string>
                    {
                        { WopiHeader.Lock, "" },
                        { WopiHeader.LockFailureReason, "CheckedOut" }
                    }
                });
            }
            if (existingLock != wopiRequest.Lock)
            {
                return(new WopiResponse
                {
                    StatusCode = HttpStatusCode.Conflict,
                    Headers = new Dictionary <string, string>
                    {
                        { WopiHeader.Lock, existingLock },
                        { WopiHeader.LockFailureReason, "LockedByAnother" }
                    }
                });
            }
            SharedLock.RefreshLock(contentId, existingLock, CancellationToken.None);
            return(new WopiResponse {
                StatusCode = HttpStatusCode.OK
            });
        }
Example #2
0
        private WopiResponse ProcessLockRequest(LockRequest 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)
            {
                if (!file.Locked)
                {
                    SharedLock.Lock(file.Id, wopiReq.Lock);
                    return(new WopiResponse {
                        StatusCode = HttpStatusCode.OK
                    });
                }
                return(new WopiResponse
                {
                    StatusCode = HttpStatusCode.Conflict,
                    Headers = new Dictionary <string, string>
                    {
                        { WopiHeader.Lock, "" },
                        { WopiHeader.LockFailureReason, "CheckedOut" }
                    }
                });
            }
            if (existingLock != wopiReq.Lock)
            {
                return(new WopiResponse
                {
                    StatusCode = HttpStatusCode.Conflict,
                    Headers = new Dictionary <string, string>
                    {
                        { WopiHeader.Lock, existingLock },
                        { WopiHeader.LockFailureReason, "LockedByAnother" }
                    }
                });
            }
            SharedLock.RefreshLock(contentId, existingLock);
            return(new WopiResponse {
                StatusCode = HttpStatusCode.OK
            });
        }