コード例 #1
0
        public override async Task <WopiResponse> Lock(LockRequest lockRequest)
        {
            var userId = WopiSecurity.GetIdentityNameFromToken(lockRequest.AccessToken);

            var wopiFileRepository = new WopiFileRepository();
            var response           = await wopiFileRepository.LockFile(lockRequest.ResourceId, userId, lockRequest.Lock, null);

            if (response.Item1 == HttpStatusCode.BadRequest)
            {
                return(lockRequest.ResponseBadRequest());
            }
            // Check for file not found or no permissions
            else if (response.Item1 == HttpStatusCode.NotFound)
            {
                return(lockRequest.ResponseNotFound());
            }
            // Ensure the file isn't already locked
            else if (response.Item1 == HttpStatusCode.Conflict)
            {
                return(lockRequest.ResponseLockConflict(response.Item2));
            }
            // File successfully locked
            else if (response.Item1 == HttpStatusCode.OK)
            {
                return(lockRequest.ResponseOK(response.Item3));
            }
            else
            {
                return(lockRequest.ResponseServerError(string.Format("Unknown HTTPStatusCode from WopiFileRepository.LockFile: {0}", response.Item1)));
            }
        }
コード例 #2
0
        public override async Task <WopiResponse> Lock(LockRequest lockRequest)
        {
            WopiResponse wopiResponse = null;
            var          file         = DocumentDBRepository <DetailedFileModel> .GetItem("Files", i => i.id.ToString() == lockRequest.ResourceId);

            // Check for null file
            if (file != null)
            {
                // Ensure the file isn't already locked or expired
                if (String.IsNullOrEmpty(file.LockValue) ||
                    (file.LockExpires != null &&
                     file.LockExpires < DateTime.Now))
                {
                    // Update the file with a LockValue and LockExpiration
                    file.LockValue   = lockRequest.Lock;
                    file.LockExpires = DateTime.Now.AddMinutes(30);
                    await DocumentDBRepository <FileModel> .UpdateItemAsync("Files", file.id.ToString(), (FileModel)file);

                    // Return success 200
                    wopiResponse = lockRequest.ResponseOK(file.Version.ToString());
                }
                else if (file.LockValue == lockRequest.Lock)
                {
                    // File lock matches existing lock, so refresh lock by extending expiration
                    file.LockExpires = DateTime.Now.AddMinutes(30);
                    await DocumentDBRepository <FileModel> .UpdateItemAsync("Files", file.id.ToString(), (FileModel)file);

                    // Return success 200
                    wopiResponse = lockRequest.ResponseOK(file.Version.ToString());
                }
                else
                {
                    // The file is locked by someone else...return mismatch
                    wopiResponse = lockRequest.ResponseLockConflict(file.LockValue, String.Format("File already locked by {0}", file.LockValue));
                }
            }
            else
            {
                wopiResponse = lockRequest.ResponseNotFound();
            }
            return(wopiResponse);
        }