using System;
|
using System.Collections.Generic;
|
using System.IO;
|
using System.Linq;
|
using System.Net;
|
using System.Text;
|
using IStation.Bimface;
|
|
namespace IStation
|
{
|
/// <summary>
|
/// 获取
|
/// </summary>
|
public sealed partial class BimfaceClient
|
{
|
/// <summary>
|
/// 获取构件Id列表(只使用与3D模型)
|
/// </summary>
|
/// <param name="fileid"></param>
|
/// <returns></returns>
|
public List<string> GetAllComponentIds(long fileid)
|
{
|
GetAccessToken();
|
//var data = JsonHelper.Object2Json(new FileElementsGetRequest().GetJsonDict());
|
var url = string.Format("https://api.bimface.com/data/v2/files/{0}/elementIds", fileid);
|
using (var httpClient = new HttpClient())
|
using (var request=new HttpRequestMessage(HttpMethod.Get,url))
|
{
|
var autoHeader = new HttpHeaders().GetBasicAuthorHeader(_accesstoken);
|
request.Headers.Add(autoHeader.Key, autoHeader.Value);
|
//request.Content= new StringContent(data,Encoding.UTF8, "application/json");
|
var response=httpClient.SendAsync(request).Result;
|
response.EnsureSuccessStatusCode();
|
var responsetext = response.Content.ReadAsStringAsync().Result;
|
var result = JsonHelper.Json2Object<Result<List<string>>>(responsetext);
|
if (result.code != Constants.Success)
|
{
|
throw new BimfaceException(result.code);
|
}
|
return result.data;
|
}
|
}
|
|
/// <summary>
|
/// 批量获取构件属性
|
/// </summary>
|
/// <param name="fileId"></param>
|
/// <param name="includeOverrides"></param>
|
/// <returns></returns>
|
public List<ComponentProperty> GetComponentPropertiesByIds(long fileId, List<string> elementIds, bool? includeOverrides = null)
|
{
|
GetAccessToken();
|
var data = JsonHelper.Object2Json(new ElementPropertyFilterRequest() { elementIds = elementIds }.GetJsonDict());
|
string url = string.Format("https://api.bimface.com/data/v2/files/{0}/elements", fileId);
|
if (includeOverrides != null)
|
{
|
url += "?includeOverrides=" + includeOverrides;
|
}
|
using (var httpClient = new HttpClient())
|
using (var request = new HttpRequestMessage(HttpMethod.Post, url))
|
{
|
var autoHeader = new HttpHeaders().GetBasicAuthorHeader(_accesstoken);
|
request.Headers.Add(autoHeader.Key, autoHeader.Value);
|
request.Content=new StringContent(data, Encoding.UTF8, "application/json");
|
var response = httpClient.SendAsync(request).Result;
|
response.EnsureSuccessStatusCode();
|
var responsetext=response.Content.ReadAsStringAsync().Result;
|
var result = JsonHelper.Json2Object<Result<List<ComponentProperty>>>(responsetext);
|
if (result.code != Constants.Success)
|
{
|
throw new BimfaceException(result.code);
|
}
|
return result.data;
|
}
|
}
|
|
/// <summary>
|
/// 通过条件获取构件属性
|
/// </summary>
|
/// <param name="fileId"></param>
|
/// <param name="elementIds"></param>
|
/// <param name="includeOverrides"></param>
|
/// <returns></returns>
|
public List<ComponentProperty> GetComponentPropertiesByFiter(long fileId, List<string> elementIds, string group, List<string> keys, bool? includeOverrides = null)
|
{
|
GetAccessToken();
|
var requestBody = new ElementPropertyFilterRequest() { elementIds = elementIds };
|
var groupFilter = new GroupAndKeysPair() { group = group, keys = keys };
|
requestBody.filter = new List<GroupAndKeysPair>() { groupFilter };
|
var data = JsonHelper.Object2Json(requestBody.GetJsonDict());
|
string url = string.Format("https://api.bimface.com/data/v2/files/{0}/elements", fileId);
|
if (includeOverrides != null)
|
{
|
url += "?includeOverrides=" + includeOverrides;
|
}
|
using (var httpClient = new HttpClient())
|
using (var request = new HttpRequestMessage(HttpMethod.Post, url))
|
{
|
var autoHeader = new HttpHeaders().GetBasicAuthorHeader(_accesstoken);
|
request.Headers.Add(autoHeader.Key, autoHeader.Value);
|
request.Content=new StringContent(data,Encoding.UTF8, "application/json");
|
var response = httpClient.Send(request);
|
response.EnsureSuccessStatusCode();
|
var responsetext=response.Content.ReadAsStringAsync().Result;
|
var result = JsonHelper.Json2Object<Result<List<ComponentProperty>>>(responsetext);
|
if (result.code != Constants.Success)
|
{
|
throw new BimfaceException(result.code);
|
}
|
return result.data;
|
}
|
}
|
|
|
}
|
|
}
|