RevitUpdater.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:RevitUpdater
  3. * 作者:xulisong
  4. * 创建时间: 2018/12/28 10:22:35
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using Autodesk.Revit.DB;
  13. namespace FWindSoft.Revit
  14. {
  15. /*
  16. * 不知道revit的机制是不是一样的触发器会合并所有Updater,待测试。
  17. * 但一个updater可以被几个触发器关联
  18. */
  19. public class RevitUpdater : IUpdater
  20. {
  21. /*
  22. * 可以通过扩展继承该类
  23. */
  24. protected Action<UpdaterData> m_Execute;
  25. public RevitUpdater(UpdaterId id, Action<UpdaterData> execute)
  26. {
  27. this.Id = id;
  28. this.m_Execute = execute;
  29. }
  30. #region 接口继承方法
  31. public virtual void Execute(UpdaterData data)
  32. {
  33. if (m_Execute != null)
  34. {
  35. m_Execute(data);
  36. }
  37. }
  38. public string GetAdditionalInformation()
  39. {
  40. return AdditionalInformation ?? string.Empty;
  41. }
  42. public ChangePriority GetChangePriority()
  43. {
  44. return ChangePriority;
  45. }
  46. public UpdaterId GetUpdaterId()
  47. {
  48. return Id;
  49. }
  50. public string GetUpdaterName()
  51. {
  52. return UpdaterName ?? this.GetType().ToString();
  53. }
  54. #endregion
  55. #region 相关属性延伸
  56. /// <summary>
  57. /// 附加信息
  58. /// </summary>
  59. public string AdditionalInformation { get; set; }
  60. /// <summary>
  61. /// 触发器名称
  62. /// </summary>
  63. public string UpdaterName { get; set; }
  64. /// <summary>
  65. /// 改变优先级
  66. /// </summary>
  67. public ChangePriority ChangePriority { get; set; }
  68. /// <summary>
  69. /// UpdaterId
  70. /// </summary>
  71. public UpdaterId Id { get; protected set; }
  72. #endregion
  73. #region 注册和注销
  74. private bool IsExistId(Document doc)
  75. {
  76. bool flag = false;
  77. if (doc == null)
  78. {
  79. flag = UpdaterRegistry.IsUpdaterRegistered(this.GetUpdaterId());
  80. }
  81. else
  82. {
  83. flag = UpdaterRegistry.IsUpdaterRegistered(this.GetUpdaterId(), doc);
  84. }
  85. return flag;
  86. }
  87. public void RegisterUpdater(Document doc, bool isOptional = true)
  88. {
  89. if (IsExistId(doc))
  90. return;
  91. if (doc == null)
  92. {
  93. UpdaterRegistry.RegisterUpdater(this, isOptional);
  94. }
  95. else
  96. {
  97. UpdaterRegistry.RegisterUpdater(this, doc, isOptional);
  98. }
  99. }
  100. public void UnregisterUpdater(Document doc)
  101. {
  102. if (!IsExistId(doc))
  103. return;
  104. if (doc == null)
  105. {
  106. UpdaterRegistry.UnregisterUpdater(this.Id);
  107. }
  108. else
  109. {
  110. UpdaterRegistry.UnregisterUpdater(this.Id, doc);
  111. }
  112. }
  113. #endregion
  114. }
  115. }