1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- 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 IdlingEventCommand: IRevitRegister
- {
- #region 初始化
- public IdlingEventCommand()
- {
- Commands = new IdlingCommands();
- }
- /// <summary>
- /// 命令队列
- /// </summary>
- private readonly IdlingCommands Commands;
- #endregion
- #region 消费队列
- /// <summary>
- /// 对接事件绑定
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- protected void ApplicaionIdling(object sender, IdlingEventArgs e)
- {
- IdlingCommand currentCommand = Commands.Dequeue();
- if (currentCommand != null)
- {
- currentCommand.Raise(sender as UIApplication);
- e.SetRaiseWithoutDelay();
- }
- }
- #endregion
- #region 生产队列
- public IdlingCommand OnceExecute(Func<RevitEventArgs, HandlerResult> handler, Action<RevitEventArgs> callBack)
- {
- IdlingCommand command = new IdlingCommand(RevitHandlerFactory.CreateOnceHandler(handler, callBack));
- Commands.Enqueue(command);
- return command;
- }
- public IdlingCommand WhileExecute(Func<RevitEventArgs, HandlerResult> handler, Action<RevitEventArgs> callBack)
- {
- IdlingCommand command = new IdlingCommand(RevitHandlerFactory.CreateWhileHandler(handler, callBack));
- Commands.Enqueue(command);
- return command;
- }
- public IdlingCommand Execute(IdlingCommand command)
- {
- if (command == null)
- return null;
- Commands.Enqueue(command);
- return command;
- }
- #endregion
- #region 事件注册相关
- public void Register(ExternalApplication application)
- {
- application.Idling += ApplicaionIdling;
- }
- public void Unregister(ExternalApplication application)
- {
- application.Idling -= ApplicaionIdling;
- }
- #endregion
- }
- }
|