MbiExport.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 Autodesk.Revit.DB;
  11. using MBIRevitBase.Services;
  12. using MBIRevitBase.Tools;
  13. using Newtonsoft.Json;
  14. using RevitExport.Export;
  15. using RevitToJBim.ComponentParse;
  16. using RevitToJBim.JsonConverter;
  17. using RevitToJBim.MBI;
  18. using SAGA.DotNetUtils.Logger;
  19. using ServiceRevitLib.Mode;
  20. namespace RevitToJBim
  21. {
  22. public class MbiExport
  23. {
  24. public static string Export(Document document, string param)
  25. {
  26. string result = null;
  27. //导出类
  28. try
  29. {
  30. var wrappers = ExportDataBuilder.CreateExportData(document);
  31. ExportInstance report = new ExportInstance(wrappers);
  32. //解析类
  33. JBimParseContext context = new JBimParseContext(ParseCore.GetUseParsers());
  34. context.Parser.Parse(report);
  35. //构建需要结果
  36. var mbiDocument = MBIDocument.CreateDocument(document, param);
  37. mbiDocument.AttachElements(context.GetResultDocument());
  38. /*
  39. * 序列化的变化封装在这里,增加MBIDocument传输数据对象,
  40. * 增加一些和JBIM无关,又和当前业务逻辑相关的属性
  41. */
  42. var json = BimJsonUtil.Serializer(mbiDocument);
  43. #if DEBUG
  44. //保存到本地
  45. string fileName = DateTime.Now.ToString("yyyyMMddHHmmss");
  46. string path = Path.Combine($"{document.PathName}_{fileName}.json");
  47. File.WriteAllText(path, json.ToString());
  48. #endif
  49. Log4Net.Info("Begin UploadExportFile");
  50. var resultResponse = UploadService.UploadExportFile(json);
  51. result = BimJsonUtil.Serializer((ResultBase)resultResponse);
  52. Log4Net.Info("End UploadExportFile");
  53. }
  54. catch (Exception ex)
  55. {
  56. result = BimJsonUtil.Serializer(ResultBase.Exception(ex.Message + ex.StackTrace));
  57. }
  58. return result;
  59. }
  60. }
  61. }