MbiExport.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:TestExport
  3. * 作者:xulisong
  4. * 创建时间: 2019/6/18 15:43:54
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using System;
  8. using System.Collections.Generic;
  9. using System.IO;
  10. using System.Linq;
  11. using Autodesk.Revit.DB;
  12. using MBIRevitBase.Services;
  13. using MBIRevitBase.Tools;
  14. using Newtonsoft.Json;
  15. using RevitExport.Export;
  16. using RevitToJBim.ComponentParse;
  17. using RevitToJBim.JsonConverter;
  18. using RevitToJBim.MBI;
  19. using SAGA.DotNetUtils.Logger;
  20. using ServiceRevitLib.Mode;
  21. namespace RevitToJBim
  22. {
  23. public class MbiExport
  24. {
  25. public static string Export(Document document, string param)
  26. {
  27. string result = null;
  28. //导出类
  29. try
  30. {
  31. var wrappers = ExportDataBuilder.CreateExportData(document);
  32. var cats = wrappers.Select(w => w.Category).Distinct().ToList();
  33. ExportInstance report = new ExportInstance(wrappers);
  34. //解析类
  35. var parsers = ParseCore.GetUseParsers();
  36. JBimParseContext context = new JBimParseContext(parsers);
  37. context.Parser.Parse(report);
  38. //构建需要结果
  39. var mbiDocument = MBIDocument.CreateDocument(document, param);
  40. mbiDocument.AttachElements(context.GetResultDocument());
  41. /*
  42. * 序列化的变化封装在这里,增加MBIDocument传输数据对象,
  43. * 增加一些和JBIM无关,又和当前业务逻辑相关的属性
  44. */
  45. var json = BimJsonUtil.Serializer(mbiDocument);
  46. //var json = File.ReadAllText(@"E:\88.rvt_20191219141937.json");
  47. #if DEBUG
  48. //保存到本地
  49. string fileName = DateTime.Now.ToString("yyyyMMddHHmmss");
  50. string path = Path.Combine($"{document.PathName}_{fileName}.json");
  51. File.WriteAllText(path, json.ToString());
  52. #endif
  53. Log4Net.Debug("Begin UploadExportFile");
  54. var resultResponse = UploadService.UploadExportFile(json);
  55. result = BimJsonUtil.Serializer((ResultBase)resultResponse);
  56. Log4Net.Debug("End UploadExportFile");
  57. }
  58. catch (Exception ex)
  59. {
  60. result = BimJsonUtil.Serializer(ResultBase.Exception(ex.Message + ex.StackTrace));
  61. }
  62. return result;
  63. }
  64. }
  65. }