using Autodesk.Revit.UI;
namespace FWindSoft.Revit
{
/*
* 验证是否是同步,不是同步的话,则需要提供回调函数
*/
///
/// 扩展事件
///
public class ExternalEventCommand
{
public ExternalEventCommand(RevitHandler handler) : this(handler, true)
{
}
public ExternalEventCommand(RevitHandler handler, bool createRefCommand)
{
Handler = handler;
if (createRefCommand)
{
CreateEvent();
}
}
///
/// 命令实际处理者
///
public RevitHandler Handler { get; private set; }
///
/// 生成Event
///
///
public ExternalEvent CreateEvent()
{
if (Handler != null && Event == null)
{
Event = ExternalEvent.Create(Handler);
}
return Event;
}
#region 关联扩展事件
///
/// 扩展事件的命令
///
public ExternalEvent Event { get; private set; }
///
/// 触发命令
///
///
public ExternalEventRequest Raise()
{
#region 如果关联命令为空,创建一次
if (Event == null)
{
CreateEvent();
}
#endregion
if (Event == null)
{
return ExternalEventRequest.Pending;
}
return Event.Raise();
}
///
/// 根据指定参数触发命令
///
/// 传入参数,在回调方法参数中可以找打使用
///
public ExternalEventRequest Raise(object parameter)
{
if (Handler != null)
{
Handler.Parameter = parameter;
}
#region 如果关联命令为空,创建一次
if (Event == null)
{
CreateEvent();
}
#endregion
if (Event == null)
{
return ExternalEventRequest.Pending;
}
return Event.Raise();
}
#endregion
#region 析构处理
~ExternalEventCommand()
{
if (Event != null)
Event.Dispose();
}
#endregion
}
}