12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- /*-------------------------------------------------------------------------
- * 功能描述:ExportInstance
- * 作者:xulisong
- * 创建时间: 2019/6/13 14:46:48
- * 版本号:v1.0
- * -------------------------------------------------------------------------*/
- using System;
- using System.Collections.Generic;
- namespace RevitExport.Export
- {
- /*
- * 使用event形式,将Export和Parse关联断开
- */
- /// <summary>
- /// 导出实例
- /// </summary>
- public class ExportInstance
- {
- public ExportInstance(List<ElementWrapper> elements)
- {
- ExportElements = elements ?? new List<ElementWrapper>();
- }
- /// <summary>
- /// 待导出元素
- /// </summary>
- private List<ElementWrapper> ExportElements { get; set; }
- #region 导出逻辑相关
- public bool Export()
- {
- if (ExportElements == null)
- return false;
- for (int i = 0; i < ExportElements.Count; i++)
- {
- if (IsCancel)
- return false;
- try
- {
- ElementWrapper revitElementWrapper = ExportElements[i];
- ParseElement?.Invoke(this, new ExportArgs(revitElementWrapper));
- ProcessChanged?.Invoke(i + 1);
- }
- catch (Exception e)
- {
- Console.WriteLine(e);
- }
- }
- return true;
- }
- /// <summary>
- /// 是否取消
- /// </summary>
- public bool IsCancel { get; set; }
- public event EventHandler<ExportArgs> ParseElement;
- public event Action<int> ProcessChanged;
- #endregion
- }
- public class ExportArgs : EventArgs
- {
- public ExportArgs(ElementWrapper elementWrapper)
- {
- ElementWrapper = elementWrapper;
- }
- public ElementWrapper ElementWrapper { get; private set; }
- }
- }
|