添加项目文件。
This commit is contained in:
36
RevitTools.Utils/Properties/AssemblyInfo.cs
Normal file
36
RevitTools.Utils/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 有关程序集的一般信息由以下
|
||||
// 控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
[assembly: AssemblyTitle("RevitTools.Utils")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("RevitTools.Utils")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2019")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// 将 ComVisible 设置为 false 会使此程序集中的类型
|
||||
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
|
||||
//请将此类型的 ComVisible 特性设置为 true。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
|
||||
[assembly: Guid("514e9c5d-93c6-4781-b982-83fc7fcd6a19")]
|
||||
|
||||
// 程序集的版本信息由下列四个值组成:
|
||||
//
|
||||
// 主版本
|
||||
// 次版本
|
||||
// 生成号
|
||||
// 修订号
|
||||
//
|
||||
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
|
||||
//通过使用 "*",如下所示:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
51
RevitTools.Utils/Revit/ExEventHandle.cs
Normal file
51
RevitTools.Utils/Revit/ExEventHandle.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using Autodesk.Revit.DB;
|
||||
using Autodesk.Revit.UI;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
|
||||
namespace RevitTools.Utils.Revit
|
||||
{
|
||||
/// <summary>
|
||||
/// 外部事件处理程序
|
||||
/// </summary>
|
||||
public class ExEventHandle : IExternalEventHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// 创建具有指定名字的外部事件处理程序
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
public ExEventHandle(string name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
private readonly string name;
|
||||
|
||||
/// <summary>
|
||||
/// 工作项队列
|
||||
/// </summary>
|
||||
internal readonly ConcurrentQueue<ExEventWorkItem> ExEventQueue = new ConcurrentQueue<ExEventWorkItem>();
|
||||
|
||||
/// <summary>
|
||||
/// 执行外部事件函数
|
||||
/// </summary>
|
||||
/// <param name="app"></param>
|
||||
public void Execute(UIApplication app)
|
||||
{
|
||||
while (ExEventQueue.TryDequeue(out ExEventWorkItem workItem))
|
||||
{
|
||||
workItem.InvokeAction(app);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取字符串标识
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string GetName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
78
RevitTools.Utils/Revit/ExEventUtils.cs
Normal file
78
RevitTools.Utils/Revit/ExEventUtils.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using Autodesk.Revit.UI;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RevitTools.Utils.Revit
|
||||
{
|
||||
/// <summary>
|
||||
/// 外部事件封装类
|
||||
/// </summary>
|
||||
public class ExEventUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// 创建外部事件
|
||||
/// </summary>
|
||||
/// <param name="handleName"></param>
|
||||
private ExEventUtils(string handleName)
|
||||
{
|
||||
this.Handle = new ExEventHandle(handleName);
|
||||
this.ExEvent = ExternalEvent.Create(this.Handle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 外部事件实例
|
||||
/// </summary>
|
||||
private readonly ExternalEvent ExEvent;
|
||||
|
||||
/// <summary>
|
||||
/// 外部事件处理程序
|
||||
/// </summary>
|
||||
private readonly ExEventHandle Handle;
|
||||
|
||||
/// <summary>
|
||||
/// 在外部事件中执行函数, 可以等待函数执行完成
|
||||
/// </summary>
|
||||
/// <param name="action">要执行的函数</param>
|
||||
/// <param name="transactionGroupName">事务组名</param>
|
||||
/// <returns></returns>
|
||||
public async Task InvokeAsync(Action<UIApplication> action)
|
||||
{
|
||||
var workItem = new ExEventWorkItem(action);
|
||||
Handle.ExEventQueue.Enqueue(workItem);
|
||||
ExEvent.Raise();
|
||||
await workItem.CompletionSource.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在外部事件中执行函数, 并且可以等待函数执行完成
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="func">要执行的函数</param>
|
||||
/// <returns></returns>
|
||||
public async Task<T> InvokeAsync<T>(Func<UIApplication, T> func)
|
||||
{
|
||||
object func1(UIApplication app)
|
||||
{
|
||||
return func(app);
|
||||
}
|
||||
var workItem = new ExEventWorkItem(func1);
|
||||
Handle.ExEventQueue.Enqueue(workItem);
|
||||
ExEvent.Raise();
|
||||
var result = await workItem.CompletionSource.Task;
|
||||
return (T)result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或创建外部事件处理实例
|
||||
/// </summary>
|
||||
/// <param name="name">外部事件处理程序名称</param>
|
||||
/// <returns></returns>
|
||||
public static ExEventUtils GetOrCreate(string name = "ScriptPadExEventHandle")
|
||||
{
|
||||
return EventUtils.GetOrAdd(name, new ExEventUtils(name));
|
||||
}
|
||||
|
||||
private static readonly ConcurrentDictionary<string, ExEventUtils> EventUtils = new ConcurrentDictionary<string, ExEventUtils>();
|
||||
}
|
||||
}
|
||||
64
RevitTools.Utils/Revit/ExEventWorkItem.cs
Normal file
64
RevitTools.Utils/Revit/ExEventWorkItem.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using Autodesk.Revit.UI;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RevitTools.Utils.Revit
|
||||
{
|
||||
/// <summary>
|
||||
/// 外部事件工作项
|
||||
/// </summary>
|
||||
internal class ExEventWorkItem
|
||||
{
|
||||
/// <summary>
|
||||
/// 异步阻塞信号
|
||||
/// </summary>
|
||||
public TaskCompletionSource<object> CompletionSource { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// 在外部事件中执行的, 带有一个返回值的函数
|
||||
/// </summary>
|
||||
private Action<UIApplication> Action { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 在外部事件中执行的, 带有一个返回值的函数
|
||||
/// </summary>
|
||||
private Func<UIApplication, object> Func { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 执行外部事件函数
|
||||
/// </summary>
|
||||
/// <param name="application"></param>
|
||||
public void InvokeAction(UIApplication application)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Action != null)
|
||||
{
|
||||
Action.Invoke(application);
|
||||
this.CompletionSource.TrySetResult(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = Func.Invoke(application);
|
||||
this.CompletionSource.TrySetResult(result);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.CompletionSource.TrySetException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public ExEventWorkItem(Action<UIApplication> action)
|
||||
{
|
||||
this.CompletionSource = new TaskCompletionSource<object>();
|
||||
this.Action = action;
|
||||
}
|
||||
|
||||
public ExEventWorkItem(Func<UIApplication, object> action)
|
||||
{
|
||||
this.CompletionSource = new TaskCompletionSource<object>();
|
||||
this.Func = action;
|
||||
}
|
||||
}
|
||||
}
|
||||
58
RevitTools.Utils/RevitTools.Utils.csproj
Normal file
58
RevitTools.Utils/RevitTools.Utils.csproj
Normal file
@@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{514E9C5D-93C6-4781-B982-83FC7FCD6A19}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>RevitTools.Utils</RootNamespace>
|
||||
<AssemblyName>RevitTools.Utils</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Revit\ExEventHandle.cs" />
|
||||
<Compile Include="Revit\ExEventUtils.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Revit\ExEventWorkItem.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Revit_All_Main_Versions_API_x64">
|
||||
<Version>2018.0.2</Version>
|
||||
<ExcludeAssets>runtime</ExcludeAssets>
|
||||
<IncludeAssets>compile; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
Reference in New Issue
Block a user