first commmit

This commit is contained in:
unknown 2022-04-06 17:30:48 +08:00
commit 26dd451123
8 changed files with 479 additions and 0 deletions

261
.gitignore vendored Normal file
View File

@ -0,0 +1,261 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# DNX
project.lock.json
project.fragment.lock.json
artifacts/
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
#*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignoreable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
*.mdf
*.ldf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# JetBrains Rider
.idea/
*.sln.iml
# CodeRush
.cr/
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# uBIM.Checker.AOP
使用静态织入的方式,将验证代码添加进插件里

View File

@ -0,0 +1,35 @@
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System;
using uBIM.Checker.AOP;
using Autodesk.Revit.Attributes;
using System.Windows;
namespace TestDemo1
{
[Transaction(TransactionMode.Manual)]
public class TestCommand : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
var a = new A();
a.B();
return Result.Succeeded;
}
}
}
namespace Autodesk.Revit.UI
{
[Checker("uBIM ReCAD")]
public class A
{
public void B()
{
MessageBox.Show("121");
}
}
}

View File

@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<UserSecretsId>e809dde1-3dc4-4ca0-bcb9-65c8473f590e</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="RevitSDK2019" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\uBIM.Checker.AOP\uBIM.Checker.AOP.csproj" />
</ItemGroup>
</Project>

31
src/uBIM.Checker.AOP.sln Normal file
View File

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.1.32228.430
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "uBIM.Checker.AOP", "uBIM.Checker.AOP\uBIM.Checker.AOP.csproj", "{B13A63A8-9101-44D5-9CC1-A300BA312AB8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestDemo1", "TestDemo1\TestDemo1.csproj", "{CE0CDCE8-07D5-4E25-A109-93618F102178}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B13A63A8-9101-44D5-9CC1-A300BA312AB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B13A63A8-9101-44D5-9CC1-A300BA312AB8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B13A63A8-9101-44D5-9CC1-A300BA312AB8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B13A63A8-9101-44D5-9CC1-A300BA312AB8}.Release|Any CPU.Build.0 = Release|Any CPU
{CE0CDCE8-07D5-4E25-A109-93618F102178}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CE0CDCE8-07D5-4E25-A109-93618F102178}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CE0CDCE8-07D5-4E25-A109-93618F102178}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CE0CDCE8-07D5-4E25-A109-93618F102178}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {AB127A4B-B955-4373-94AE-CBC2A6561243}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,45 @@
using AspectInjector.Broker;
using Autodesk.Revit.UI;
using System;
using System.Linq;
namespace uBIM.Checker.AOP
{
[Injection(typeof(CkeckerAspect))]
public class CheckerAttribute : Attribute
{
public string Title { get; }
public CheckerAttribute(string title = "uBIM")
{
Title = title;
}
}
[Aspect(Scope.PerInstance)]
public class CkeckerAspect
{
[Advice(Kind.Around, Targets = Target.Method)]
public object DoCheck([Argument(Source.Instance)] object obj, [Argument(Source.Triggers)] Attribute[] triggers, [Argument(Source.Target)] Func<object[], object> target, [Argument(Source.Arguments)] object[] args)
{
var checker = triggers.OfType<CheckerAttribute>().First();
if (checker != null && obj is IExternalCommand)
{
if (LicenseChecker.Instance.CheckLicenseState(checker.Title))
{
return target(args);
}
return Result.Cancelled;
}
else
{
if (LicenseChecker.Instance.CheckLicenseState(checker.Title, false))
{
return target(args);
}
throw new MethodAccessException($"{checker.Title}:激活信息无效");
}
}
}
}

View File

@ -0,0 +1,69 @@
using System;
using System.Reflection;
using System.Windows;
namespace uBIM.Checker.AOP
{
/// <summary>
/// 许可检查
/// </summary>
public class LicenseChecker
{
#region
//Lazy默认是线程安全的
private static readonly Lazy<LicenseChecker> instance = new Lazy<LicenseChecker>(() => new LicenseChecker());
public static LicenseChecker Instance
{
get
{
return instance.Value;
}
}
#endregion
public uBIM.PersonLicense.Checker Checker { get; set; }
private LicenseChecker()
{
RunChecker();
}
/// <summary>
/// 启动检查器
/// </summary>
public void RunChecker()
{
Checker = new uBIM.PersonLicense.Checker(Assembly.GetExecutingAssembly());
Checker.Run();
}
/// <summary>
/// 检查许可状态(是否有效)
/// </summary>
/// <param name="showMsg">是否显示提示消息</param>
/// <returns>是否有效</returns>
public bool CheckLicenseState(string title = "uBIM", bool showMsg = true)
{
bool result = !Checker.OutLimit;
if (showMsg)
{
string msg;
if (Checker.LimitDate == DateTime.MinValue)
{
msg = "未激活!\r\n\r\n点击选项卡中的【关于】按钮在弹出窗的右下角处进行激活";
MessageBox.Show(msg, title, MessageBoxButton.OK, MessageBoxImage.Information);
}
else if (DateTime.Now.Date > Checker.LimitDate)
{
msg = string.Format("{0}\r\n有效期至{1}", "已过期", Checker.LimitDate.ToString("yyyy-MM-dd"));
MessageBox.Show(msg, title, MessageBoxButton.OK, MessageBoxImage.Information);
}
}
return result;
}
/// <summary>
/// 注销登录
/// </summary>
/// <returns></returns>
public void Logout()
{
}
}
}

View File

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net462</TargetFramework>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<VersionPrefix>0.0.5</VersionPrefix>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AspectInjector" Version="2.7.2" />
<PackageReference Include="dotnetCampus.SourceYard" Version="0.1.19392">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="RevitSDK2017" Version="1.0.0" />
<PackageReference Include="uBIM.Checker.Person" Version="1.0.13" />
</ItemGroup>
</Project>