From 26dd451123abf7dcad88f4b511774a76075a34ff Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 6 Apr 2022 17:30:48 +0800 Subject: [PATCH] first commmit --- .gitignore | 261 +++++++++++++++++++ README.md | 3 + src/TestDemo1/TestCommand.cs | 35 +++ src/TestDemo1/TestDemo1.csproj | 16 ++ src/uBIM.Checker.AOP.sln | 31 +++ src/uBIM.Checker.AOP/Checker.cs | 45 ++++ src/uBIM.Checker.AOP/LicenseChecker.cs | 69 +++++ src/uBIM.Checker.AOP/uBIM.Checker.AOP.csproj | 19 ++ 8 files changed, 479 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 src/TestDemo1/TestCommand.cs create mode 100644 src/TestDemo1/TestDemo1.csproj create mode 100644 src/uBIM.Checker.AOP.sln create mode 100644 src/uBIM.Checker.AOP/Checker.cs create mode 100644 src/uBIM.Checker.AOP/LicenseChecker.cs create mode 100644 src/uBIM.Checker.AOP/uBIM.Checker.AOP.csproj diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..48a07ae --- /dev/null +++ b/.gitignore @@ -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 diff --git a/README.md b/README.md new file mode 100644 index 0000000..d1341c6 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# uBIM.Checker.AOP + +使用静态织入的方式,将验证代码添加进插件里 \ No newline at end of file diff --git a/src/TestDemo1/TestCommand.cs b/src/TestDemo1/TestCommand.cs new file mode 100644 index 0000000..5cb9529 --- /dev/null +++ b/src/TestDemo1/TestCommand.cs @@ -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"); + } + } +} \ No newline at end of file diff --git a/src/TestDemo1/TestDemo1.csproj b/src/TestDemo1/TestDemo1.csproj new file mode 100644 index 0000000..751b7de --- /dev/null +++ b/src/TestDemo1/TestDemo1.csproj @@ -0,0 +1,16 @@ + + + + net472 + e809dde1-3dc4-4ca0-bcb9-65c8473f590e + + + + + + + + + + + diff --git a/src/uBIM.Checker.AOP.sln b/src/uBIM.Checker.AOP.sln new file mode 100644 index 0000000..79f5b74 --- /dev/null +++ b/src/uBIM.Checker.AOP.sln @@ -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 diff --git a/src/uBIM.Checker.AOP/Checker.cs b/src/uBIM.Checker.AOP/Checker.cs new file mode 100644 index 0000000..d38ebe4 --- /dev/null +++ b/src/uBIM.Checker.AOP/Checker.cs @@ -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 target, [Argument(Source.Arguments)] object[] args) + { + var checker = triggers.OfType().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}:激活信息无效"); + } + } + } +} \ No newline at end of file diff --git a/src/uBIM.Checker.AOP/LicenseChecker.cs b/src/uBIM.Checker.AOP/LicenseChecker.cs new file mode 100644 index 0000000..3a4495b --- /dev/null +++ b/src/uBIM.Checker.AOP/LicenseChecker.cs @@ -0,0 +1,69 @@ +using System; +using System.Reflection; +using System.Windows; +namespace uBIM.Checker.AOP +{ + /// + /// 许可检查 + /// + public class LicenseChecker + { + #region 单例 + //Lazy默认是线程安全的 + private static readonly Lazy instance = new Lazy(() => new LicenseChecker()); + public static LicenseChecker Instance + { + get + { + return instance.Value; + } + } + #endregion + public uBIM.PersonLicense.Checker Checker { get; set; } + + private LicenseChecker() + { + RunChecker(); + } + /// + /// 启动检查器 + /// + public void RunChecker() + { + Checker = new uBIM.PersonLicense.Checker(Assembly.GetExecutingAssembly()); + Checker.Run(); + } + /// + /// 检查许可状态(是否有效) + /// + /// 是否显示提示消息 + /// 是否有效 + 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; + } + /// + /// 注销登录 + /// + /// + public void Logout() + { + + } + } +} diff --git a/src/uBIM.Checker.AOP/uBIM.Checker.AOP.csproj b/src/uBIM.Checker.AOP/uBIM.Checker.AOP.csproj new file mode 100644 index 0000000..29a980b --- /dev/null +++ b/src/uBIM.Checker.AOP/uBIM.Checker.AOP.csproj @@ -0,0 +1,19 @@ + + + + net462 + False + 0.0.5 + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + +