IRevitEventHandler.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:IRevitEventHandler
  3. * 作者:xulisong
  4. * 创建时间: 2019/1/7 12:59:33
  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. namespace FWindSoft.Revit
  13. {
  14. /// <summary>
  15. /// revit事件处理接口
  16. /// </summary>
  17. public interface IRevitEventHandler
  18. {
  19. void Execute(object sender, EventArgs args);
  20. }
  21. public class RevitEvent: IRevitEventHandler
  22. {
  23. /// <summary>
  24. /// 事件名称
  25. /// </summary>
  26. public string Name { get; set; }
  27. /// <summary>
  28. /// 关联实际处理类型
  29. /// </summary>
  30. private List<IRevitEventHandler> Handlers { get; set; }
  31. public void AddHandler(IRevitEventHandler handler)
  32. {
  33. if (handler == null)
  34. return;
  35. if (Handlers == null)
  36. Handlers = new List<IRevitEventHandler>();
  37. Handlers.Add(handler);
  38. }
  39. public event EventHandler<EventArgs> Handler;
  40. public void Execute(object sender, EventArgs args)
  41. {
  42. if (Handlers == null||!Handlers.Any())
  43. return;
  44. foreach (var revitEventHandler in Handlers)
  45. {
  46. revitEventHandler.Execute(sender, args);
  47. }
  48. Handler?.Invoke(sender, args);
  49. }
  50. }
  51. }