C#开发BIMFACE系列34 服务端API之模型对比5:获取模型构件对比差异
阅读原文时间:2021年10月09日阅读:1

系列目录     【已更新最新开发文章,点击查看详细】

  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):

{
"code" : "success",
"data" : {
"_A" : "string",
"_B" : "string",
"changeAttributes" : [ {
"_A" : {
"key" : "key",
"unit" : "unit",
"value" : "value"
},
"_B" : {
"key" : "key",
"unit" : "unit",
"value" : "value"
}
} ],
"changeQuantities" : [ {
"_A" : {
"code" : "code",
"desc" : "desc",
"name" : "name",
"qty" : ,
"unit" : "unit"
},
"_B" : {
"code" : "code",
"desc" : "desc",
"name" : "name",
"qty" : ,
"unit" : "unit"
}
} ],
"deleteAttributes" : [ {
"key" : "key",
"unit" : "unit",
"value" : "value"
} ],
"deleteQuantities" : [ {
"code" : "code",
"desc" : "desc",
"name" : "name",
"qty" : ,
"unit" : "unit"
} ],
"newAttributes" : [ {
"key" : "key",
"unit" : "unit",
"value" : "value"
} ],
"newQuantities" : [ {
"code" : "code",
"desc" : "desc",
"name" : "name",
"qty" : ,
"unit" : "unit"
} ]
},
"message" : ""
}

C#实现方法:

///

/// 获取模型构件对比差异 ///
/// 【必填】令牌
/// 【必填】对比ID
/// 【必填】变更后的文件ID
/// 【必填】变更后的文件的构件ID
/// 【必填】变更前的文件ID
/// 【必填】变更前的文件的构件ID
///
public virtual ModelCompareChangeResponse GetModelCompareChange(string accessToken, long compareId,
long followingFileId, string followingElementId, long previousFileId, string previousElementId)
{
// GET https: //api.bimface.com/data/v2/comparisons/{comparisonId}/elementChange
string url = string.Format(BimfaceConstants.API_HOST + "/data/v2/comparisons/{0}/elementChange", compareId);
url += "?followingFileId=" + followingFileId;
url += "&followingElementId=" + followingElementId;
url += "&previousFileId=" + previousFileId;
url += "&previousElementId=" + previousElementId;

 BimFaceHttpHeaders headers = new BimFaceHttpHeaders();  
 headers.AddOAuth2Header(accessToken);

 try  
 {  
     ModelCompareChangeResponse response;

     HttpManager httpManager = new HttpManager(headers);  
     HttpResult httpResult = httpManager.Get(url);  
     if (httpResult.Status == HttpResult.STATUS\_SUCCESS)  
     {  
         response = httpResult.Text.DeserializeJsonToObject<ModelCompareChangeResponse>();  
     }  
     else  
     {  
         response = new ModelCompareChangeResponse  
         {  
             Message = httpResult.RefText  
         };  
     }

     return response;  
 }  
 catch (Exception ex)  
 {  
     throw new Exception("\[获取模型构件对比差异\]发生异常!", ex);  
 }  

}

代码中使用的 HttpManager 类请参考我的博客文章《C# HTTP系列 HttpWebRequest 与 HttpWebResponse》。

返回类型  ModelCompareChangeResponse 类如下:

///

/// 获取模型构件对比差异的响应类 ///
public class ModelCompareChangeResponse : GeneralResponse
{

}

///

/// 模型构件对比差异类 ///
public class ModelCompareChange
{
/// /// 变化图元前一个版本的ID ///
[JsonProperty("_A", NullValueHandling = NullValueHandling.Ignore)]
public string A { get; set; }

 /// <summary>  
 /// 变化图元后一个版本的ID  
 /// </summary>  
 \[JsonProperty("\_B", NullValueHandling = NullValueHandling.Ignore)\]  
 public string B { get; set; }

 /// <summary>  
 ///  变更的构建属性集合  
 /// </summary>

 \[JsonProperty("changeAttributes", NullValueHandling = NullValueHandling.Ignore)\]  
 public ChangeAttributes\[\] ChangeAttributes { get; set; }

 /// <summary>  
 ///  变更的工程量集合  
 /// </summary>

 \[JsonProperty("changeQuantities", NullValueHandling = NullValueHandling.Ignore)\]  
 public ChangeQuantities\[\] ChangeQuantities { get; set; }

 /// <summary>  
 ///  删除的构建属性集合  
 /// </summary>

 \[JsonProperty("deleteAttributes", NullValueHandling = NullValueHandling.Ignore)\]  
 public Attribute\[\] DeleteAttributes { get; set; }

 /// <summary>  
 ///  删除的工程量集合  
 /// </summary>

 \[JsonProperty("deleteQuantities", NullValueHandling = NullValueHandling.Ignore)\]  
 public Quantity\[\] DeleteQuantities { get; set; }

 /// <summary>  
 ///  新增的构建属性集合  
 /// </summary>

 \[JsonProperty("newAttributes", NullValueHandling = NullValueHandling.Ignore)\]  
 public Attribute\[\] NewAttributes { get; set; }

 /// <summary>  
 ///  新增的工程量集合  
 /// </summary>

 \[JsonProperty("newQuantities", NullValueHandling = NullValueHandling.Ignore)\]  
 public Quantity\[\] NewQuantities { get; set; }  

}

///

/// 变更的构建属性 ///
public class ChangeAttributes
{
/// /// 前一个版本 ///
[JsonProperty("_A", NullValueHandling = NullValueHandling.Ignore)]
public Attribute A { get; set; }

 /// <summary>  
 /// 后一个版本  
 /// </summary>  
 \[JsonProperty("\_B", NullValueHandling = NullValueHandling.Ignore)\]  
 public Attribute B { get; set; }  

}

///

/// 变更的工程量 ///
public class ChangeQuantities
{
/// /// 前一个版本 ///
[JsonProperty("_A", NullValueHandling = NullValueHandling.Ignore)]
public Quantity A { get; set; }

 /// <summary>  
 /// 后一个版本  
 /// </summary>  
 \[JsonProperty("\_B", NullValueHandling = NullValueHandling.Ignore)\]  
 public Quantity B { get; set; }  

}

///

/// 构建属性 ///
public class Attribute
{
[JsonProperty("key", NullValueHandling = NullValueHandling.Ignore)]
public string Key { get; set; }

 \[JsonProperty("value", NullValueHandling = NullValueHandling.Ignore)\]  
 public string Value { get; set; }

 \[JsonProperty("unit", NullValueHandling = NullValueHandling.Ignore)\]  
 public string Unit { get; set; }  

}

///

/// 工程量 ///
public class Quantity
{
[JsonProperty("code", NullValueHandling = NullValueHandling.Ignore)]
public string Code { get; set; }

 \[JsonProperty("desc", NullValueHandling = NullValueHandling.Ignore)\]  
 public string Desc { get; set; }

 \[JsonProperty("name", NullValueHandling = NullValueHandling.Ignore)\]  
 public string Name { get; set; }

 \[JsonProperty("qty", NullValueHandling = NullValueHandling.Ignore)\]  
 public string Qty { get; set; }

 \[JsonProperty("unit", NullValueHandling = NullValueHandling.Ignore)\]  
 public string Unit { get; set; }  

}

系列目录     【已更新最新开发文章,点击查看详细】

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章