MBIModelInfoUpload.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Autodesk.Revit.DB;
  8. using SAGA.DotNetUtils;
  9. using SAGA.DotNetUtils.Extend;
  10. using SAGA.DotNetUtils.Logger;
  11. using SAGA.MBI.Calc;
  12. using SAGA.MBI.Common;
  13. using SAGA.MBI.DataArrange;
  14. using SAGA.MBI.JsonConvert;
  15. using SAGA.MBI.RequestData;
  16. using SAGA.MBI.RevitExport;
  17. using SAGA.MBI.WinView.TraceView;
  18. using SAGA.Models;
  19. using SAGA.RevitUtils;
  20. namespace SAGA.MBI.Interaction
  21. {
  22. public class MBIModelInfoUpload
  23. { /*
  24. 在文件关闭前做导出;
  25. 在文件上传完成后,再上传配置文件
  26. */
  27. /// <summary>
  28. /// 上传信息点导出信息
  29. /// </summary>
  30. /// <returns></returns>
  31. public static bool UploadMbiInfo(string floorId,string sagaName)
  32. {
  33. bool flag = false;
  34. string key = $"{floorId}"+DateTime.Now.ToString("yyyyMMddHHmmss")+"bim.jsonz";//楼层对应信息文件key值
  35. var db = MbiElementManager.MBIDb;
  36. string jsonStr = string.Empty;
  37. if (db != null)
  38. {
  39. jsonStr = db.ToJsonString(sagaName);
  40. }
  41. //测试使用
  42. //File.WriteAllText(@"c:\" + key, jsonStr);
  43. if (!string.IsNullOrEmpty(jsonStr))
  44. {
  45. var newBytes = Encoding.UTF8.GetBytes(jsonStr);
  46. var gzipBytes = CompressUtil.GZipCompress(newBytes);
  47. var upSuccess = UpLoadFileRequest.UploadFile(FileServiceSetting.RevitSetting, key, gzipBytes);
  48. if (!upSuccess)
  49. return false;
  50. #region 删除旧的底图信息
  51. try
  52. {
  53. var floor =MBIItemFactory.Create<FloorItem>(DalCommon.GetMBIData(floorId));
  54. if (floor != null)
  55. {
  56. var oldFloorKey = floor.FloorMap;
  57. if (!string.IsNullOrEmpty(oldFloorKey))
  58. {
  59. UpLoadFileRequest.DeleteRevitFile(oldFloorKey);
  60. }
  61. }
  62. }
  63. catch (Exception ex)
  64. {
  65. // Logs.Log(ex.StackTrace);
  66. }
  67. #endregion
  68. var jo = CommonTool.GetPropertyJObject(MBIBuiltInParameter.FloorMap, key);
  69. flag=CommonConvert.UpdateInfosSigle(floorId, jo);
  70. }
  71. return flag;
  72. }
  73. /// <summary>
  74. /// 批量获取导出信息
  75. /// </summary>
  76. /// <param name="contexts"></param>
  77. /// <returns></returns>
  78. public static bool UpdateMbiInfo(List<CalcContext> contexts)
  79. {
  80. Dictionary<string,bool> results=new Dictionary<string, bool>();
  81. foreach (var context in contexts)
  82. {
  83. if(context==null)continue;
  84. try
  85. {
  86. //loading完成的进度
  87. LoadingOperation.Update();
  88. context.OpenDocument();
  89. Document doc = context.RevitDoc;
  90. MbiElementManager.ExecuteExport(doc);
  91. var floorId = doc.PathName.GetFileName();
  92. var sagaName = doc.GetUseView()?.Name;
  93. var flag=MBIModelInfoUpload.UploadMbiInfo(floorId, sagaName);
  94. results[floorId] = flag;
  95. }
  96. catch (Exception ex)
  97. {
  98. Log4Net.Debug(ex.StackTrace+"\r\n"+ex.Message);
  99. }
  100. finally
  101. {
  102. context.CloseDocument();
  103. }
  104. }
  105. return results.All(kv=>kv.Value);
  106. }
  107. }
  108. }