Exemplo n.º 1
0
        private async Task RunLock()
        {
            base.CheckForFileId(this._fileId.Value, this._app);
            var boxClient   = base.ConfigureBoxClient(oneCallAsUserId: base._asUser.Value(), oneCallWithToken: base._oneUseToken.Value());
            var lockRequest = new BoxFileLockRequest();
            var boxLock     = new BoxFileLock();

            if (this._preventDownload.HasValue())
            {
                boxLock.IsDownloadPrevented = true;
            }
            if (this._expires.HasValue())
            {
                boxLock.ExpiresAt = GeneralUtilities.GetDateTimeFromString(this._expires.Value());
            }
            lockRequest.Lock = boxLock;
            var boxLocked = await boxClient.FilesManager.LockAsync(lockRequest, this._fileId.Value);

            if (base._json.HasValue() || this._home.GetBoxHomeSettings().GetOutputJsonSetting())
            {
                base.OutputJson(boxLocked);
                return;
            }
            base.PrintFileLock(boxLocked);
        }
        public async Task UpdateFileLock_ValidResponse_ValidFile()
        {
            string responseString = "{ \"type\": \"file\", \"id\": \"7435988481\", \"etag\": \"1\", \"lock\": { \"type\": \"lock\", \"id\": \"14516545\", \"created_by\": { \"type\": \"user\", \"id\": \"13130406\", \"name\": \"I don't know gmail\", \"login\": \"[email protected]\" }, \"created_at\": \"2014-05-29T18:03:04-07:00\", \"expires_at\": \"2014-05-30T19:03:04-07:00\", \"is_download_prevented\": false } } ";

            _handler.Setup(h => h.ExecuteAsync <BoxFile>(It.IsAny <IBoxRequest>()))
            .Returns(Task.FromResult <IBoxResponse <BoxFile> >(new BoxResponse <BoxFile>()
            {
                Status        = ResponseStatus.Success,
                ContentString = responseString
            }));

            /*** Act ***/
            BoxFileLockRequest request = new BoxFileLockRequest();

            request.Lock = new BoxFileLock();
            request.Lock.IsDownloadPrevented = false;

            BoxFileLock fileLock = await _filesManager.UpdateLockAsync(request, "0");

            /*** Assert ***/
            Assert.IsNotNull(fileLock);
            Assert.AreEqual(false, fileLock.IsDownloadPrevented);
            Assert.AreEqual(new DateTime(2014, 5, 31, 4, 03, 04, DateTimeKind.Utc), fileLock.ExpiresAt);
            Assert.AreEqual(new DateTime(2014, 5, 30, 3, 03, 04, DateTimeKind.Utc), fileLock.CreatedAt);
            Assert.IsNotNull(fileLock.CreatedBy);
            Assert.AreEqual("I don't know gmail", fileLock.CreatedBy.Name);
            Assert.AreEqual("*****@*****.**", fileLock.CreatedBy.Login);
        }
        /// <summary>
        /// Used to update the lock information on the file
        /// </summary>
        /// <param name="fileRequest"></param>
        /// <returns></returns>
        public async Task <BoxFileLock> UpdateLockAsync(BoxFileLockRequest lockFileRequest, string Id)
        {
            BoxRequest request = new BoxRequest(_config.FilesEndpointUri, Id)
                                 .Method(RequestMethod.Put)
                                 .Param(ParamFields, "lock");

            request.Payload = _converter.Serialize(lockFileRequest);

            IBoxResponse <BoxFile> response = await ToResponseAsync <BoxFile>(request).ConfigureAwait(false);

            return(response.ResponseObject.Lock);
        }
        /// <summary>
        /// Used to update the lock information on the file (for example, ExpiresAt or IsDownloadPrevented.
        /// </summary>
        /// <param name="lockFileRequest">BoxFileLockRequest object.</param>
        /// <param name="id">Id of the file.</param>
        /// <returns>BoxFileLock object.</returns>
        public async Task <BoxFileLock> UpdateLockAsync(BoxFileLockRequest lockFileRequest, string id)
        {
            lockFileRequest.ThrowIfNull("lockFileRequest");
            id.ThrowIfNullOrWhiteSpace("id");

            BoxRequest request = new BoxRequest(_config.FilesEndpointUri, id)
                                 .Method(RequestMethod.Put)
                                 .Param(ParamFields, BoxFile.FieldLock);

            request.Payload = _converter.Serialize(lockFileRequest);

            IBoxResponse <BoxFile> response = await ToResponseAsync <BoxFile>(request).ConfigureAwait(false);

            return(response.ResponseObject.Lock);
        }
 /// <summary>
 /// Used to create a lock on the file.
 /// </summary>
 /// <param name="lockFileRequest">Request contains Lock object for setting of lock properties such as ExpiresAt - the time the lock expires, IsDownloadPrevented - whether or not the file can be downloaded while locked. </param>
 /// <param name="id">Id of the file.</param>
 /// <returns>Returns information about locked file</returns>
 public async Task <BoxFileLock> LockAsync(BoxFileLockRequest lockFileRequest, string id)
 {
     return(await UpdateLockAsync(lockFileRequest, id));
 }