/*------------------------------------------------------------------------- * 功能描述:RevitUpdater * 作者:xulisong * 创建时间: 2018/12/28 10:22:35 * 版本号:v1.0 * -------------------------------------------------------------------------*/ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Autodesk.Revit.DB; namespace FWindSoft.Revit { /* * 不知道revit的机制是不是一样的触发器会合并所有Updater,待测试。 * 但一个updater可以被几个触发器关联 */ public class RevitUpdater : IUpdater { /* * 可以通过扩展继承该类 */ protected Action m_Execute; public RevitUpdater(UpdaterId id, Action execute) { this.Id = id; this.m_Execute = execute; } #region 接口继承方法 public virtual void Execute(UpdaterData data) { if (m_Execute != null) { m_Execute(data); } } public string GetAdditionalInformation() { return AdditionalInformation ?? string.Empty; } public ChangePriority GetChangePriority() { return ChangePriority; } public UpdaterId GetUpdaterId() { return Id; } public string GetUpdaterName() { return UpdaterName ?? this.GetType().ToString(); } #endregion #region 相关属性延伸 /// /// 附加信息 /// public string AdditionalInformation { get; set; } /// /// 触发器名称 /// public string UpdaterName { get; set; } /// /// 改变优先级 /// public ChangePriority ChangePriority { get; set; } /// /// UpdaterId /// public UpdaterId Id { get; protected set; } #endregion #region 注册和注销 private bool IsExistId(Document doc) { bool flag = false; if (doc == null) { flag = UpdaterRegistry.IsUpdaterRegistered(this.GetUpdaterId()); } else { flag = UpdaterRegistry.IsUpdaterRegistered(this.GetUpdaterId(), doc); } return flag; } public void RegisterUpdater(Document doc, bool isOptional = true) { if (IsExistId(doc)) return; if (doc == null) { UpdaterRegistry.RegisterUpdater(this, isOptional); } else { UpdaterRegistry.RegisterUpdater(this, doc, isOptional); } } public void UnregisterUpdater(Document doc) { if (!IsExistId(doc)) return; if (doc == null) { UpdaterRegistry.UnregisterUpdater(this.Id); } else { UpdaterRegistry.UnregisterUpdater(this.Id, doc); } } #endregion } }