ExportInstance.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. ElementWrapper revitElementWrapper = ExportElements[i];
  37. ParseElement?.Invoke(this, new ExportArgs(revitElementWrapper));
  38. ProcessChanged?.Invoke(i + 1);
  39. }
  40. return true;
  41. }
  42. /// <summary>
  43. /// 是否取消
  44. /// </summary>
  45. public bool IsCancel { get; set; }
  46. public event EventHandler<ExportArgs> ParseElement;
  47. public event Action<int> ProcessChanged;
  48. #endregion
  49. }
  50. public class ExportArgs : EventArgs
  51. {
  52. public ExportArgs(ElementWrapper elementWrapper)
  53. {
  54. ElementWrapper = elementWrapper;
  55. }
  56. public ElementWrapper ElementWrapper { get; private set; }
  57. }
  58. }