C#开发BIMFACE系列34 服务端API之模型对比5:获取模型构件对比差异
BIMFACE二次开发系列目录
BIMFACE平台提供了服务端“获取修改构件属性差异”API,其返回的结果也是一个列表,仅针对修改的构件(不包含新增、删除的构件),是指对于一个修改过的构件ID,其修改前后分别新增、删除了哪些属性,或是属性值发生了变化。
请求地址:GET https://api.bimface.com/data/v2/comparisons/{comparisonId}/elementChange
参数:
请求 path(示例):https://api.bimface.com/data/v2/comparisons/1136906400211168/elementChange?followingElementId=296524&followingFileId=1136893002033344&previousElementId=296524&previousFileId=1136239003943104
请求 header(示例):"Authorization: Bearer dc671840-bacc-4dc5-a134-97c1918d664b"
HTTP响应示例(200):
1 { 2 "code" : "success", 3 "data" : { 4 "_A" : "string", 5 "_B" : "string", 6 "changeAttributes" : [ { 7 "_A" : { 8 "key" : "key", 9 "unit" : "unit", 10 "value" : "value" 11 }, 12 "_B" : { 13 "key" : "key", 14 "unit" : "unit", 15 "value" : "value" 16 } 17 } ], 18 "changeQuantities" : [ { 19 "_A" : { 20 "code" : "code", 21 "desc" : "desc", 22 "name" : "name", 23 "qty" : 0, 24 "unit" : "unit" 25 }, 26 "_B" : { 27 "code" : "code", 28 "desc" : "desc", 29 "name" : "name", 30 "qty" : 0, 31 "unit" : "unit" 32 } 33 } ], 34 "deleteAttributes" : [ { 35 "key" : "key", 36 "unit" : "unit", 37 "value" : "value" 38 } ], 39 "deleteQuantities" : [ { 40 "code" : "code", 41 "desc" : "desc", 42 "name" : "name", 43 "qty" : 0, 44 "unit" : "unit" 45 } ], 46 "newAttributes" : [ { 47 "key" : "key", 48 "unit" : "unit", 49 "value" : "value" 50 } ], 51 "newQuantities" : [ { 52 "code" : "code", 53 "desc" : "desc", 54 "name" : "name", 55 "qty" : 0, 56 "unit" : "unit" 57 } ] 58 }, 59 "message" : "" 60 }
C#实现方法:
1 ///2 /// 获取模型构件对比差异 3 /// 4 /// 【必填】令牌 5 /// 【必填】对比ID 6 /// 【必填】变更后的文件ID 7 /// 【必填】变更后的文件的构件ID 8 /// 【必填】变更前的文件ID 9 /// 【必填】变更前的文件的构件ID 10 /// 11 public virtual ModelCompareChangeResponse GetModelCompareChange(string accessToken, long compareId, 12 long followingFileId, string followingElementId, long previousFileId, string previousElementId) 13 { 14 // GET https: //api.bimface.com/data/v2/comparisons/{comparisonId}/elementChange 15 string url = string.Format(BimfaceConstants.API_HOST + "/data/v2/comparisons/{0}/elementChange", compareId); 16 url += "?followingFileId=" + followingFileId; 17 url += "&followingElementId=" + followingElementId; 18 url += "&previousFileId=" + previousFileId; 19 url += "&previousElementId=" + previousElementId; 20 21 BimFaceHttpHeaders headers = new BimFaceHttpHeaders(); 22 headers.AddOAuth2Header(accessToken); 23 24 try 25 { 26 ModelCompareChangeResponse response; 27 28 HttpManager httpManager = new HttpManager(headers); 29 HttpResult httpResult = httpManager.Get(url); 30 if (httpResult.Status == HttpResult.STATUS_SUCCESS) 31 { 32 response = httpResult.Text.DeserializeJsonToObject (); 33 } 34 else 35 { 36 response = new ModelCompareChangeResponse 37 { 38 Message = httpResult.RefText 39 }; 40 } 41 42 return response; 43 } 44 catch (Exception ex) 45 { 46 throw new Exception("[获取模型构件对比差异]发生异常!", ex); 47 } 48 }
代码中使用的 HttpManager 类请参考我的博客文章《》。
返回类型 ModelCompareChangeResponse 类如下:
1 ///BIMFACE二次开发系列目录2 /// 获取模型构件对比差异的响应类 3 /// 4 public class ModelCompareChangeResponse : GeneralResponse 5 { 6 7 } 8 9 /// 10 /// 模型构件对比差异类 11 /// 12 public class ModelCompareChange 13 { 14 /// 15 /// 变化图元前一个版本的ID 16 /// 17 [JsonProperty("_A", NullValueHandling = NullValueHandling.Ignore)] 18 public string A { get; set; } 19 20 /// 21 /// 变化图元后一个版本的ID 22 /// 23 [JsonProperty("_B", NullValueHandling = NullValueHandling.Ignore)] 24 public string B { get; set; } 25 26 /// 27 /// 变更的构建属性集合 28 /// 29 30 [JsonProperty("changeAttributes", NullValueHandling = NullValueHandling.Ignore)] 31 public ChangeAttributes[] ChangeAttributes { get; set; } 32 33 /// 34 /// 变更的工程量集合 35 /// 36 37 [JsonProperty("changeQuantities", NullValueHandling = NullValueHandling.Ignore)] 38 public ChangeQuantities[] ChangeQuantities { get; set; } 39 40 /// 41 /// 删除的构建属性集合 42 /// 43 44 [JsonProperty("deleteAttributes", NullValueHandling = NullValueHandling.Ignore)] 45 public Attribute[] DeleteAttributes { get; set; } 46 47 /// 48 /// 删除的工程量集合 49 /// 50 51 [JsonProperty("deleteQuantities", NullValueHandling = NullValueHandling.Ignore)] 52 public Quantity[] DeleteQuantities { get; set; } 53 54 /// 55 /// 新增的构建属性集合 56 /// 57 58 [JsonProperty("newAttributes", NullValueHandling = NullValueHandling.Ignore)] 59 public Attribute[] NewAttributes { get; set; } 60 61 /// 62 /// 新增的工程量集合 63 /// 64 65 [JsonProperty("newQuantities", NullValueHandling = NullValueHandling.Ignore)] 66 public Quantity[] NewQuantities { get; set; } 67 } 68 69 /// 70 /// 变更的构建属性 71 /// 72 public class ChangeAttributes 73 { 74 /// 75 /// 前一个版本 76 /// 77 [JsonProperty("_A", NullValueHandling = NullValueHandling.Ignore)] 78 public Attribute A { get; set; } 79 80 /// 81 /// 后一个版本 82 /// 83 [JsonProperty("_B", NullValueHandling = NullValueHandling.Ignore)] 84 public Attribute B { get; set; } 85 } 86 87 /// 88 /// 变更的工程量 89 /// 90 public class ChangeQuantities 91 { 92 /// 93 /// 前一个版本 94 /// 95 [JsonProperty("_A", NullValueHandling = NullValueHandling.Ignore)] 96 public Quantity A { get; set; } 97 98 /// 99 /// 后一个版本 100 /// 101 [JsonProperty("_B", NullValueHandling = NullValueHandling.Ignore)] 102 public Quantity B { get; set; } 103 } 104 105 /// 106 /// 构建属性 107 /// 108 public class Attribute 109 { 110 [JsonProperty("key", NullValueHandling = NullValueHandling.Ignore)] 111 public string Key { get; set; } 112 113 [JsonProperty("value", NullValueHandling = NullValueHandling.Ignore)] 114 public string Value { get; set; } 115 116 [JsonProperty("unit", NullValueHandling = NullValueHandling.Ignore)] 117 public string Unit { get; set; } 118 } 119 120 /// 121 /// 工程量 122 /// 123 public class Quantity 124 { 125 [JsonProperty("code", NullValueHandling = NullValueHandling.Ignore)] 126 public string Code { get; set; } 127 128 [JsonProperty("desc", NullValueHandling = NullValueHandling.Ignore)] 129 public string Desc { get; set; } 130 131 [JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)] 132 public string Name { get; set; } 133 134 [JsonProperty("qty", NullValueHandling = NullValueHandling.Ignore)] 135 public string Qty { get; set; } 136 137 [JsonProperty("unit", NullValueHandling = NullValueHandling.Ignore)] 138 public string Unit { get; set; } 139 }