コード例 #1
0
ファイル: WopiMiddleware.cs プロジェクト: SenseNet/sensenet
        private async Task <WopiResponse> ProcessUnlockAndRelockRequestAsync(UnlockAndRelockRequest 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.OldLock)
            {
                return(new WopiResponse
                {
                    StatusCode = HttpStatusCode.Conflict,
                    Headers = new Dictionary <string, string>
                    {
                        { WopiHeader.Lock, existingLock },
                        { WopiHeader.LockFailureReason, "LockedByAnother" }
                    }
                });
            }
            SharedLock.ModifyLock(contentId, existingLock, wopiRequest.Lock, CancellationToken.None);
            return(new WopiResponse {
                StatusCode = HttpStatusCode.OK
            });
        }
コード例 #2
0
        private WopiResponse ProcessUnlockAndRelockRequest(UnlockAndRelockRequest 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.OldLock)
            {
                return(new WopiResponse
                {
                    StatusCode = HttpStatusCode.Conflict,
                    Headers = new Dictionary <string, string>
                    {
                        { WopiHeader.Lock, existingLock },
                        { WopiHeader.LockFailureReason, "LockedByAnother" }
                    }
                });
            }
            SharedLock.ModifyLock(contentId, existingLock, wopiReq.Lock);
            return(new WopiResponse {
                StatusCode = HttpStatusCode.OK
            });
        }