using System;
|
using System.Collections.Generic;
|
using System.IO;
|
using System.Linq;
|
using System.Net;
|
using System.Text;
|
using IStation.Bimface;
|
|
namespace IStation
|
{
|
/// <summary>
|
/// ViewToken
|
/// </summary>
|
public sealed partial class BimfaceClient
|
{
|
/// <summary>
|
/// 获取ViewToken
|
/// </summary>
|
public string GetViewToken(long id, eModelIdType modeltype = eModelIdType.fileId)
|
{
|
GetAccessToken();
|
if (_expiretime.ValidViewTokenExpiration(id, DateTime.Now))
|
getViewToken(id, modeltype);
|
return _viewtokenDic[id];
|
}
|
|
//视图令牌请求地址
|
private const string _viewtokenurl = @"https://api.bimface.com/view/token";
|
|
//获取ViewToken,内部调用
|
private void getViewToken(long id, eModelIdType modeltype = eModelIdType.fileId)
|
{
|
var url = string.Format("{0}?{1}={2}", _viewtokenurl, modeltype.ToString(), id);
|
using (var httpClient = new HttpClient())
|
{
|
httpClient.DefaultRequestHeaders.Add("Method","Get");
|
var header = new HttpHeaders().GetBasicAuthorHeader(_accesstoken);
|
httpClient.DefaultRequestHeaders.Add(header.Key, header.Value);
|
var response=httpClient.GetAsync(url).Result;
|
response.EnsureSuccessStatusCode();
|
var responsetext=response.Content.ReadAsStringAsync().Result;
|
var result = JsonHelper.Json2Object<Result<string>>(responsetext);
|
if (result.code != Constants.Success)
|
{
|
throw new BimfaceException(result.code);
|
}
|
if (_viewtokenDic.ContainsKey(id))
|
_viewtokenDic[id] = result.data;
|
else
|
_viewtokenDic.Add(id, result.data);
|
_expiretime.SetViewTokenGetTime(id, DateTime.Now);
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
}
|