從2013年12月的developer road map中有一條說明,「鎖定/解鎖 - 我們已經添加了對鎖定和解鎖文件到V2 API的支持。」Box V2 API - 鎖定/解鎖位置在哪裏?
我已經通過V2 API(對於C#),並且無法在任何地方找到它。我期望在BoxFilesManager類中找到一些東西,或者將其作爲UpdateInformationAsync中的BoxFileRequest類。
那麼有沒有辦法鎖定/解鎖文件?
從2013年12月的developer road map中有一條說明,「鎖定/解鎖 - 我們已經添加了對鎖定和解鎖文件到V2 API的支持。」Box V2 API - 鎖定/解鎖位置在哪裏?
我已經通過V2 API(對於C#),並且無法在任何地方找到它。我期望在BoxFilesManager類中找到一些東西,或者將其作爲UpdateInformationAsync中的BoxFileRequest類。
那麼有沒有辦法鎖定/解鎖文件?
偉大的問題。爲了查看文件的當前鎖定狀態做一個
GET https://api.box.com/2.0/files/7435988481/?fields=lock
如果在文件中沒有鎖,你會得到這樣的背:
{
"type": "file",
"id": "7435988481",
"etag": "0",
"lock": null
}
如果要鎖定一個文件,你需要在/ files/endpoint上做一個PUT(更新),它的主體告訴我們什麼類型的鎖,以及什麼時候釋放它。就像這樣:
PUT https://api.box.com/2.0/files/7435988481/?fields=lock
{"lock": {
"expires_at" : "2014-05-29T19:03:04-07:00",
"is_download_prevented": true
}
}
你會得到迴應,確認您的鎖被創造:
{
"type": "file",
"id": "7435988481",
"etag": "1",
"lock": {
"type": "lock",
"id": "14516545",
"created_by": {
"type": "user",
"id": "13130406",
"name": "Peter Rexer gmail",
"login": "[email protected]"
},
"created_at": "2014-05-29T18:03:04-07:00",
"expires_at": "2014-05-29T19:03:04-07:00",
"is_download_prevented": true
}
}
由於沒有鎖定/解鎖然而,我創建基於現有管理人員鎖管理器:
class BoxCloudLockManager : BoxResourceManager
{
#region Lock/Unlock Classes
[DataContract]
internal class BoxLockRequestInfo
{
[DataMember(Name = "status")]
public string Status { get; set; }
//[DataMember(Name = "expires_at")]
//public string ExpiresAt { get; set; }
[DataMember(Name = "is_download_prevented")]
public bool IsDownloadPrevented { get; set; }
}
[DataContract]
internal class BoxLockRequest
{
[DataMember(Name = "lock")]
public BoxLockRequestInfo Lock { get; set; }
}
#endregion
const string LockFileString = "{0}/?fields=lock";
public BoxCloudLockManager(IBoxConfig config, IBoxService service, IBoxConverter converter, IAuthRepository auth)
: base(config, service, converter, auth)
{
}
public async Task<BoxLockInfo> LockAsync(string documentId,bool isDownloadPrevented = true)
{
var lockRequest = new BoxLockRequest { Lock = new BoxLockRequestInfo { Status = "lock", IsDownloadPrevented = isDownloadPrevented } };
BoxRequest request = new BoxRequest(_config.FilesEndpointUri, string.Format(LockFileString, documentId))
.Method(RequestMethod.Put)
.Payload(_converter.Serialize(lockRequest));
IBoxResponse<BoxLockInfo> response = await ToResponseAsync<BoxLockInfo>(request).ConfigureAwait(false);
return response.ResponseObject;
}
public async Task<BoxLockInfo> UnlockAsync(string documentId)
{
BoxRequest request = new BoxRequest(_config.FilesEndpointUri, string.Format(LockFileString, documentId))
.Method(RequestMethod.Put)
.Payload("{\"lock\":null}");
IBoxResponse<BoxLockInfo> response = await ToResponseAsync<BoxLockInfo>(request).ConfigureAwait(false);
return response.ResponseObject;
}
public async Task<BoxLockInfo> GetLockInfoAsync(string documentId)
{
BoxRequest request = new BoxRequest(_config.FilesEndpointUri, string.Format(LockFileString, documentId))
.Method(RequestMethod.Get);
IBoxResponse<BoxLockInfo> response = await ToResponseAsync<BoxLockInfo>(request).ConfigureAwait(false);
return response.ResponseObject;
}
}
我從BoxClient派生了一個類,添加一個LockManager並在構造函數中實例化它。
這裏是鎖定信息:
[DataContract]
public class BoxLockedBy
{
[DataMember(Name = "type")]
public string Type { get; set; }
[DataMember(Name = "id")]
public string Id { get; set; }
[DataMember(Name = "name")]
public string Name { get; set; }
[DataMember(Name = "login")]
public string Login { get; set; }
}
[DataContract]
public class BoxLockDetails
{
[DataMember(Name = "type")]
public string Type { get; set; }
[DataMember(Name = "id")]
public string Id { get; set; }
[DataMember(Name = "created_by")]
public BoxLockedBy CreatedBy { get; set; }
[DataMember(Name = "created_at")]
public string CreatedAt { get; set; }
[DataMember(Name = "expires_at")]
public string ExpiresAt { get; set; }
[DataMember(Name = "is_download_prevented")]
public bool IsDownloadPrevented { get; set; }
}
[DataContract]
public class BoxLockInfo
{
[DataMember(Name = "type")]
public string Type { get; set; }
[DataMember(Name = "id")]
public string Id { get; set; }
[DataMember(Name = "etag")]
public string Etag { get; set; }
[DataMember(Name = "lock")]
public BoxLockDetails LockDetails { get; set; }
}
這是如何確定使用GET/PUT狀態。是否還有C#API調用? – kberson
呃...... C#世界大師?任何人都想將它添加到SDK中?可能應該提交功能請求..或者https://github.com/box/box-windows-sdk-v2或https://github.com/jhoerr/box-csharp-sdk-v2 – Peter
JHoerr已停用,停止當Box自帶的時候保持這個庫。 – kberson