123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- /*-------------------------------------------------------------------------
- * 功能描述:TestExport
- * 作者:xulisong
- * 创建时间: 2019/6/18 15:43:54
- * 版本号:v1.0
- * -------------------------------------------------------------------------*/
- using System;
- using System.Collections.Generic;
- using System.IO;
- using Autodesk.Revit.DB;
- using MBIRevitBase.Services;
- using MBIRevitBase.Tools;
- using Newtonsoft.Json;
- using RevitExport.Export;
- using RevitToJBim.ComponentParse;
- using RevitToJBim.JsonConverter;
- using RevitToJBim.MBI;
- using SAGA.DotNetUtils.Logger;
- using ServiceRevitLib.Mode;
- namespace RevitToJBim
- {
- public class MbiExport
- {
- public static string Export(Document document, string param)
- {
- string result = null;
- //导出类
- try
- {
- var wrappers = ExportDataBuilder.CreateExportData(document);
- ExportInstance report = new ExportInstance(wrappers);
- //解析类
- JBimParseContext context = new JBimParseContext(ParseCore.GetUseParsers());
- context.Parser.Parse(report);
- //构建需要结果
- var mbiDocument = MBIDocument.CreateDocument(document, param);
- mbiDocument.AttachElements(context.GetResultDocument());
- /*
- * 序列化的变化封装在这里,增加MBIDocument传输数据对象,
- * 增加一些和JBIM无关,又和当前业务逻辑相关的属性
- */
- var json = BimJsonUtil.Serializer(mbiDocument);
- #if DEBUG
- //保存到本地
- string fileName = DateTime.Now.ToString("yyyyMMddHHmmss");
- string path = Path.Combine($"{document.PathName}_{fileName}.json");
- File.WriteAllText(path, json.ToString());
- #endif
- Log4Net.Info("Begin UploadExportFile");
- var resultResponse = UploadService.UploadExportFile(json);
- result = BimJsonUtil.Serializer((ResultBase)resultResponse);
- Log4Net.Info("End UploadExportFile");
- }
- catch (Exception ex)
- {
- result = BimJsonUtil.Serializer(ResultBase.Exception(ex.Message + ex.StackTrace));
- }
- return result;
- }
- }
- }
|