123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- /*-------------------------------------------------------------------------
- * 功能描述: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<UpdaterData> m_Execute;
- public RevitUpdater(UpdaterId id, Action<UpdaterData> 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 相关属性延伸
- /// <summary>
- /// 附加信息
- /// </summary>
- public string AdditionalInformation { get; set; }
- /// <summary>
- /// 触发器名称
- /// </summary>
- public string UpdaterName { get; set; }
- /// <summary>
- /// 改变优先级
- /// </summary>
- public ChangePriority ChangePriority { get; set; }
- /// <summary>
- /// UpdaterId
- /// </summary>
- 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
- }
- }
|