123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- using Autodesk.Revit.UI;
- using Autodesk.Revit.UI.Events;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace FWindSoft.Revit
- {
- /// <summary>
- /// 守护命令【该命令队列,可控制是否移除】
- /// </summary>
- public class GuardianIdlingCommand : IRevitRegister
- {
- public List<IdlingCommand> Commands { get; private set; }
- public GuardianIdlingCommand()
- {
- Commands = new List<IdlingCommand>();
- }
- #region 关联命令
- /// <summary>
- /// 对接事件绑定
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- public void ApplicaionIdling(object sender, IdlingEventArgs e)
- {
- var application = sender as UIApplication;
- foreach (var command in Commands)
- {
- command.Raise(application);
- }
- e.SetRaiseWithoutDelay();
- }
- #endregion
- #region 操作命令
- //添加,移除
- public IdlingCommand AddExecute(Func<RevitEventArgs, HandlerResult> handler)
- {
- IdlingCommand command = new IdlingCommand(RevitHandlerFactory.CreateOnceHandler(handler));
- Commands.Add(command);
- return command;
- }
- public IdlingCommand AddExecute(IdlingCommand command)
- {
- if (command == null)
- return null;
- Commands.Add(command);
- return command;
- }
- public void RemoveExecute(IdlingCommand command)
- {
- if (command == null)
- return;
- Commands.Remove(command);
- }
- public void RemoveExecute(string commandName)
- {
- if (string.IsNullOrWhiteSpace(commandName))
- return;
- Commands.RemoveAll(command=>command.Handler?.Name==commandName);
- }
- #endregion
- #region 事件注册相关
- public void Register(ExternalApplication application)
- {
- application.Idling += ApplicaionIdling;
- }
- public void Unregister(ExternalApplication application)
- {
- application.Idling -= ApplicaionIdling;
- }
- #endregion
- }
- }
|