123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Autodesk.Revit.DB;
- using SAGA.DotNetUtils;
- using SAGA.DotNetUtils.Extend;
- using SAGA.DotNetUtils.Logger;
- using SAGA.MBI.Calc;
- using SAGA.MBI.Common;
- using SAGA.MBI.DataArrange;
- using SAGA.MBI.JsonConvert;
- using SAGA.MBI.RequestData;
- using SAGA.MBI.RevitExport;
- using SAGA.MBI.WinView.TraceView;
- using SAGA.Models;
- using SAGA.RevitUtils;
- namespace SAGA.MBI.Interaction
- {
- public class MBIModelInfoUpload
- { /*
- 在文件关闭前做导出;
- 在文件上传完成后,再上传配置文件
- */
- /// <summary>
- /// 上传信息点导出信息
- /// </summary>
- /// <returns></returns>
- public static bool UploadMbiInfo(string floorId,string sagaName)
- {
- bool flag = false;
- string key = $"{floorId}"+DateTime.Now.ToString("yyyyMMddHHmmss")+"bim.jsonz";//楼层对应信息文件key值
- var db = MbiElementManager.MBIDb;
- string jsonStr = string.Empty;
- if (db != null)
- {
- jsonStr = db.ToJsonString(sagaName);
- }
- //测试使用
- //File.WriteAllText(@"c:\" + key, jsonStr);
- if (!string.IsNullOrEmpty(jsonStr))
- {
- var newBytes = Encoding.UTF8.GetBytes(jsonStr);
- var gzipBytes = CompressUtil.GZipCompress(newBytes);
- var upSuccess = UpLoadFileRequest.UploadFile(FileServiceSetting.RevitSetting, key, gzipBytes);
- if (!upSuccess)
- return false;
- #region 删除旧的底图信息
- try
- {
- var floor =MBIItemFactory.Create<FloorItem>(DalCommon.GetMBIData(floorId));
- if (floor != null)
- {
- var oldFloorKey = floor.FloorMap;
- if (!string.IsNullOrEmpty(oldFloorKey))
- {
- UpLoadFileRequest.DeleteRevitFile(oldFloorKey);
- }
- }
- }
- catch (Exception ex)
- {
-
- // Logs.Log(ex.StackTrace);
- }
- #endregion
- var jo = CommonTool.GetPropertyJObject(MBIBuiltInParameter.FloorMap, key);
- flag=CommonConvert.UpdateInfosSigle(floorId, jo);
- }
- return flag;
- }
- /// <summary>
- /// 批量获取导出信息
- /// </summary>
- /// <param name="contexts"></param>
- /// <returns></returns>
- public static bool UpdateMbiInfo(List<CalcContext> contexts)
- {
- Dictionary<string,bool> results=new Dictionary<string, bool>();
- foreach (var context in contexts)
- {
- if(context==null)continue;
- try
- {
- //loading完成的进度
- LoadingOperation.Update();
- context.OpenDocument();
- Document doc = context.RevitDoc;
- MbiElementManager.ExecuteExport(doc);
- var floorId = doc.PathName.GetFileName();
- var sagaName = doc.GetUseView()?.Name;
- var flag=MBIModelInfoUpload.UploadMbiInfo(floorId, sagaName);
- results[floorId] = flag;
- }
- catch (Exception ex)
- {
- Log4Net.Debug(ex.StackTrace+"\r\n"+ex.Message);
- }
- finally
- {
- context.CloseDocument();
- }
- }
- return results.All(kv=>kv.Value);
- }
- }
- }
|