ExportInstance.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:ExportInstance
  3. * 作者:xulisong
  4. * 创建时间: 2019/6/13 14:46:48
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using System;
  8. using System.Collections.Generic;
  9. namespace RevitExport.Export
  10. {
  11. /*
  12. * 使用event形式,将Export和Parse关联断开
  13. */
  14. /// <summary>
  15. /// 导出实例
  16. /// </summary>
  17. public class ExportInstance
  18. {
  19. public ExportInstance(List<ElementWrapper> elements)
  20. {
  21. ExportElements = elements ?? new List<ElementWrapper>();
  22. }
  23. /// <summary>
  24. /// 待导出元素
  25. /// </summary>
  26. private List<ElementWrapper> ExportElements { get; set; }
  27. #region 导出逻辑相关
  28. public bool Export()
  29. {
  30. if (ExportElements == null)
  31. return false;
  32. for (int i = 0; i < ExportElements.Count; i++)
  33. {
  34. if (IsCancel)
  35. return false;
  36. try
  37. {
  38. ElementWrapper revitElementWrapper = ExportElements[i];
  39. ParseElement?.Invoke(this, new ExportArgs(revitElementWrapper));
  40. ProcessChanged?.Invoke(i + 1);
  41. }
  42. catch (Exception e)
  43. {
  44. Console.WriteLine(e);
  45. }
  46. }
  47. return true;
  48. }
  49. /// <summary>
  50. /// 是否取消
  51. /// </summary>
  52. public bool IsCancel { get; set; }
  53. public event EventHandler<ExportArgs> ParseElement;
  54. public event Action<int> ProcessChanged;
  55. #endregion
  56. }
  57. public class ExportArgs : EventArgs
  58. {
  59. public ExportArgs(ElementWrapper elementWrapper)
  60. {
  61. ElementWrapper = elementWrapper;
  62. }
  63. public ElementWrapper ElementWrapper { get; private set; }
  64. }
  65. }