using Autodesk.Revit.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FWindSoft.Revit
{
///
/// 处理者,就是接收者
///
public class RevitHandler : IExternalEventHandler
{
public RevitHandler() : this(Guid.NewGuid().ToString("N"))
{
}
public RevitHandler(string name)
{
this.Name = name;
}
public RevitHandler(string name, Action action) : this(name)
{
if (action != null)
{
Executing += (s, e) => action(e);
}
}
public RevitHandler(Action action) : this(Guid.NewGuid().ToString("N"), action)
{
}
#region 接口逻辑实现
public void Execute(UIApplication app)
{
this.UIApp = app;
var args = new RevitEventArgs();
args.UIApp = this.UIApp;
args.Handler = this;
OnPreExecute(args);
if (args.Handled)
return;
OnExecute(args);
if (args.Handled)
return;
OnPostExecute(args);
}
///
/// 命令名称
///
public string Name { get; protected set; }
public string GetName()
{
return Name;
}
#endregion
///
/// 关联UIApp
///
public UIApplication UIApp { get; private set; }
#region 事件处理相关
public event EventHandler PreExecute;
public event EventHandler Executing;
public event EventHandler PostExecute;
public virtual void OnExecute(RevitEventArgs args)
{
if (Executing != null)
{
Executing(this, args);
}
}
protected virtual void OnPreExecute(RevitEventArgs args)
{
if (PreExecute != null)
{
PreExecute(this, args);
}
}
protected virtual void OnPostExecute(RevitEventArgs args)
{
if (PostExecute != null)
{
PostExecute(this, args);
}
}
#endregion
///
/// 关联参数
///
public object Parameter { get; set; }
}
}