系列目录 【已更新最新开发文章,点击查看详细】
上一篇《C#开发BIMFACE系列13 服务端API之获取转换状态》中介绍了根据文件ID查询单个文件的转换状态。
本文介绍批量获取转换状态详情。
请求地址:POST https://api.bimface.com/translateDetails
说明:应用发起转换以后,可以根据筛选条件,通过该接口批量查询转换状态详情
参数:
请求 path(示例):https://api.bimface.com/translateDetails
请求 header(示例):"Authorization: Bearer dc671840-bacc-4dc5-a134-97c1918d664b"
请求 body(示例):
{
"appKey" : "appKey", //必填
"endDate" : "string",
"fileId" : ,
"fileName" : "fileName",
"pageNo" : ,
"pageSize" : ,
"sortType" : "sortType",
"sourceId" : "d4649ee227e345c8b7f0022342247dec",
"startDate" : "string",
"status" : ,
"suffix" : "suffix"
}
HTTP响应示例(200):application/octet-stream
{
"code" : "success",
"data" : {
"list" : [ {
"appKey" : "appKey",
"cost" : ,
"createTime" : "createTime",
"databagId" : "498bc694854244abab728b20620cbaf9",
"fileId" : ,
"length" : ,
"name" : "name",
"offlineDatabagStatus" : "offlineDatabagStatus",
"priority" : ,
"reason" : "reason",
"retry" : true,
"shareToken" : "shareToken",
"shareUrl" : "shareUrl",
"sourceId" : "d69620720c63480c9f4808bf442ed96a",
"status" : "status",
"supportOfflineDatabag" : true,
"thumbnail" : [ "string" ],
"type" : "type"
} ],
"page" : {
"htmlDisplay" : "string",
"nextPage" : ,
"pageNo" : ,
"pageSize" : ,
"prePage" : ,
"startIndex" : ,
"totalCount" : ,
"totalPages" :
}
},
"message" : ""
}
请求体参数说明:
经过测试验证,其中 appKey 是必填项,其余参数非必填。
对应封装的请求实体类为:
/// <summary>
/// 批量获取转换状态详情的请求数据
/// </summary>
[Serializable]
public class TranslateQueryRequest
{
public TranslateQueryRequest()
{
FileId = null;
Suffix = null;
FileName = null;
SourceId = null;
PageNo = null;
PageSize = null;
Status = null;
SortType = null;
StartDate = null;
EndDate = null;
} /// <summary>
/// 【必填项】应用的 appKey
/// </summary>
[JsonProperty("appKey")]
public string AppKey { get; set; } /// <summary>
/// 【非必填项】单模型对应的id,例如:1216871503527744
/// </summary>
[JsonProperty("fileId", NullValueHandling = NullValueHandling.Ignore)]
public string FileId { get; set; } /// <summary>
/// 【非必填项】单模型的文件类型。例如:rvt(或者igms,dwg…)
/// </summary>
[JsonProperty("suffix", NullValueHandling = NullValueHandling.Ignore)]
public string Suffix { get; set; } /// <summary>
/// 【非必填项】单模型的名称。例如:translate-test
/// </summary>
[JsonProperty("fileName", NullValueHandling = NullValueHandling.Ignore)]
public string FileName { get; set; } /// <summary>
/// 【非必填项】模型对应的sourceId。例如:389c28de59ee62e66a7d87ec12692a76
/// </summary>
[JsonProperty("sourceId", NullValueHandling = NullValueHandling.Ignore)]
public string SourceId { get; set; } /// <summary>
/// 【非必填项】页码
/// </summary>
[JsonProperty("pageNo",NullValueHandling = NullValueHandling.Ignore)]
public int? PageNo { get; set; } /// <summary>
/// 【非必填项】每页返回数目
/// </summary>
[JsonProperty("pageSize", NullValueHandling = NullValueHandling.Ignore)]
public int? PageSize { get; set; } /// <summary>
/// 【非必填项】模型状态码。1(处理中) 99(成功) -1(失败)
/// </summary>
[JsonProperty("status", NullValueHandling = NullValueHandling.Ignore)]
public short? Status { get; set; } /// <summary>
/// 【非必填项】筛选类型
/// </summary>
[JsonProperty("sortType", NullValueHandling = NullValueHandling.Ignore)]
public string SortType { get; set; } /// <summary>
/// 【非必填项】开始日期。例如:2019-05-01
/// </summary>
[JsonProperty("startDate", NullValueHandling = NullValueHandling.Ignore)]
public string StartDate { get; set; } /// <summary>
/// 【非必填项】截止日期。例如:2019-05-03
/// </summary>
[JsonProperty("endDate", NullValueHandling = NullValueHandling.Ignore)]
public string EndDate { get; set; }
}
C#实现方法:
/// <summary>
/// 批量获取转换状态详情
/// </summary>
/// <param name="accessToken">令牌</param>
/// <param name="request">请求体参数对象</param>
/// <returns></returns>
public virtual FileTranslateDetailsResponse GetFileTranslateDetails(string accessToken, TranslateQueryRequest request)
{
// POST https://api.bimface.com/translateDetails
string url = string.Format(BimfaceConstants.API_HOST + "/translateDetails"); BimFaceHttpHeaders headers = new BimFaceHttpHeaders();
headers.AddOAuth2Header(accessToken); string data = request.SerializeToJson(); try
{
FileTranslateDetailsResponse response; HttpManager httpManager = new HttpManager(headers);
HttpResult httpResult = httpManager.Post(url,data);
if (httpResult.Status == HttpResult.STATUS_SUCCESS)
{
response = httpResult.Text.DeserializeJsonToObject<FileTranslateDetailsResponse>();
}
else
{
response = new FileTranslateDetailsResponse
{
Message = httpResult.RefText
};
} return response;
}
catch (Exception ex)
{
throw new Exception("[批量获取转换状态详情]发生异常!", ex);
}
}
其中调用到的 httpManager.Post() 方法,请参考《C# HTTP系列》
测试
在BIMFACE的控制台中可以看到我们上传的文件列表,共计2个文件。模型状态均为转换成功。
调用上面的GetFileTranslateDetails()方法测试批量查询转换状态:
测试代码如下:
// 批量获取转换状态详情
protected void btnGetFileTranslateDetails_Click(object sender, EventArgs e)
{
TranslateQueryRequest request = new TranslateQueryRequest
{
AppKey = _appKey //必填项
}; FileConvertApi api = new FileConvertApi();
FileTranslateDetailsResponse response = api.GetFileTranslateDetails(txtAccessToken.Text, request); txtResult.Text = response.Code.ToString2()
+ Environment.NewLine
+ response.Message.ToString2()
+ Environment.NewLine
+ response.Data.ToString2();
}
返回的结果实体类如下:
/// <summary>
/// 批量获取转换状态详情返回的结果类
/// </summary>
[Serializable]
public class FileTranslateDetailsResponse : GeneralResponse<FileTranslateDetailsEntity>
{ }
[Serializable]
public class FileTranslateDetailsEntity
{
[JsonProperty("list")]
public Detail[] Details { get; set; } [JsonProperty("page")]
public Page Page { get; set; } /// <summary>返回表示当前对象的字符串。</summary>
/// <returns>表示当前对象的字符串。</returns>
public override string ToString()
{
StringBuilder sb = new StringBuilder();
if (Details != null && Details.Length > )
{
for (var i = ; i < Details.Length; i++)
{
Detail detail = Details[i]; StringBuilder sbThumbnails = new StringBuilder();
string[] thumbnails = detail.Thumbnails;
if (thumbnails != null && thumbnails.Length > )
{
foreach (var thumbnail in thumbnails)
{
sbThumbnails.Append(thumbnail + ";");
}
} sb.AppendLine(String.Format("\r\nDetail{0}\r\nappKey={1}, cost={2}, createTime={3}, databagId={4}, fileId={5}, length={6}, name={7}, "
+ "offlineDatabagStatus={8}, priority={9}, reason={10}, retry={11}, shareToken={12}, shareUrl={13}, sourceId={14}, status={15}, supportOfflineDatabag={16}, "
+ "type={17}, thumbnails={18}",
(i + ), detail.AppKey, detail.Cost, detail.CreateTime, detail.DatabagId, detail.FileId, detail.Length, detail.Name,
detail.OfflineDatabagStatus, detail.Priority, detail.Reason, detail.Retry, detail.ShareToken, detail.ShareUrl, detail.SourceId, detail.Status, detail.SupportOfflineDatabag,
detail.Type, sbThumbnails));
}
} sb.AppendLine("\r\npage");
sb.AppendLine(string.Format("prePage={0}, nextPage={1}, pageNo={2}, pageSize={3}, startIndex={4}, totalCount={5}, totalPages={6}",
Page.PrePage, Page.NextPage, Page.PageNo, Page.PageSize, Page.StartIndex, Page.TotalCount, Page.TotalPages)); return string.Format("FileTranslateDetailsEntity [\r\n{0}\r\n]", sb);
}
}
/// <summary>
/// 转换状态详情
/// </summary>
[Serializable]
public class Detail
{
/// <summary>
/// 应用的 appkey
/// </summary>
[JsonProperty("appKey")]
public string AppKey { get; set; } /// <summary>
/// 任务耗时(单位:秒)
/// </summary>
[JsonProperty("cost")]
public int Cost { get; set; } /// <summary>
/// 创建时间
/// </summary>
[JsonProperty("createTime")]
public string CreateTime { get; set; } /// <summary>
/// 数据包id。例如:70b8c10b686061525420fc240bf48aca
/// </summary>
[JsonProperty("databagId")]
public string DatabagId { get; set; } /// <summary>
/// 模型的fileId。例如:1609858191716512
/// </summary>
[JsonProperty("fileId")]
public long? FileId { get; set; } /// <summary>
/// 文件长度(单位:字节)
/// </summary>
[JsonProperty("length")]
public long? Length { get; set; } /// <summary>
/// 集成模型的名称,例如:integrate-test
/// </summary>
[JsonProperty("name")]
public string Name { get; set; } /// <summary>
/// 离线数据包生成状态:prepare(未生成) processing(生成中) success(生成成功) failed(生成失败)
/// </summary>
[JsonProperty("offlineDatabagStatus")]
public string OfflineDatabagStatus { get; set; } /// <summary>
/// 任务优先级。 数字越大,优先级越低。1, 2, 3。
/// </summary>
[JsonProperty("priority")]
public short? Priority { get; set; } /// <summary>
/// 若转换失败,返回失败原因。转换成功时,返回空字符串
/// </summary>
[JsonProperty("reason")]
public string Reason { get; set; } /// <summary>
/// 重试,true(或者false)
/// </summary>
[JsonProperty("retry")]
public bool? Retry { get; set; } /// <summary>
/// 分享码。例如:3c476c55
/// </summary>
[JsonProperty("shareToken")]
public string ShareToken { get; set; } /// <summary>
/// 分享链接。例如:https://api.bimface.com/preview/3c476c55
/// </summary>
[JsonProperty("shareUrl")]
public string ShareUrl { get; set; } /// <summary>
/// 模型对应的sourceId。该字段暂时空置
/// </summary>
[JsonProperty("sourceId")]
public string SourceId { get; set; } /// <summary>
/// 模型状态,processing(处理中) success(成功) failed(失败)
/// </summary>
[JsonProperty("status")]
public string Status { get; set; } /// <summary>
/// 是否支持离线数据包,true(或者false)
/// </summary>
[JsonProperty("supportOfflineDatabag")]
public bool? SupportOfflineDatabag { get; set; } /// <summary>
/// 模型的缩略图,该字段暂时空置
/// </summary>
[JsonProperty("thumbnail")]
public string[] Thumbnails { get; set; } /// <summary>
/// 转换类型。例如:rvt-translate(或者igms-translate…)
/// </summary>
[JsonProperty("type")]
public string Type { get; set; }
}
/// <summary>
/// 返回总记录的分页信息
/// </summary>
[Serializable]
public class Page
{
/// <summary>
/// 下一页码
/// </summary>
[JsonProperty("nextPage")]
public int NextPage { get; set; } /// <summary>
/// 当前页码
/// </summary>
[JsonProperty("pageNo")]
public int PageNo { get; set; } /// <summary>
/// 每页条目数
/// </summary>
[JsonProperty("pageSize")]
public int PageSize { get; set; } /// <summary>
/// 上一页码
/// </summary>
[JsonProperty("prePage")]
public int PrePage { get; set; } /// <summary>
/// 起始索引数
/// </summary>
[JsonProperty("startIndex")]
public int StartIndex { get; set; } /// <summary>
/// 条目总数
/// </summary>
[JsonProperty("totalCount")]
public int TotalCount { get; set; } /// <summary>
/// 页码总数
/// </summary>
[JsonProperty("totalPages")]
public int TotalPages { get; set; }
}
系列目录 【已更新最新开发文章,点击查看详细】