UpdaterRegister.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:UpdaterRegister
  3. * 作者:xulisong
  4. * 创建时间: 2018/12/28 10:24:24
  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. using Autodesk.Revit.UI;
  14. namespace FWindSoft.Revit
  15. {
  16. /// <summary>
  17. /// 注册updater相关
  18. /// </summary>
  19. public abstract class UpdaterRegister : IRevitRegister
  20. {
  21. public UpdaterRegister()
  22. {
  23. }
  24. /// <summary>
  25. /// 关联项目
  26. /// </summary>
  27. public Document RefDocument { get; set; }
  28. public bool IsOptional { get; set; }
  29. /// <summary>
  30. /// 当前updater,注册后生效
  31. /// </summary>
  32. public RevitUpdater CurrentUpdater { get; private set; }
  33. public virtual void Register(ExternalApplication application)
  34. {
  35. //这里会不会导致重复注册,CurrentUpdater内存泄漏无法卸载
  36. CurrentUpdater = GetUpdater(application);
  37. if (CurrentUpdater == null)
  38. return;
  39. CurrentUpdater.RegisterUpdater(RefDocument, IsOptional);
  40. var triggers = GetTriggers(application);
  41. foreach (var revitTrigger in triggers)
  42. {
  43. revitTrigger.AttachUpdater(CurrentUpdater);
  44. }
  45. }
  46. public virtual void Unregister(ExternalApplication application)
  47. {
  48. CurrentUpdater = CurrentUpdater ?? GetUpdater(application);
  49. if (CurrentUpdater == null)
  50. {
  51. return;
  52. }
  53. CurrentUpdater.UnregisterUpdater(RefDocument);
  54. }
  55. protected abstract List<RevitTrigger> GetTriggers(ExternalApplication application);
  56. protected abstract RevitUpdater GetUpdater(ExternalApplication application);
  57. }
  58. }