MBIModelInfoUpload.cs 3.5 KB

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