C # development BIMFACE 13 series of server-side API to obtain the conversion status

In the "C # development BIMFACE 12 series of server-side API file conversion" in detail the method seven kinds of file conversion. After the originating source file / model conversion, the conversion process may succeed or fail. So in this case you need to query the source file / transition state model. There are three ways to know if the conversion was successful.

The first: calling file conversion interface https://api.bimface.com/translate, the result returns information contained in the conversion results interface.

The second: the calling file conversion interface https://api.bimface.com/translate, because the conversion can not be completed immediately, BIMFace support after file conversion is complete, notify the application through Callback mechanisms, including the conversion results information Callbak returned results .

The third is to introduce Benpian query through the interface conversion status.

Request Address: GET https://api.bimface.com/translate

Description: Application launched after conversion, you can use this interface to query into state

parameter:

Request path (Example): https://api.bimface.com/translate?fileId=857482189666208

Request header (Example): "the Authorization: Bearer dc671840-BACC-4dc5-a134-97c1918d664b"

Example HTTP response (200):

{
  "code" : "success",
  "data" : {
    "createTime" : "2017-12-25 17:23:46",
    "databagId" : "9b711803a43b92d871cde346b63e5019",
    "fileId" : 1248789071339712,
    "name" : "bimface_2018.rvt",
    "priority" : 2,
    "reason" : "reason",
    "status" : "success",
    "thumbnail" : [ "https://m.bimface.com/9b711803a43b92d871cde346b63e5019/thumbnail/96.png", "https://m.bimface.com/9b711803a43b92d871cde346b63e5019/thumbnail/256.png" ]
  },
  "message" : ""
}

C#实现方法:

 1 /// <summary>
 2 ///  获取转换状态(应用发起转换以后,可以通过该接口查询转换状态)
 3 /// </summary>
 4 /// <param name="accessToken">令牌</param>
 5 /// <param name="fileId"></param>
 6 /// <returns></returns>
 7 public virtual FileTranslateResponse GetFileTranslateStatus(string accessToken, long fileId)
 8 {
 9     //GET https://api.bimface.com/translate
10     string url = string.Format(BimfaceConstants.API_HOST + "/translate?fileId={0}", fileId);
11 
12     BimFaceHttpHeaders headers = new BimFaceHttpHeaders();
13     headers.AddOAuth2Header(accessToken);
14 
15     try
16     {
17         FileTranslateResponse response;
18 
19         HttpManager httpManager = new HttpManager(headers);
20         HttpResult httpResult = httpManager.Get(url);
21         if (httpResult.Status == HttpResult.STATUS_SUCCESS)
22         {
23             response = httpResult.Text.DeserializeJsonToObject<FileTranslateResponse>();
24         }
25         else
26         {
27             response = new FileTranslateResponse
28             {
29                 Message = httpResult.RefText
30             };
31         }
32 
33         return response;
34     }
35     catch (Exception ex)
36     {
37         throw new Exception("[获取转换状态]发生异常!", ex);
38     }
39 }

其中调用到的 httpManager.Get() 方法,请参考《C# HTTP系列》

测试
在BIMFACE的控制台中可以看到我们上传的文件列表,共计2个文件。模型状态均为转换成功。
 

以“rac_advanced_sample_project-三维视图 - From Parking Area.dwg”为例,查询其转换的状态信息

测试代码如下:
 1 // 获取转换状态
 2 protected void btnGetFileTranslateStatus_Click(object sender, EventArgs e)
 3 {
 4     long fileId = txtFileID.Text.Trim().ToLong();
 5     FileConvertApi api = new FileConvertApi();
 6     FileTranslateResponse response = api.GetFileTranslateStatus(txtAccessToken.Text, fileId);
 7 
 8     txtResult.Text = response.Code.ToString2()
 9                    + Environment.NewLine
10                    + response.Message.ToString2()
11                    + Environment.NewLine
12                    + response.Data.ToString2();
13 }

返回的转换结果类FileTranslateResponse如下:

 1 /// <summary>
 2 ///  文件转换返回的结果类
 3 /// </summary>
 4 [Serializable]
 5 public class FileTranslateResponse : GeneralResponse<FileTranslateEntity>
 6 {
 7 
 8 }
 9 
10 [Serializable]
11 public class FileTranslateEntity
12 {
13     /// <summary>
14     /// 文件转换完成的时间
15     /// </summary>
16     [JsonProperty("createTime")]
17     public DateTime? CreateTime { get; set; }
18 
19     [JsonProperty("databagId")]
20     public string DatabagId { get; set; }
21 
22     [JsonProperty("fileId")]
23     public long? FileId { get; set; }
24 
25     /// <summary>
26     ///  文件的名称,包括后缀
27     /// </summary>
28     [JsonProperty("name")]
29     public string Name { get; set; }
30 
31     /// <summary>
32     /// 优先级,数字越大,优先级越低。1, 2, 3
33     /// </summary>
34     [JsonProperty("priority")]
35     public int? Priority { get; set; }
36 
37     /// <summary>
38     ///  若转换失败,则返回失败原因
39     /// </summary>
40     [JsonProperty("reason")]
41     public string Reason { get; set; }
42 
43     /// <summary>
44     ///  转换的状态
45     /// </summary>
46     [JsonProperty("status")]
47     public string Status { get; set; }
48 
49     /// <summary>
50     ///  缩略图
51     /// </summary>
52     [JsonProperty("thumbnail")]
53     public string[] Thumbnails { get; set; }
54 
55 
56     /// <summary>返回表示当前对象的字符串。</summary>
57     /// <returns>表示当前对象的字符串。</returns>
58     public override string ToString()
59     {
60         StringBuilder sb = new StringBuilder();
61         if(Thumbnails != null && Thumbnails.Length > 0)
62         {
63             foreach(string thumbnail in Thumbnails)
64             {
65                 sb.AppendLine(thumbnail);
66             }
67         }
68 
69         return string.Format("FileTranslateEntity [createTime={0}, fileId={1}, name={2}, priority={3},reason={4},status={5},thumbnail={6}]",
70                              CreateTime, FileId, Name, Priority, Reason, Status, sb.ToString());
71     }
72 }

 

 

Guess you like

Origin www.cnblogs.com/SavionZhang/p/11455484.html