| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- /*-------------------------------------------------------------------------
- * 功能描述:UpdaterRegister
- * 作者:xulisong
- * 创建时间: 2018/12/28 10:24:24
- * 版本号:v1.0
- * -------------------------------------------------------------------------*/
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Autodesk.Revit.DB;
- using Autodesk.Revit.UI;
- namespace FWindSoft.Revit
- {
- /// <summary>
- /// 注册updater相关
- /// </summary>
- public abstract class UpdaterRegister : IRevitRegister
- {
- public UpdaterRegister()
- {
- }
- /// <summary>
- /// 关联项目
- /// </summary>
- public Document RefDocument { get; set; }
- public bool IsOptional { get; set; }
- /// <summary>
- /// 当前updater,注册后生效
- /// </summary>
- public RevitUpdater CurrentUpdater { get; private set; }
-
- public virtual void Register(ExternalApplication application)
- {
- //这里会不会导致重复注册,CurrentUpdater内存泄漏无法卸载
- CurrentUpdater = GetUpdater(application);
- if (CurrentUpdater == null)
- return;
- CurrentUpdater.RegisterUpdater(RefDocument, IsOptional);
- var triggers = GetTriggers(application);
- foreach (var revitTrigger in triggers)
- {
- revitTrigger.AttachUpdater(CurrentUpdater);
- }
- }
-
- public virtual void Unregister(ExternalApplication application)
- {
- CurrentUpdater = CurrentUpdater ?? GetUpdater(application);
- if (CurrentUpdater == null)
- {
- return;
- }
- CurrentUpdater.UnregisterUpdater(RefDocument);
- }
- protected abstract List<RevitTrigger> GetTriggers(ExternalApplication application);
- protected abstract RevitUpdater GetUpdater(ExternalApplication application);
- }
- }
|