├── asset └── UPPERIOC.png ├── dll ├── netstandard.dll ├── Newtonsoft.Json.dll └── UPPER.GengXinQi.dll ├── UPPERIOC ├── UPPERIOC.png ├── targets │ ├── upperioc.props │ └── upperioc.targets ├── UPPER │ ├── Event │ │ ├── AppEvent │ │ │ ├── IUPPERApplicationEvent.cs │ │ │ └── Impl │ │ │ │ ├── UPPERApplicationEvent.cs │ │ │ │ ├── IUPPERApplicationListener.cs │ │ │ │ └── Event.cs │ │ └── Attri │ │ │ ├── Order.cs │ │ │ └── After.cs │ ├── Log_ │ │ ├── enums │ │ │ └── LogType.cs │ │ ├── LogManager.cs │ │ └── ILog.cs │ ├── IOC │ │ ├── Annaiation │ │ │ ├── IOCMethod.cs │ │ │ ├── IOCConstructor.cs │ │ │ ├── IOCObject.cs │ │ │ └── IOCPorpeties.cs │ │ ├── MyTypeInfo │ │ │ └── IOCTypeInfo.cs │ │ ├── DefaultProvider │ │ │ └── Builder │ │ │ │ └── InstanceBuilder.cs │ │ └── Moudle │ │ │ └── UPPERIOCModule.cs │ ├── Center │ │ └── U.cs │ ├── Moudle_ │ │ ├── IUPPERModule.cs │ │ ├── Initializer │ │ │ └── ModuleInitializer.cs │ │ ├── MoudleLoader.cs │ │ └── ModuleConfiguaion.cs │ ├── MainApplication │ │ ├── Dispatcher │ │ │ └── EventDispatcher.cs │ │ └── UPPERIOCApplication.cs │ ├── IProvider │ │ └── IContainerProvider.cs │ ├── LogCenter.cs │ ├── _Inter │ │ └── VersionModel.cs │ └── MoudleManager │ │ └── UPPERMoudleManager.cs ├── UPPER.UFileModel │ ├── IConfiguaion │ │ └── IUFileModelConfiguation.cs │ ├── UAttribute │ │ └── IModelAttribute.cs │ ├── Model │ │ └── IModel.cs │ ├── Moudle │ │ └── UPPERFileModelModule.cs │ └── Entry │ │ └── DirectoryEx.cs ├── UPPER._Premission │ ├── UAttribute │ │ ├── ProxyAttribute.cs │ │ ├── ProxyConAttribute.cs │ │ └── PremissionRequiredAttribute.cs │ ├── Model │ │ ├── Role.cs │ │ ├── RoleGroup.cs │ │ ├── User.cs │ │ └── PermissionModel.cs │ ├── UInterceptor │ │ └── PermissionInterceptor.cs │ ├── IConfiguation │ │ ├── IPremissionConfiguation.cs │ │ └── RigisterObjLoad.cs │ └── Center │ │ └── PremissionCenter.cs ├── UPPER.Translate │ ├── IConfigration │ │ └── ITranslateConfig.cs │ ├── Model │ │ └── TranslateModle.cs │ ├── Moudle │ │ └── UPPERTranslateModule.cs │ └── Center │ │ └── TranslateCenter.cs ├── Util │ ├── Moudle │ │ ├── MustRunAsAdminMoudle.cs │ │ └── SimpleOnlyRunProcessMoudle.cs │ ├── Deepcopy.cs │ ├── ThreadHelper │ │ ├── ThreadStoper.cs │ │ └── TaskPool.cs │ ├── TaskbarHider.cs │ ├── MutiPageUtil.cs │ ├── FileUtil.cs │ ├── MyStopwatch.cs │ ├── DumpHelper.cs │ ├── AnimationUtil.cs │ ├── HashHelper.cs │ ├── RegisterHelper.cs │ ├── Extend │ │ └── StaticExtend.cs │ └── TranslateUtil.cs ├── UPPER.MLOCK │ ├── IConfiguation │ │ └── MLockConfiguation.cs │ ├── Moudle │ │ └── UPPERMLockModule.cs │ ├── Center │ │ └── RegistryRegisterConsole.cs │ └── FileRigisterConsole.cs ├── UPPER.UFileLog │ ├── IConfiguation │ │ └── IFileLogConfiguation.cs │ ├── Moudle │ │ └── UPPERLogFileModule.cs │ └── DefineLog │ │ └── FileLog.cs ├── UPPER.USendor │ ├── Moudle │ │ └── UPPERSendorMoudle.cs │ └── Center │ │ └── SendorCenter.cs └── UPPERIOC.csproj ├── .gitee ├── ISSUE_TEMPLATE │ ├── config.yml │ ├── chat.yml │ ├── question.yml │ ├── feature.yml │ └── bug.yml └── PULL_REQUEST_TEMPLATE.md ├── .editorconfig ├── .github ├── ISSUE_TEMPLATE │ ├── config.yml │ ├── chat.yml │ ├── suggestion.yml │ ├── help.yml │ ├── feature_request.yml │ ├── feature_request.md │ ├── bug_report.md │ └── bug_report.yml └── PULL_REQUEST_TEMPLATE.md ├── UPPER.ApplicationEventTest ├── App.config ├── Properties │ └── AssemblyInfo.cs └── UPPER.Test.ApplicationEventTest.csproj ├── UPPER.TestTests ├── ModuleTestsTests.cs └── UPPER.TestTests.csproj ├── IOCCodeGenerator ├── build │ └── IOCCodeGenerator.props ├── Properties │ └── PublishProfiles │ │ └── FolderProfile.pubxml ├── App.config ├── packages.config └── IOCCodeGenerator.csproj ├── UPPER.Test.MoudleLifecycle ├── UPPER.Test.MoudleLifecycle.csproj └── Program.cs ├── MigrationBackup ├── bcda289f │ └── AutoComTest │ │ └── packages.config └── 51c27922 │ └── FrmControl │ └── packages.config ├── UPPER.Test.ApplicationEventTests ├── UPPER.Test.ApplicationEventTests.csproj └── Program.cs ├── TestDemo ├── Util │ └── FileCleanupTest.cs ├── UPPER.Test.csproj ├── Entity │ └── Entitys.cs ├── UModelTests.cs ├── ApplicationEventTests.cs ├── MFileLogTest.cs ├── MLockTest.cs ├── ModuleTests.cs └── IoCTests.cs ├── UPPER.Shared ├── UPPER.Shared.projitems └── UPPER.Shared.shproj ├── .workflow ├── pipeline-20240709.yml ├── pr-pipeline.yml ├── master-pipeline.yml └── branch-pipeline.yml ├── CONTRIBUTING.md ├── UPPER.Test.Share ├── Properties │ └── AssemblyInfo.cs └── UPPER.Test.Share.csproj ├── LICENSE ├── SECURITY.md ├── .gitattributes ├── .gitignore ├── README.md ├── CODE_OF_CONDUCT.md └── UPPERIOC.sln /asset/UPPERIOC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrwangshipei/UPPERIOC/HEAD/asset/UPPERIOC.png -------------------------------------------------------------------------------- /dll/netstandard.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrwangshipei/UPPERIOC/HEAD/dll/netstandard.dll -------------------------------------------------------------------------------- /UPPERIOC/UPPERIOC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrwangshipei/UPPERIOC/HEAD/UPPERIOC/UPPERIOC.png -------------------------------------------------------------------------------- /dll/Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrwangshipei/UPPERIOC/HEAD/dll/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /dll/UPPER.GengXinQi.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mrwangshipei/UPPERIOC/HEAD/dll/UPPER.GengXinQi.dll -------------------------------------------------------------------------------- /.gitee/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Gitee 帮助中心 4 | url: https://help.gitee.com/ 5 | about: 提交遇到困难?请参考 Gitee 官方文档 6 | -------------------------------------------------------------------------------- /UPPERIOC/targets/upperioc.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | [*.cs] 2 | 3 | # IDE0005: Using 指令是不需要的。 4 | dotnet_diagnostic.IDE0005.severity = silent 5 | 6 | # Default severity for all analyzer diagnostics 7 | dotnet_analyzer_diagnostic.severity = suggestion 8 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: 🙋‍♂️ General Question / 一般问题咨询 4 | url: https://github.com/your-org/your-repo/discussions 5 | about: 如果你只是想提问或讨论,请转到 Discussions。 6 | -------------------------------------------------------------------------------- /UPPER.ApplicationEventTest/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /UPPER.TestTests/ModuleTestsTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace UPPER.TestTests 8 | { 9 | internal class ModuleTestsTests 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/chat.yml: -------------------------------------------------------------------------------- 1 | name: 💬 讨论 Chat 2 | description: 提出一个开放性问题或建议讨论方向 3 | title: "[Chat] ..." 4 | labels: ["discussion"] 5 | body: 6 | - type: textarea 7 | id: topic 8 | attributes: 9 | label: 讨论话题 10 | description: 描述你想讨论的问题或思路 11 | validations: 12 | required: true 13 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER/Event/AppEvent/IUPPERApplicationEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace UPPERIOC.UPPER.Event.AppEvent 8 | { 9 | public interface IUPPERApplicationEvent 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /IOCCodeGenerator/build/IOCCodeGenerator.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Analyzer 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER.UFileModel/IConfiguaion/IUFileModelConfiguation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace UPPERIOC2.UPPER.UFileModel.IConfiguaion 6 | { 7 | public interface IUFileModelConfiguation 8 | { 9 | string SaveModelPath { get; set; } 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/suggestion.yml: -------------------------------------------------------------------------------- 1 | name: 💡 建议 Suggestion 2 | description: 你有一个不算功能需求的建议或改进点 3 | title: "[Suggestion] ..." 4 | labels: ["suggestion"] 5 | body: 6 | - type: textarea 7 | id: idea 8 | attributes: 9 | label: 建议内容 10 | description: 描述你的想法,它可能是优化、调整、文档改进等 11 | validations: 12 | required: true 13 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER/Log_/enums/LogType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace UPPERIOC.UPPER.enums 8 | { 9 | public enum LogType 10 | { 11 | Debug, 12 | Info, 13 | Warn, 14 | Error, 15 | Success, 16 | Tip 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER._Premission/UAttribute/ProxyAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace UPPERIOC2.UPPER.Premission.UAttribute 6 | { 7 | [AttributeUsage ( AttributeTargets.Class)] 8 | public class ProxyClassAttribute : Attribute 9 | { 10 | public ProxyClassAttribute() 11 | { 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER._Premission/UAttribute/ProxyConAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace UPPERIOC2.UPPER.Premission.UAttribute 6 | { 7 | [AttributeUsage ( AttributeTargets.Constructor)] 8 | public class ProxyConAttribute : Attribute 9 | { 10 | public ProxyConAttribute() 11 | { 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER._Premission/Model/Role.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace UPPERIOC2.UPPER.Premission.Model 6 | { 7 | [Serializable] 8 | 9 | public class Role 10 | { 11 | public int id { get; set; } 12 | public string Name { get; set; } 13 | public string Backup { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER/IOC/Annaiation/IOCMethod.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace UPPERIOC.UPPER.IOC.Annaiation 8 | { 9 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)] 10 | public class IOCMethod : Attribute 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | # 📥 Pull Request 模板 2 | 3 | 感谢你的贡献!请确保: 4 | 5 | - 所有代码已在本地测试通过 6 | - 所有更改已按模块提交,并附带描述 7 | 8 | ## 🧾 类型 9 | 10 | - [ ] Bug 修复 11 | - [ ] 新功能 12 | - [ ] 文档更新 13 | - [ ] 结构优化 14 | 15 | ## 📌 变更说明 16 | 17 | 请简要描述改动内容,例如: 18 | 19 | - 修复了 xxx 问题 20 | - 增加了 xxx 功能 21 | - 拆分了 xxx 模块 22 | 23 | ## ✅ 检查项 24 | 25 | - [ ] 所有变更已通过测试 26 | - [ ] 相关文档已更新(如需) 27 | - [ ] 确认无遗留调试代码 28 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER.UFileModel/UAttribute/IModelAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Xml.Serialization; 7 | 8 | namespace UPPERIOC.UPPER.UFileModel.UAttribute 9 | { 10 | [Serializable] 11 | [XmlRoot] 12 | public class IModelAttribute : Attribute 13 | { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER/IOC/Annaiation/IOCConstructor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace UPPERIOC.UPPER.IOC.Annaiation 8 | { 9 | [AttributeUsage(AttributeTargets.Constructor, AllowMultiple = false, Inherited = true)] 10 | 11 | public class IOCConstructor : Attribute 12 | { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /.gitee/ISSUE_TEMPLATE/chat.yml: -------------------------------------------------------------------------------- 1 | name: 闲聊 / 吐槽 2 | description: 自由交流,欢迎讨论项目相关话题 3 | title: "[Chat]: " 4 | labels: ["discussion"] 5 | body: 6 | - type: textarea 7 | attributes: 8 | label: 想聊点啥? 9 | placeholder: 比如:觉得 IOC 这个理念真酷,或者某设计不太好理解… 10 | validations: 11 | required: true 12 | - type: textarea 13 | attributes: 14 | label: 有什么建议或者灵感吗? 15 | placeholder: 也许你的点子能变成下一个版本的新特性 16 | -------------------------------------------------------------------------------- /UPPER.Test.MoudleLifecycle/UPPER.Test.MoudleLifecycle.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net8.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER._Premission/UAttribute/PremissionRequiredAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | [AttributeUsage(AttributeTargets.Method)] 4 | public class PremissionRequiredAttribute : Attribute 5 | { 6 | public int Permission { get; } 7 | public bool NeedLogin { get; } 8 | 9 | public PremissionRequiredAttribute(int permission,bool NeedLogin = false) 10 | { 11 | Permission = permission; 12 | this.NeedLogin = NeedLogin; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/help.yml: -------------------------------------------------------------------------------- 1 | name: 🙋 寻求帮助 Help 2 | description: 你遇到了问题,不确定是不是 bug 3 | title: "[Help] 简要描述遇到的问题" 4 | labels: ["help"] 5 | body: 6 | - type: textarea 7 | id: context 8 | attributes: 9 | label: 遇到的问题描述 10 | description: 尽量清楚描述问题和你尝试的解决方案 11 | validations: 12 | required: true 13 | - type: textarea 14 | id: env 15 | attributes: 16 | label: 环境信息 17 | placeholder: 系统 / 浏览器 / Node 版本等 18 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER/IOC/Annaiation/IOCObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace UPPERIOC.UPPER.IOC.Annaiation 8 | { 9 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)] 10 | public class IOCObject : Attribute 11 | { 12 | public IOCObject() 13 | { 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /MigrationBackup/bcda289f/AutoComTest/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER/Event/AppEvent/Impl/UPPERApplicationEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using UPPERIOC.UPPER.Event.AppEvent; 7 | 8 | namespace UPPERIOC.UPPER.Event.AppEvent.Impl 9 | { 10 | public abstract class UPPERApplicationEvent : IUPPERApplicationEvent 11 | { 12 | public DateTime Timestamp { get; } = DateTime.Now; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER.Translate/IConfigration/ITranslateConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace UPPERIOC.UPPER.Translate.IConfigration 8 | { 9 | public interface ITranslateConfig 10 | { 11 | string APPKey { get; } 12 | string APPSeret { get; } 13 | string FromLanguage { get; } 14 | string ToLanguage { get; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /IOCCodeGenerator/Properties/PublishProfiles/FolderProfile.pubxml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | Release 8 | Any CPU 9 | bin\Release\netstandard2.0\publish\ 10 | FileSystem 11 | <_TargetId>Folder 12 | 13 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER._Premission/Model/RoleGroup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace UPPERIOC2.UPPER.Premission.Model 6 | { 7 | [Serializable] 8 | 9 | public class RoleGroup 10 | { 11 | public int id { get; set; } 12 | public string GpName { get; set; } 13 | public string Backup{ get; set; } 14 | public List Roles { get; set; } = new List(); 15 | //public List users{ get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER/IOC/Annaiation/IOCPorpeties.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace UPPERIOC.UPPER.IOC.Annaiation 8 | { 9 | [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)] 10 | public class IOCPorpeties : Attribute 11 | { 12 | public string Name { get; set; } 13 | 14 | public IOCPorpeties() 15 | { 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER/Log_/LogManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace UPPERIOC.UPPER.MainApplication.Log_ 8 | { 9 | public static class LogManager 10 | { 11 | public static void Init(IEnumerable logs) 12 | { 13 | var validLogs = logs?.ToArray() ?? Array.Empty(); 14 | LogCenter.AddAllLoggers(validLogs); 15 | } 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /UPPER.Test.ApplicationEventTests/UPPER.Test.ApplicationEventTests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | Exe 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.gitee/ISSUE_TEMPLATE/question.yml: -------------------------------------------------------------------------------- 1 | name: 问题求助 2 | description: 使用中遇到的疑惑、配置问题等请在此提交 3 | title: "[Question]: " 4 | labels: ["question"] 5 | body: 6 | - type: textarea 7 | attributes: 8 | label: 你的问题是什么? 9 | description: 请清晰描述你的疑问或配置问题 10 | placeholder: 比如:IOC 如何动态注册接口? 11 | validations: 12 | required: true 13 | - type: textarea 14 | attributes: 15 | label: 你尝试过哪些方案? 16 | placeholder: 描述你排查或尝试的过程 17 | - type: input 18 | attributes: 19 | label: 当前使用版本 20 | placeholder: v1.3.0 / master 21 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER/Event/AppEvent/Impl/IUPPERApplicationListener.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using UPPERIOC.UPPER.Event.AppEvent; 7 | using UPPERIOC2.UPPER.UIOC.Center; 8 | 9 | namespace UPPERIOC.UPPER.Event.AppEvent.Impl 10 | { 11 | public interface IUPPERApplicationListener where T : IUPPERApplicationEvent, new() 12 | { 13 | string MoudleName { get; } 14 | void OnEvent(T applicationEvent); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER/Log_/ILog.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using UPPERIOC.UPPER.enums; 7 | 8 | namespace UPPERIOC.UPPER.MainApplication.Log_ 9 | { 10 | public interface ILog 11 | { 12 | LogType[] CanLogType { get; } 13 | 14 | /// 15 | /// 输出日志 16 | /// 17 | /// 可以是Warn一类的类型,也可以是Color.ToString()... 18 | /// 消息文本 19 | void Log(LogType LogType, string Msg); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER.UFileModel/Model/IModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Xml.Serialization; 5 | using UPPERIOC2.UPPER.UFileModel.Center; 6 | using UPPERIOC2.UPPER.USendor.Center; 7 | 8 | namespace UPPERIOC2.UPPER.UFileModel.Model 9 | { 10 | [Serializable] 11 | [XmlRoot] 12 | 13 | [XmlInclude(typeof(IModel))] 14 | public class IModel 15 | { 16 | public virtual string? ModelName { get; set; } 17 | public void SaveModel() 18 | { 19 | F.I.SaveModel(this); 20 | } 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER._Premission/Model/User.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace UPPERIOC2.UPPER.Premission.Model 6 | { 7 | [Serializable] 8 | public class User 9 | { 10 | public int id { get; set; } 11 | public string UserName { get; set; } 12 | public string ActPath{ get; set; } 13 | 14 | public string Name { get; set; } 15 | public string Backup { get; set; } 16 | public string Token { get; set; } 17 | 18 | public int RoleGroup { get; set; } 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /.gitee/ISSUE_TEMPLATE/feature.yml: -------------------------------------------------------------------------------- 1 | name: 功能建议 2 | description: 提出新特性或结构优化建议 3 | title: "[Feature]: " 4 | labels: ["enhancement"] 5 | body: 6 | - type: textarea 7 | attributes: 8 | label: 你希望增加什么功能? 9 | placeholder: 比如:支持热更新 IOC 映射关系 10 | validations: 11 | required: true 12 | - type: textarea 13 | attributes: 14 | label: 为什么需要这个功能? 15 | description: 背景或使用场景 16 | - type: textarea 17 | attributes: 18 | label: 你希望的实现方式(可选) 19 | description: 可以附上代码建议或伪代码 20 | - type: textarea 21 | attributes: 22 | label: 补充说明(可选) 23 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER._Premission/UInterceptor/PermissionInterceptor.cs: -------------------------------------------------------------------------------- 1 | 2 | using System; 3 | using System.Reflection; 4 | using UPPERIOC; 5 | using UPPERIOC2.UPPER.Premission.Center; 6 | 7 | public static class PermissionInterceptor 8 | { 9 | 10 | public static bool Intercept(int p,bool needlogin) 11 | { 12 | PremissionCenter cen =UPPERIOCApplication.Container.GetInstance(); 13 | if (cen.c.AllowNull) 14 | { 15 | return true; 16 | } 17 | return cen.CanInvoke(p, needlogin); 18 | 19 | // 处理验证失败的情况,比如提示用户登录 20 | 21 | 22 | 23 | // 调用被拦截的方法 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /.gitee/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | # 📥 Pull Request 模板 2 | 3 | 7 | 8 | ## 🧾 变更类型 9 | 10 | - [ ] 🐞 Bug 修复 11 | - [ ] ✨ 新功能 Feature 12 | - [ ] 🛠️ 优化或重构 13 | - [ ] 📄 文档更新 14 | - [ ] ✅ 测试用例 15 | 16 | ## 📦 涉及模块 17 | 18 | 请说明具体修改了哪些模块 / 包: 19 | 20 | 例如:ioc-registry、config-center 21 | 22 | ## 📄 变更内容 23 | 24 | 简要描述本次改动的目的、背景和实现方式: 25 | 26 | - 修复了…… 27 | - 增加了…… 28 | - 移除了…… 29 | 30 | ## 🔍 测试情况 31 | 32 | - [ ] 已通过 `go test ./...` 33 | - [ ] 本地手动验证通过 34 | - [ ] 涉及逻辑较轻,无需测试 35 | 36 | ## 💬 补充说明(可选) 37 | 38 | 可附上截图、接口示意、设计文档链接等信息 39 | -------------------------------------------------------------------------------- /UPPER.TestTests/UPPER.TestTests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | latest 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER._Premission/IConfiguation/IPremissionConfiguation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Security.Cryptography; 4 | using System.Text; 5 | using UPPERIOC2.UPPER.Premission.Model; 6 | 7 | namespace UPPERIOC2.UPPER.Premission.IConfiguation 8 | { 9 | public interface IPremissionConfiguation 10 | { 11 | 12 | string ApplicationName { get; set; } 13 | string PicSavePath { get; set; } 14 | string Solt{ get; set; } 15 | bool AllowNull { get; set; } 16 | 17 | User Login(PermissionModel pm,string def = ""); 18 | PermissionModel InitModel(); 19 | bool NotPremission(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER/Center/U.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using UPPERIOC.UPPER.Event.AppEvent; 7 | using UPPERIOC.UPPER.IOC.Center.IProvider; 8 | using UPPERIOC.UPPER.MainApplication.Dispatcher; 9 | 10 | namespace UPPERIOC2.UPPER.UIOC.Center 11 | { 12 | public static class U 13 | { 14 | public static ApplicationEventManager E 15 | { 16 | get 17 | { 18 | return _e; 19 | } 20 | } 21 | internal static ApplicationEventManager _e { get; set; } 22 | public static IContainerProvider C { get; internal set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.yml: -------------------------------------------------------------------------------- 1 | name: ✨ 功能请求 Feature 2 | description: 请求添加一个新的功能 3 | title: "[Feature] 简要描述功能" 4 | labels: ["feature"] 5 | body: 6 | - type: textarea 7 | id: feature-desc 8 | attributes: 9 | label: 功能描述 10 | description: 请详细描述你希望添加的功能是什么,以及为什么它很重要 11 | validations: 12 | required: true 13 | - type: textarea 14 | id: usecase 15 | attributes: 16 | label: 使用场景 17 | description: 请描述该功能会在哪些场景下被使用,有无替代方案 18 | validations: 19 | required: false 20 | - type: input 21 | id: priority 22 | attributes: 23 | label: 优先级(可选) 24 | placeholder: high / medium / low 25 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER._Premission/Model/PermissionModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace UPPERIOC2.UPPER.Premission.Model 6 | { 7 | [Serializable] 8 | 9 | public class PermissionModel 10 | { 11 | public List users { get; set; } = new List(); 12 | public List roles { get; set; } = new List(); 13 | public List rolegps { get; set; } = new List(); 14 | public int Userid { get; set; } 15 | public int Roleid { get; set; } 16 | public int RoleGPid { get; set; } 17 | public int PicNum { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /UPPERIOC/Util/Moudle/MustRunAsAdminMoudle.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Diagnostics; 5 | using System.Runtime.InteropServices; 6 | using System.Security.Principal; 7 | using System.Text; 8 | using System.Threading; 9 | using System.Windows.Forms; 10 | using UPPERIOC.UPPER.IOC.Center.Interface; 11 | using UPPERIOC.UPPER.IOC.Center.IProvider; 12 | using static System.Net.Mime.MediaTypeNames; 13 | 14 | namespace UPPERIOC2.UPPER.Util.Moudle 15 | { 16 | [StructLayout(LayoutKind.Sequential)] 17 | struct TOKEN_ELEVATION_TYPE 18 | { 19 | public int TokenElevationType; 20 | } 21 | 22 | 23 | } 24 | #endif -------------------------------------------------------------------------------- /UPPERIOC/Util/Deepcopy.cs: -------------------------------------------------------------------------------- 1 | 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Runtime.Serialization.Formatters.Binary; 7 | using System.Runtime.Serialization; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | 11 | namespace COMIEEE.Util 12 | { 13 | public class Deepcopy 14 | { 15 | public static T DeepCopy(T obj) 16 | { 17 | using (var ms = new MemoryStream()) 18 | { 19 | IFormatter formatter = new BinaryFormatter(); 20 | formatter.Serialize(ms, obj); 21 | ms.Seek(0, SeekOrigin.Begin); 22 | return (T)formatter.Deserialize(ms); 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /TestDemo/Util/FileCleanupTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using Xunit; 8 | 9 | namespace UPPERTest.Util 10 | { 11 | public class FileTempFile : IDisposable 12 | { 13 | public readonly string _tempFile; 14 | 15 | public FileTempFile() 16 | { 17 | _tempFile = Path.GetTempFileName(); 18 | File.WriteAllText(_tempFile, "test content"); 19 | } 20 | 21 | 22 | 23 | public void Dispose() 24 | { 25 | if (File.Exists(_tempFile)) 26 | File.Delete(_tempFile); 27 | } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 💡 Feature Request / 功能建议 3 | about: Suggest a new idea or enhancement. 提出新功能或改进建议。 4 | title: "[Feature] " 5 | labels: enhancement 6 | assignees: '' 7 | --- 8 | 9 | ## 💡 Describe the Feature / 功能描述 10 | 11 | A clear and concise description of the feature you’d like to see. 12 | 请清楚、直接地描述你希望添加的功能。 13 | 14 | ## ❓ Why Is It Needed? / 为什么需要这个功能? 15 | 16 | Explain the use case or the problem it solves. 17 | 请说明该功能的实际使用场景或解决的问题。 18 | 19 | ## 🔄 Alternatives Considered / 是否有替代方案? 20 | 21 | Have you considered alternative solutions or workarounds? 22 | 你是否考虑过其他方式解决这个问题? 23 | 24 | ## 📎 Additional Context / 补充信息 25 | 26 | Add any other context or screenshots here. 27 | 其他相关信息或截图可以附在此处。 28 | -------------------------------------------------------------------------------- /UPPER.Shared/UPPER.Shared.projitems: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath) 5 | true 6 | cf82d5a3-e4e9-447b-8eb3-6200954cfe4e 7 | 8 | 9 | UPPER.Generators 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER/Event/AppEvent/Impl/Event.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace UPPERIOC.UPPER.Event.AppEvent.Impl 8 | { 9 | public class ApplicationPreInitializationEvent : UPPERApplicationEvent { } 10 | public class ApplicationModuleInitializedEvent : UPPERApplicationEvent { } 11 | public class ApplicationModulePreCreationEvent : UPPERApplicationEvent { } 12 | public class ApplicationInstanceCreatedEvent : UPPERApplicationEvent { } 13 | public class ApplicationInitEndEvent : UPPERApplicationEvent { } 14 | 15 | public class ApplicationStoppingEvent : UPPERApplicationEvent { } 16 | public class ApplicationStoppedEvent : UPPERApplicationEvent { } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /UPPERIOC/Util/ThreadHelper/ThreadStoper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | 9 | namespace UPPERIOC2.UPPER.Util.ThreadHelper 10 | { 11 | public class ThreadStoper 12 | { 13 | volatile static Dictionary Stops = new Dictionary(); 14 | /// 15 | /// 停止线程th直到被唤醒,每个noti毫秒检测唤醒一次 16 | /// 17 | /// 18 | /// 19 | public static void Stop(int th,int noti = 10) 20 | { 21 | Stops[th] = false; 22 | while (!Stops[th]) 23 | { 24 | Thread.Sleep(noti); 25 | } 26 | } 27 | public static void Start(int th) 28 | { 29 | Stops[th] = true; 30 | 31 | } 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /IOCCodeGenerator/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /.workflow/pipeline-20240709.yml: -------------------------------------------------------------------------------- 1 | version: '1.0' 2 | name: pipeline-20240709 3 | displayName: pipeline-20240709 4 | triggers: 5 | trigger: auto 6 | push: 7 | branches: 8 | prefix: 9 | - '' 10 | stages: 11 | - name: stage-32addd96 12 | displayName: 未命名 13 | strategy: naturally 14 | trigger: auto 15 | executor: [] 16 | steps: 17 | - step: build@dotnet 18 | name: build_dotnet 19 | displayName: .NET Core 构建 20 | dotnetVersion: '3.1' 21 | commands: 22 | - '# input your command here' 23 | - dotnet restore 24 | - dotnet publish -c Release -o out 25 | artifacts: 26 | - name: BUILD_ARTIFACT 27 | path: 28 | - ./out 29 | caches: 30 | - ~/.nuget/packages 31 | notify: [] 32 | strategy: 33 | retry: '0' 34 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER/Event/Attri/Order.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace UPPERIOC.UPPER.Event.Attri 8 | { 9 | [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)] 10 | sealed class OrderAttribute : Attribute 11 | { 12 | // See the attribute guidelines at 13 | // http://go.microsoft.com/fwlink/?LinkId=85236 14 | readonly int order; 15 | 16 | // This is a positional argument 17 | public OrderAttribute(int order) 18 | { 19 | this.order = order; 20 | 21 | // TODO: Implement code here 22 | 23 | throw new NotImplementedException(); 24 | } 25 | 26 | public int Order 27 | { 28 | get { return order; } 29 | } 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /UPPERIOC/Util/TaskbarHider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | namespace UPPERIOC.Util 4 | { 5 | public class TaskbarHider 6 | { 7 | // Windows API函数声明 8 | [DllImport("coredll.dll", SetLastError = true)] 9 | public static extern int FindWindow(string lpClassName, string lpWindowName); 10 | 11 | [DllImport("coredll.dll", SetLastError = true)] 12 | public static extern int ShowWindow(int hWnd, int nCmdShow); 13 | 14 | private const int SW_HIDE = 0; 15 | private const int SW_RESTORE = 9; 16 | private const int SW_SHOW = 5; 17 | private const int SW_SHOWNA = 8; 18 | 19 | public static void HideTaskbar() 20 | { 21 | int hWnd = FindWindow("HHTaskBar", null); 22 | ShowWindow(hWnd, SW_HIDE); 23 | } 24 | 25 | public static void ShowTaskbar() 26 | { 27 | int hWnd = FindWindow("HHTaskBar", null); 28 | ShowWindow(hWnd, SW_SHOW); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 🐛 Bug Report / 错误报告 3 | about: Report a reproducible bug. 汇报一个可重现的问题。 4 | title: "[Bug] " 5 | labels: bug 6 | assignees: '' 7 | --- 8 | 9 | ## 🐛 Describe the Bug / 错误描述 10 | 11 | A clear and concise description of what the bug is. 12 | 请清晰简洁地描述这个错误。 13 | 14 | ## 🔁 To Reproduce / 重现步骤 15 | 16 | Steps to reproduce the behavior: 17 | 复现问题的步骤: 18 | 19 | 1. Go to '...' 20 | 2. Click on '....' 21 | 3. Scroll down to '....' 22 | 4. See error 23 | 24 | ## ✅ Expected Behavior / 期望结果 25 | 26 | What you expected to happen. 27 | 你本来期望看到什么结果? 28 | 29 | ## 📸 Screenshots / 截图(如有) 30 | 31 | If applicable, add screenshots to help explain your problem. 32 | 如果有必要,请添加截图。 33 | 34 | ## 💻 Environment / 环境信息(请实事求是) 35 | 36 | - OS: [e.g. macOS 13.5] 37 | - Browser/Runtime: [e.g. Chrome 114 / Node.js 18] 38 | - Version: [项目版本号] 39 | 40 | ## 📎 Additional Context / 补充信息 41 | 42 | Add any other context or screenshots about the issue here. 43 | 其他相关信息或截图可以附在此处。 44 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER/Event/Attri/After.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace UPPERIOC.UPPER.Event.Attri 9 | { 10 | [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)] 11 | sealed class AfterAttribute : Attribute 12 | { 13 | // See the attribute guidelines at 14 | // http://go.microsoft.com/fwlink/?LinkId=85236 15 | readonly string after; 16 | 17 | // This is a positional argument 18 | public AfterAttribute(string after) 19 | { 20 | this.after = after; 21 | 22 | // TODO: Implement code here 23 | 24 | if (!Debugger.IsAttached) 25 | { 26 | Debugger.Launch(); 27 | } 28 | } 29 | 30 | public string After 31 | { 32 | get { return after; } 33 | } 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER.MLOCK/IConfiguation/MLockConfiguation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using UPPERIOC2.UPPER.MLOCK.Center; 5 | using UPPERIOC2.UPPER.Util; 6 | 7 | namespace UPPERIOC2.UPPER.MLOCK.IConfiguation 8 | { 9 | public class MLockConfiguation 10 | { 11 | public virtual string Solt { get; set; } 12 | public virtual string Listenaddr { get; set; } 13 | public virtual string LockName { get; set; } 14 | public virtual void Noregister() { 15 | Console.Write("没有注册"); 16 | Environment.Exit(0); 17 | } 18 | protected virtual void Register() { 19 | var r = HashHelper.EncryptWithSalt(Solt); 20 | RegisterHelper.Instance.SaveLockFile(Listenaddr, LockName, r); 21 | Console.WriteLine("注册成功,使用愉快"); 22 | } 23 | public void UnloadRegister() { 24 | RegisterHelper.Instance.UnloadLockFile(Listenaddr, LockName); 25 | } 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # 🤝 贡献指南 | UPPERIOC 2 | 3 | 感谢你对 UPPERIOC 的关注和贡献意愿。 4 | 5 | 本项目遵循“实事求是、模块清晰、代码简洁”的开发原则,所有贡献都需遵循以下流程。 6 | 7 | --- 8 | 9 | ## 🧱 贡献类型 10 | 11 | 欢迎以下类型的贡献: 12 | 13 | - 🐞 Bug 修复 14 | - ✨ 新功能开发(需先开 issue 讨论) 15 | - 📚 文档完善 16 | - 🧹 代码优化与重构 17 | - ✅ 测试用例补充 18 | 19 | --- 20 | 21 | ## 📋 提交前须知 22 | 23 | > **请不要直接往 `main` 分支提交代码!** 24 | 25 | 1. Fork 仓库后新建分支,命名建议: 26 | 27 | ``` 28 | fix/ioc-registry-crash 29 | feat/config-hot-reload 30 | docs/update-readme 31 | ``` 32 | 33 | 34 | --- 35 | 36 | ## ✅ PR 提交流程 37 | 38 | 1. 确保已签署 CLA(如项目启用) 39 | 2. 提交前请确保 PR 模板填写完整 40 | 3. 若为新功能,建议先提 Issue 获取维护者确认 41 | 4. 每个 PR 仅聚焦一个问题/功能,避免混杂多个修改 42 | 5. 所有代码变更请附带上下文说明 43 | 44 | --- 45 | 46 | ## 🧪 本地开发命令(示例) 47 | 48 | ```bash 49 | go mod tidy 50 | go fmt ./... 51 | go test ./... 52 | ``` 53 | 54 | --- 55 | 56 | ## 💬 沟通 57 | 58 | - Issue 中可公开讨论技术问题 59 | - PR 反馈不会敷衍处理,但请勿催 merge 60 | - 对于明显无效或重复内容,Maintainer 有权关闭 61 | 62 | --- 63 | 64 | UPPERIOC 核心原则:**“模块职责清晰 + 简洁工程化”** 65 | 欢迎你的高质量贡献。 66 | 67 | --- 68 | -------------------------------------------------------------------------------- /UPPER.Test.Share/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("UPPER.Test.Share")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("HP")] 12 | [assembly: AssemblyProduct("UPPER.Test.Share")] 13 | [assembly: AssemblyCopyright("Copyright © HP 2025")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("f780c7b8-f373-486e-bd5e-a67364027b28")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | [assembly: AssemblyVersion("1.0.0.0")] 33 | [assembly: AssemblyFileVersion("1.0.0.0")] 34 | -------------------------------------------------------------------------------- /TestDemo/UPPER.Test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | false 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | PreserveNewest 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /.gitee/ISSUE_TEMPLATE/bug.yml: -------------------------------------------------------------------------------- 1 | name: Bug 反馈 2 | description: 程序报错或行为异常时请用这个模板 3 | title: "[Bug]: " 4 | labels: ["bug"] 5 | body: 6 | - type: textarea 7 | attributes: 8 | label: 问题描述 9 | description: 简要概括你遇到的问题是什么 10 | placeholder: 比如:IOC 在写入后未能持久化 11 | validations: 12 | required: true 13 | - type: textarea 14 | attributes: 15 | label: 复现步骤 16 | description: 请详细说明如何复现该问题 17 | placeholder: | 18 | 1. 启动服务 19 | 2. 写入数据 X 20 | 3. 中途关闭服务 21 | 4. 重启后未恢复 X 22 | validations: 23 | required: true 24 | - type: textarea 25 | attributes: 26 | label: 预期结果 27 | placeholder: 应该可以恢复之前写入的数据 28 | validations: 29 | required: true 30 | - type: textarea 31 | attributes: 32 | label: 实际结果 33 | validations: 34 | required: true 35 | - type: textarea 36 | attributes: 37 | label: 日志信息(可选) 38 | description: 可粘贴报错或日志内容 39 | - type: input 40 | attributes: 41 | label: 当前使用版本 42 | placeholder: v1.2.3 / master 43 | -------------------------------------------------------------------------------- /UPPER.ApplicationEventTest/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("UPPER.ApplicationEventTest")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("HP")] 12 | [assembly: AssemblyProduct("UPPER.ApplicationEventTest")] 13 | [assembly: AssemblyCopyright("Copyright © HP 2025")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("58362791-4e08-46db-9c63-f3a83d0cc7c0")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | [assembly: AssemblyVersion("1.0.0.0")] 33 | [assembly: AssemblyFileVersion("1.0.0.0")] 34 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER/IOC/MyTypeInfo/IOCTypeInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace UPPERIOC.UPPER.IOC.MyTypeInfo 8 | { 9 | public class IOCTypeInfo 10 | { 11 | public Type Type { get; set; } 12 | public Type BaseType { get; set; } 13 | public bool SingleBean { get; set; } = true; 14 | public string TypeName { get; set; } 15 | 16 | public override bool Equals(object obj) 17 | { 18 | return obj is IOCTypeInfo info && 19 | EqualityComparer.Default.Equals(Type, info.Type) && 20 | TypeName == info.TypeName; 21 | } 22 | 23 | public override int GetHashCode() 24 | { 25 | int hashCode = -1262880317; 26 | hashCode = hashCode * -1521134295 + (Type).GetHashCode(); 27 | hashCode = hashCode * -1521134295 + (TypeName).GetHashCode(); 28 | if (BaseType != null) 29 | { 30 | hashCode = hashCode * -1521134295 + (BaseType).GetHashCode(); 31 | } 32 | return hashCode; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /UPPER.Shared/UPPER.Shared.shproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | cf82d5a3-e4e9-447b-8eb3-6200954cfe4e 5 | 14.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER/Moudle_/IUPPERModule.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using UPPERIOC.UPPER.IOC.Center.IProvider; 7 | 8 | namespace UPPERIOC.UPPER.Moudle_ 9 | { 10 | public abstract class IUPPERModule 11 | { 12 | public abstract Type[] Dependencies { get; } 13 | } 14 | 15 | // 阶段接口(按执行顺序) 16 | 17 | public interface IModulePostConstruction 18 | { 19 | void OnPostConstruct(IContainerProvider provider); 20 | } 21 | public interface IModulePreDestruction 22 | { 23 | void OnPreDestroy(IContainerProvider provider); 24 | } 25 | 26 | public interface IModulePreInitialization 27 | { 28 | void OnPreInitialize(IContainerProvider provider); 29 | } 30 | 31 | public interface IModuleInitialization 32 | { 33 | void OnInitialize(IContainerProvider provider); 34 | } 35 | 36 | public interface IModulePostInitialization 37 | { 38 | void OnPostInitialize(IContainerProvider provider); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /UPPERIOC/Util/MutiPageUtil.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace UPPERIOC2.UPPER.Util 8 | { 9 | public class MutiPageUtil 10 | { 11 | public static MutiPageUtil I = new MutiPageUtil(); 12 | List Pages = new List(); 13 | public IPage CurrentPage ; 14 | public void AddPage(IPage pa) 15 | { 16 | Pages.Add(pa); 17 | } 18 | public void ClearPage() { 19 | Pages.Clear(); 20 | CurrentPage = null; 21 | } 22 | public void ChangeCurrentPage(string pa) 23 | { 24 | if (CurrentPage == null) 25 | { 26 | CurrentPage = Pages.Find(i=>i.PageName == pa); 27 | } 28 | else 29 | { 30 | CurrentPage.ToBack(); 31 | } 32 | if (pa == null) 33 | { 34 | CurrentPage?.ToBack(); 35 | 36 | } 37 | var page = Pages.Find(i => i.PageName == pa); 38 | page?.ToFront(); 39 | CurrentPage = page; 40 | } 41 | } 42 | public interface IPage 43 | { 44 | string PageName { get; } 45 | void ToFront(); 46 | void ToBack(); 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /IOCCodeGenerator/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /UPPERIOC/Util/ThreadHelper/TaskPool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Collections.Generic; 4 | using System.IO.IsolatedStorage; 5 | using System.Linq; 6 | using System.Runtime.CompilerServices; 7 | using System.Text; 8 | using System.Threading; 9 | using System.Threading.Tasks; 10 | 11 | namespace UPPERIOC2.UPPER.Util.ThreadHelper 12 | { 13 | public class TaskPool:IDisposable 14 | { 15 | public TaskPool Instance { get; set; } = new TaskPool(8); 16 | public int Count { get; set; } 17 | 18 | public TaskPool(int count) { 19 | Count = count; 20 | } 21 | protected void Notify() { 22 | 23 | } 24 | /// 25 | /// 执行一段Act,Count次数,注意执行的顺序是无序的, 26 | /// 27 | /// 28 | /// 29 | public void BeginDo(int Count,Action Act) 30 | { 31 | 32 | var re = Parallel.For(0, Count, Act); 33 | while (re.IsCompleted) 34 | { 35 | Thread.Sleep(0); 36 | Thread.Sleep(0); 37 | } 38 | 39 | } 40 | 41 | public void Dispose() 42 | { 43 | } 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 wsp 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER.UFileLog/IConfiguation/IFileLogConfiguation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using UPPERIOC.UPPER.enums; 7 | 8 | namespace UPPERIOC.UPPER.UFileLog.IConfiguation 9 | { 10 | public interface IFileLogConfiguation 11 | { 12 | /// 13 | /// 是否打印毫秒 14 | /// 15 | /// 16 | bool PrintMs { get; set; } 17 | /// 18 | /// 目录文件名称 19 | /// 20 | string DirectoryName { get; set; } 21 | /// 22 | /// 默认的后缀名 23 | /// 24 | string DefaultExt{ get; set; } 25 | 26 | /// 27 | /// 什么级别的日志可以被打印 28 | /// 29 | List WhichTypePrint{ get; set; } 30 | 31 | /// 32 | /// 日志名称Format 33 | /// 34 | string FileNameTimeFormat { get; set; } 35 | /// 36 | /// 日志保存多少小时 37 | /// 38 | int HowManyHourSave { get; set; } 39 | /// 40 | /// 是否在日志名前加上LogType 41 | /// 42 | bool MutiFileName{ get; } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER/MainApplication/Dispatcher/EventDispatcher.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using UPPERIOC.UPPER.Event.AppEvent; 8 | using UPPERIOC.UPPER.IOC.Center.IProvider; 9 | 10 | namespace UPPERIOC.UPPER.MainApplication.Dispatcher 11 | { 12 | public static class EventDispatcher 13 | { 14 | public static ApplicationEventManager InitAndRegister(IContainerProvider container) 15 | { 16 | var manager = container.GetInstance(); 17 | 18 | var mainAssembly = AppDomain.CurrentDomain.GetAssemblies() 19 | .FirstOrDefault(a => a.GetTypes().Any(t => t.Name == "IOCGeneratedRegistration")); 20 | 21 | var type = mainAssembly?.GetType("UPPER.Generated.IOCGeneratedRegistration"); 22 | var method = type?.GetMethod("RegisterListener", BindingFlags.Public | BindingFlags.Static); 23 | 24 | method?.Invoke(null, new object[] { manager }); 25 | 26 | return manager; 27 | } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER/IProvider/IContainerProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Linq; 5 | using System.Reflection; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using UPPERIOC.UPPER.IOC.Annaiation; 9 | 10 | namespace UPPERIOC.UPPER.IOC.Center.IProvider 11 | { 12 | public interface IContainerProvider 13 | { 14 | T GetInstanceAndSub(); 15 | 16 | object GetInstance(Type type); 17 | T GetInstance(); 18 | T GetInstance(string name); 19 | object[] GetAllInstance(Type type); 20 | T[] GetAllInstance( ); 21 | object GetInstance(string name); 22 | 23 | object GetInstance(Type type, string name); 24 | 25 | T Rigister(bool Single = true); 26 | T Rigister(T obj); 27 | object Rigister(Type T, bool Single = true); 28 | T Rigister(string name, bool Single = true); 29 | object Rigister(Type T, string name, bool Single = true); 30 | 31 | object Rigister(Type T,object obj); 32 | object Rigister(Type T,string name,object obj); 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER.Translate/Model/TranslateModle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Collections.Generic; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using System.Xml; 9 | using System.Xml.Serialization; 10 | using UPPERIOC2.UPPER.UFileModel.Model; 11 | 12 | namespace UPPERIOC2.UPPER.Translate.Model 13 | { 14 | public class TranslateModel : IModel 15 | { 16 | public override string ModelName { get=>"translate"; set { } } 17 | [XmlElement] 18 | public List Translateblocks { get; set; } = new List(); 19 | 20 | } 21 | 22 | public class Translateblock { 23 | [XmlElement] 24 | public string Name { get; set; } 25 | [XmlElement] 26 | public List Values { get; set; } = new List(); 27 | 28 | } 29 | public struct KeyValue { 30 | [XmlElement] 31 | public string Key { get; set; } 32 | [XmlElement] 33 | public string Value { get; set; } 34 | 35 | public KeyValue(string text, string str) : this() 36 | { 37 | this.Key= text; 38 | this.Value= str; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /TestDemo/Entity/Entitys.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | using UPPERIOC.UPPER.IOC.Annaiation; 8 | using UPPERIOC.UPPER.IOC.Center.Interface; 9 | using UPPERIOC.UPPER.IOC.Center.IProvider; 10 | 11 | namespace TestDemo.Entity 12 | { 13 | [IOCObject] 14 | public class SimpleService 15 | { 16 | public string GetData() => "Hello"; 17 | } 18 | 19 | [IOCObject] 20 | public class ComplexService 21 | { 22 | public SimpleService Simple { get; } 23 | 24 | [IOCConstructor] 25 | public ComplexService(SimpleService simple) 26 | { 27 | Simple = simple; 28 | } 29 | } 30 | 31 | public interface IInterfaceService 32 | { 33 | string Ping(); 34 | } 35 | 36 | [IOCObject] 37 | public class InterfaceImpl : IInterfaceService 38 | { 39 | public string Ping() => "Pong"; 40 | } 41 | 42 | [IOCObject] 43 | public class PropertyInjectedService 44 | { 45 | [IOCPorpeties] 46 | public SimpleService InjectedProp { get; set; } 47 | } 48 | 49 | } -------------------------------------------------------------------------------- /UPPERIOC/UPPER.USendor/Moudle/UPPERSendorMoudle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using UPPERIOC.UPPER.IOC.Center.IProvider; 8 | using UPPERIOC.UPPER.Moudle_; 9 | using UPPERIOC2.UPPER.USendor.Center; 10 | 11 | 12 | namespace UPPERIOC.UPPER.Sendor.Moudle 13 | { 14 | public class UPPERSendorMoudle : IUPPERModule, IModulePostConstruction, IModuleInitialization, IModulePostInitialization, IModulePreInitialization 15 | { 16 | 17 | public UPPERSendorMoudle() 18 | { 19 | 20 | } 21 | 22 | public override Type[] Dependencies { get => new Type[] { }; } 23 | 24 | 25 | public void OnPostConstruct(IContainerProvider containerProvider) 26 | { 27 | SendorCenter.Contain = containerProvider; 28 | 29 | } 30 | 31 | public void OnPreInitialize(IContainerProvider containerProvider) 32 | { 33 | } 34 | 35 | public void OnPostInitialize(IContainerProvider containerProvider) 36 | { 37 | } 38 | 39 | public void OnInitialize(IContainerProvider containerProvider) 40 | { 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.yml: -------------------------------------------------------------------------------- 1 | name: 🐞 Bug 报告 2 | description: 提交软件缺陷或异常行为 3 | title: "[Bug] 简要描述问题" 4 | labels: ["bug"] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | 请提供尽量详细的信息,以便我们复现和定位问题。 10 | - type: input 11 | id: reproduce 12 | attributes: 13 | label: 复现步骤 14 | description: 请列出复现该问题的详细步骤 15 | placeholder: 1. 进入页面... 2. 点击按钮... 3. 出现错误... 16 | validations: 17 | required: true 18 | - type: input 19 | id: expected 20 | attributes: 21 | label: 预期结果 22 | placeholder: 应该显示正常页面 23 | validations: 24 | required: true 25 | - type: textarea 26 | id: actual 27 | attributes: 28 | label: 实际结果 29 | placeholder: 实际弹出错误提示,页面空白等 30 | validations: 31 | required: true 32 | - type: dropdown 33 | id: os 34 | attributes: 35 | label: 操作系统 36 | options: 37 | - Windows 38 | - macOS 39 | - Linux 40 | - 其他 41 | validations: 42 | required: true 43 | - type: input 44 | id: version 45 | attributes: 46 | label: 项目版本 47 | placeholder: 如:v1.2.3 或 Git Commit 哈希 48 | validations: 49 | required: true 50 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER.UFileModel/Moudle/UPPERFileModelModule.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UPPERIOC.UPPER.IOC.Center.IProvider; 3 | using UPPERIOC.UPPER.Moudle_; 4 | using UPPERIOC.UPPER.Sendor.Moudle; 5 | using UPPERIOC2.UPPER.UFileModel.Center; 6 | 7 | namespace UPPERIOC2.UPPER.UFileModel.Moudle 8 | { 9 | public class UPPERFileModelModule : IUPPERModule, IModulePostConstruction, IModuleInitialization, IModulePostInitialization, IModulePreInitialization 10 | { 11 | public override Type[] Dependencies { get => new Type[] { }; } 12 | 13 | public void OnPostConstruct(IContainerProvider containerProvider) 14 | { 15 | 16 | } 17 | 18 | public void OnPostInitialize(IContainerProvider containerProvider) 19 | { 20 | } 21 | 22 | public void OnInitialize(IContainerProvider containerProvider) 23 | { 24 | } 25 | 26 | public void OnPreInitialize(IContainerProvider containerProvider) 27 | { 28 | UFileModelCenter.pdr = containerProvider; 29 | UFileModelCenter.Instance = new UFileModelCenter(); 30 | 31 | containerProvider.Rigister(UFileModelCenter.Instance); 32 | //UFileModelCenter.Instance = new UFileModelCenter(); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy / 安全政策 2 | 3 | ## Supported Versions / 支持的版本 4 | 5 | We support security updates for **2.0.1.60** and **2.0.1.60** versions. Any versions below **2.0.1.60** will no longer receive security updates. / 我们为 **2.0.1.60** 和 **2.0.1.60** 以上的版本提供安全更新。低于 **2.0.1.60** 的版本将不再接收安全更新。 6 | 7 | ## Reporting a Vulnerability / 报告漏洞 8 | 9 | To report a security vulnerability, please email us at **wsp001112@gmail.com** or open a private issue on GitHub (via **Security Advisories** section). / 要报告安全漏洞,请通过电子邮件 **wsp001112@gmail.com** 联系我们,或在 GitHub 上的 **Security Advisories** 部分提交私密问题。 10 | 11 | ### Expected Response Time / 预计响应时间: 12 | We strive to acknowledge all reports within 48 hours and provide an initial response with a plan of action. / 我们致力于在 48 小时内确认所有报告,并提供初步的行动计划。 13 | 14 | ### Vulnerability Review / 漏洞审查: 15 | Once a vulnerability is reported, we will evaluate it and determine whether it is accepted. If the vulnerability is accepted, we will: / 一旦报告漏洞,我们将对其进行评估并决定是否接受。如果漏洞被接受,我们将: 16 | - Patch the issue in a timely manner. / 及时修复问题。 17 | - Notify all users of the affected versions. / 通知所有受影响版本的用户。 18 | If the vulnerability is declined, we will provide an explanation and may suggest alternate solutions. / 如果漏洞被拒绝,我们将提供解释并可能建议替代解决方案。 19 | -------------------------------------------------------------------------------- /UPPERIOC/Util/FileUtil.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Text; 5 | 6 | namespace UPPERIOC2.UPPER.Util 7 | { 8 | public class FileUtil 9 | { 10 | 11 | public static string FileInfoToRelativePath(FileInfo fileInfo) 12 | { 13 | if (fileInfo == null) 14 | { 15 | return null; 16 | } 17 | // 获取应用程序启动目录 18 | var baseDirectory = AppDomain.CurrentDomain.BaseDirectory; 19 | // 获取文件的绝对路径 20 | var absoluteFilePath = fileInfo.FullName; 21 | 22 | var baseUri = new Uri(baseDirectory); 23 | var fileUri = new Uri(absoluteFilePath); 24 | 25 | // 计算相对路径 26 | var relativeUri = baseUri.MakeRelativeUri(fileUri); 27 | return Uri.UnescapeDataString(relativeUri.ToString().Replace('/', Path.DirectorySeparatorChar)); 28 | } 29 | 30 | public static FileInfo RelativePathToFileInfo(string relativePath) 31 | { 32 | if (string.IsNullOrWhiteSpace(relativePath)) 33 | { 34 | return null; 35 | } 36 | // 获取应用程序启动目录 37 | var baseDirectory = AppDomain.CurrentDomain.BaseDirectory; 38 | // 将相对路径转换为绝对路径 39 | var absoluteFilePath = Path.Combine(baseDirectory, relativePath); 40 | // 创建 FileInfo 对象 41 | return new FileInfo(absoluteFilePath); 42 | } 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /.workflow/pr-pipeline.yml: -------------------------------------------------------------------------------- 1 | version: '1.0' 2 | name: pr-pipeline 3 | displayName: PRPipeline 4 | stages: 5 | - stage: 6 | name: compile 7 | displayName: 编译 8 | steps: 9 | - step: build@maven 10 | name: build_maven 11 | displayName: Maven 构建 12 | # 支持6、7、8、9、10、11六个版本 13 | jdkVersion: 8 14 | # 支持2.2.1、3.2.5、3.3.9、3.5.2、3.5.3、3.5.4、3.6.1、3.6.3八个版本 15 | mavenVersion: 3.3.9 16 | # 构建命令 17 | commands: 18 | - mvn -B clean package -Dmaven.test.skip=true 19 | # 非必填字段,开启后表示将构建产物暂存,但不会上传到制品库中,7天后自动清除 20 | artifacts: 21 | # 构建产物名字,作为产物的唯一标识可向下传递,支持自定义,默认为BUILD_ARTIFACT。在下游可以通过${BUILD_ARTIFACT}方式引用来获取构建物地址 22 | - name: BUILD_ARTIFACT 23 | # 构建产物获取路径,是指代码编译完毕之后构建物的所在路径,如通常jar包在target目录下。当前目录为代码库根目录 24 | path: 25 | - ./target 26 | - step: publish@general_artifacts 27 | name: publish_general_artifacts 28 | displayName: 上传制品 29 | # 上游构建任务定义的产物名,默认BUILD_ARTIFACT 30 | dependArtifact: BUILD_ARTIFACT 31 | # 构建产物制品库,默认default,系统默认创建 32 | artifactRepository: default 33 | # 上传到制品库时的制品命名,默认output 34 | artifactName: output 35 | dependsOn: build_maven 36 | triggers: 37 | pr: 38 | branches: 39 | include: 40 | - master 41 | -------------------------------------------------------------------------------- /TestDemo/UModelTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using UPPERIOC; 7 | using UPPERIOC.UPPER.IOC.Center.Configuation; 8 | using UPPERIOC2.UPPER.UFileModel.Center; 9 | using UPPERIOC2.UPPER.UFileModel.IConfiguaion; 10 | using UPPERIOC2.UPPER.UFileModel.Model; 11 | using Xunit; 12 | 13 | namespace UPPERTest 14 | { 15 | public class UModelTests 16 | { 17 | public class FileModle : IUFileModelConfiguation 18 | { 19 | public string SaveModelPath { get =>"MOD"; set => throw new NotImplementedException(); } 20 | } 21 | [Fact] 22 | public void UModelTest() { 23 | UPPERIOCApplication.RunInstance(x => { 24 | x.UPPERFileModelMoudle(new FileModle()); 25 | }); 26 | var x = new XModel(); 27 | x.xx = "123"; 28 | F.I.SaveModel(x); 29 | var y = F.I.GetModel(x); 30 | Assert.NotEqual(x, y); 31 | Assert.Equal("123", y.xx); 32 | Assert.Equal("123", x.xx); 33 | } 34 | 35 | public class XModel : IModel 36 | { 37 | public override string ModelName { get { return "xmod.txt"; } set { } } 38 | public string xx { get; set; } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /TestDemo/ApplicationEventTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading; 8 | using System.Threading.Tasks; 9 | using UPPER.Test.ApplicationEventTests; 10 | using UPPERIOC; 11 | using UPPERIOC.UPPER.Event.AppEvent.Impl; 12 | using UPPERIOC2.UPPER.UIOC.Center; 13 | using UPPERTest.Util; 14 | using Xunit; 15 | 16 | namespace UPPERTest 17 | { 18 | 19 | public class ApplicationEventTests 20 | { 21 | 22 | 23 | [Fact] 24 | public void TestFullLifecycleEventOrder() 25 | { 26 | FileTempFile f = new FileTempFile(); 27 | var assemblyPath = typeof(ProgramEntry).Assembly.Location; 28 | assemblyPath = assemblyPath.Replace(".dll",".exe"); 29 | //传入f._tempFile到程序中应该如何传; 30 | var process = Process.Start(new ProcessStartInfo 31 | { 32 | FileName = assemblyPath, 33 | Arguments = $"\"{f._tempFile}\"", 34 | RedirectStandardOutput = true, 35 | UseShellExecute = false, 36 | CreateNoWindow = true 37 | }); 38 | 39 | process.WaitForExit(); 40 | 41 | Assert.True(File.Exists(f._tempFile), "ProcessExit 未触发或未生成文件"); 42 | Assert.Equal(File.ReadAllText(f._tempFile), "ok"); 43 | } 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /UPPERIOC/Util/Moudle/SimpleOnlyRunProcessMoudle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using System.Runtime.InteropServices; 6 | using System.Text; 7 | using UPPERIOC.UPPER.IOC.Center.IProvider; 8 | using UPPERIOC.UPPER.Moudle_; 9 | 10 | namespace UPPERIOC2.UPPER.Util.Moudle 11 | { 12 | public class SimpleOnlyRunProcessMoudle : IUPPERModule, IModulePostConstruction, IModuleInitialization, IModulePostInitialization, IModulePreInitialization 13 | { 14 | public override Type[] Dependencies { get => new Type[] { }; } 15 | 16 | public void OnPostConstruct(IContainerProvider containerProvider) 17 | { 18 | } 19 | 20 | public void OnPostInitialize(IContainerProvider containerProvider) 21 | { 22 | } 23 | 24 | public void OnInitialize(IContainerProvider containerProvider) 25 | { 26 | } 27 | [DllImport("USER32.DLL")] 28 | public static extern bool SetForegroundWindow(IntPtr hWnd); 29 | public void OnPreInitialize(IContainerProvider containerProvider) 30 | { 31 | if (Process.GetProcesses().Select(item => item.ProcessName).Count(item => item == Process.GetCurrentProcess().ProcessName) > 1) 32 | { 33 | SetForegroundWindow(Process.GetProcesses().Where(item => item.ProcessName == Process.GetCurrentProcess().ProcessName).FirstOrDefault().MainWindowHandle); 34 | Process.GetCurrentProcess().Kill(); 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER/LogCenter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using UPPERIOC.UPPER.enums; 6 | using UPPERIOC.UPPER.MainApplication.Log_; 7 | 8 | namespace UPPERIOC.UPPER 9 | { 10 | public static class LogCenter 11 | { 12 | // 使用线程安全集合 13 | private static readonly ConcurrentBag _loggers = new ConcurrentBag(); 14 | 15 | /// 16 | /// 注册单个日志器 17 | /// 18 | public static void AddLogger(ILog logger) 19 | { 20 | if (logger == null) return; 21 | _loggers.Add(logger); 22 | } 23 | 24 | /// 25 | /// 批量注册日志器 26 | /// 27 | public static void AddAllLoggers(IEnumerable loggers) 28 | { 29 | if (loggers == null) return; 30 | foreach (var logger in loggers) 31 | { 32 | if (logger != null) 33 | _loggers.Add(logger); 34 | } 35 | } 36 | 37 | /// 38 | /// 打印日志 39 | /// 40 | public static void Log(LogType type, string message) 41 | { 42 | foreach (var logger in _loggers) 43 | { 44 | if (logger?.CanLogType?.Contains(type) == true) 45 | { 46 | logger.Log(type, message); 47 | } 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /UPPERIOC/Util/MyStopwatch.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | 9 | namespace UPPERIOC2.UPPER.Util 10 | { 11 | public class MyStopwatch : IDisposable 12 | { 13 | private bool Run = true; 14 | private bool start = false; 15 | protected volatile int ElapsedMilliseconds = 0; 16 | private CancellationToken can = new CancellationToken(); 17 | public int GetAdd(int value = 0) { 18 | lock (this) 19 | { 20 | return ElapsedMilliseconds += value; 21 | } 22 | } 23 | public MyStopwatch() { 24 | Task.Factory.StartNew(() => { 25 | while (Run) 26 | { 27 | DateTime st = DateTime.Now; 28 | while (start) 29 | { 30 | //st = ; 31 | st = DateTime.Now; 32 | 33 | Thread.Sleep(500); 34 | if ((DateTime.Now - st).TotalMilliseconds < 600) 35 | { 36 | GetAdd(501); 37 | } 38 | Console.WriteLine((DateTime.Now - st).TotalMilliseconds); 39 | } 40 | Thread.Yield(); 41 | } 42 | },can); 43 | } 44 | public void Start() { 45 | start = true; 46 | } 47 | public void Stop() 48 | { 49 | start = false; 50 | can.ThrowIfCancellationRequested(); 51 | } 52 | public static MyStopwatch StartNew() 53 | { 54 | var r = new MyStopwatch(); 55 | r.Start(); 56 | return r; 57 | } 58 | 59 | public void Dispose() 60 | { 61 | Run = false; 62 | 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /MigrationBackup/51c27922/FrmControl/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER.MLOCK/Moudle/UPPERMLockModule.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UPPERIOC.UPPER.IOC.Center.IProvider; 3 | using UPPERIOC.UPPER.Moudle_; 4 | using UPPERIOC2.UPPER.MLOCK.IConfiguation; 5 | using UPPERIOC2.UPPER.Util; 6 | 7 | namespace UPPERIOC.UPPER.IOC.Moudle 8 | { 9 | public class UPPERMLockModule : IUPPERModule, IModulePostConstruction, IModuleInitialization, IModulePostInitialization, IModulePreInitialization 10 | { 11 | 12 | public override Type[] Dependencies { get; } = new Type[0]; 13 | 14 | public static MLockConfiguation m; 15 | public void OnPostConstruct(IContainerProvider containerProvider) 16 | { 17 | var c = containerProvider.GetAllInstance(); 18 | if (c.Length <= 0) 19 | { 20 | throw new Exception("至少注册一个MLockConfiguation的对象"); 21 | } 22 | m = c[0]; 23 | if (RegisterHelper.Instance.GetLockFile(m.Listenaddr,m.LockName) == null) 24 | { 25 | m.Noregister(); 26 | 27 | } 28 | if (HashHelper.VerifyWithSalt(m.Solt , RegisterHelper.Instance.GetLockFile( m.Listenaddr, m.LockName))) 29 | { 30 | Console.Write("验证成功"); 31 | } 32 | else 33 | { 34 | m.Noregister(); 35 | 36 | 37 | } 38 | 39 | } 40 | 41 | public void OnPreInitialize(IContainerProvider containerProvider) 42 | { 43 | 44 | } 45 | 46 | public void OnPostInitialize(IContainerProvider containerProvider) 47 | { 48 | 49 | } 50 | IContainerProvider containerProvider; 51 | public void OnInitialize(IContainerProvider containerProvider) 52 | { 53 | 54 | } 55 | 56 | 57 | 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER.USendor/Center/SendorCenter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Collections.Generic; 4 | using System.ComponentModel; 5 | using System.Linq; 6 | using System.Reflection; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using UPPERIOC.UPPER.IOC.Center.IProvider; 10 | 11 | namespace UPPERIOC2.UPPER.USendor.Center 12 | { 13 | public class SendorCenter 14 | { 15 | public static IContainerProvider Contain; 16 | static ConcurrentDictionary> Events = new ConcurrentDictionary>(); 17 | public static void Register(Action @event) 18 | { 19 | Events[typeof(TEvent)] = new Func((obj) => 20 | { 21 | @event?.Invoke((TEvent)obj); 22 | return null; 23 | }); 24 | 25 | } 26 | public static void UnRegister() 27 | { 28 | Events.TryRemove(typeof(TEvent), out Func F); 29 | 30 | } 31 | 32 | public static void Register(Func @event) 33 | { 34 | Events[typeof(TInEvent)] = new Func((obj) => 35 | { 36 | return @event?.Invoke((TInEvent)obj); 37 | }); 38 | 39 | } 40 | 41 | public static object Publish(TEvent T) 42 | { 43 | /*if (T.GetType() != typeof(TEvent)) 44 | { 45 | return Events[T.GetType()]?.Invoke(T); 46 | 47 | }*/ 48 | return Events[typeof(TEvent)]?.Invoke(T); 49 | 50 | 51 | } 52 | 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /UPPERIOC/Util/DumpHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.IO; 4 | using System.Runtime.InteropServices; 5 | 6 | public class DumpHelper 7 | { 8 | [DllImport("DbgHelp.dll", SetLastError = true)] 9 | static extern bool MiniDumpWriteDump( 10 | IntPtr hProcess, 11 | uint processId, 12 | IntPtr hFile, 13 | MINIDUMP_TYPE dumpType, 14 | IntPtr expParam, 15 | IntPtr userStreamParam, 16 | IntPtr callbackParam); 17 | 18 | [Flags] 19 | 20 | enum MINIDUMP_TYPE : uint 21 | { 22 | MiniDumpNormal = 0x00000000, // 标准小型转储,仅包含必要的系统信息和堆栈 23 | MiniDumpWithDataSegs = 0x00000001, // 包含数据段的信息 24 | MiniDumpWithFullMemory = 0x00000002, // 包含进程的所有内存(可能会导致非常大的转储文件) 25 | MiniDumpWithHandleData = 0x00000004, // 包含句柄信息 26 | MiniDumpWithUnloadedModules = 0x00000008, // 包含已卸载模块的信息 27 | MiniDumpWithIndirectlyReferencedMemory = 0x00000010, // 包含间接引用的内存 28 | // ... 其他标志,如 MiniDumpWithFilterData, MiniDumpWithPrivateReadWriteMemory 等 29 | } 30 | 31 | public static void CreateDump(string dumpFilePath) 32 | { 33 | Process currentProcess = Process.GetCurrentProcess(); 34 | using (FileStream fs = new FileStream(dumpFilePath, FileMode.Create, FileAccess.Write, FileShare.None)) 35 | { 36 | bool result = MiniDumpWriteDump( 37 | currentProcess.Handle, 38 | (uint)currentProcess.Id, 39 | fs.SafeFileHandle.DangerousGetHandle(), 40 | MINIDUMP_TYPE.MiniDumpWithFullMemory, 41 | IntPtr.Zero, 42 | IntPtr.Zero, 43 | IntPtr.Zero); 44 | 45 | if (!result) 46 | { 47 | throw new Exception("Failed to create dump file."); 48 | } 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /.workflow/master-pipeline.yml: -------------------------------------------------------------------------------- 1 | version: '1.0' 2 | name: master-pipeline 3 | displayName: MasterPipeline 4 | stages: 5 | - stage: 6 | name: compile 7 | displayName: 编译 8 | steps: 9 | - step: build@maven 10 | name: build_maven 11 | displayName: Maven 构建 12 | # 支持6、7、8、9、10、11六个版本 13 | jdkVersion: 8 14 | # 支持2.2.1、3.2.5、3.3.9、3.5.2、3.5.3、3.5.4、3.6.1、3.6.3八个版本 15 | mavenVersion: 3.3.9 16 | # 构建命令 17 | commands: 18 | - mvn -B clean package -Dmaven.test.skip=true 19 | # 非必填字段,开启后表示将构建产物暂存,但不会上传到制品库中,7天后自动清除 20 | artifacts: 21 | # 构建产物名字,作为产物的唯一标识可向下传递,支持自定义,默认为BUILD_ARTIFACT。在下游可以通过${BUILD_ARTIFACT}方式引用来获取构建物地址 22 | - name: BUILD_ARTIFACT 23 | # 构建产物获取路径,是指代码编译完毕之后构建物的所在路径,如通常jar包在target目录下。当前目录为代码库根目录 24 | path: 25 | - ./target 26 | - step: publish@general_artifacts 27 | name: publish_general_artifacts 28 | displayName: 上传制品 29 | # 上游构建任务定义的产物名,默认BUILD_ARTIFACT 30 | dependArtifact: BUILD_ARTIFACT 31 | # 上传到制品库时的制品命名,默认output 32 | artifactName: output 33 | dependsOn: build_maven 34 | - stage: 35 | name: release 36 | displayName: 发布 37 | steps: 38 | - step: publish@release_artifacts 39 | name: publish_release_artifacts 40 | displayName: '发布' 41 | # 上游上传制品任务的产出 42 | dependArtifact: output 43 | # 发布制品版本号 44 | version: '1.0.0.0' 45 | # 是否开启版本号自增,默认开启 46 | autoIncrement: true 47 | triggers: 48 | push: 49 | branches: 50 | include: 51 | - master 52 | -------------------------------------------------------------------------------- /.workflow/branch-pipeline.yml: -------------------------------------------------------------------------------- 1 | version: '1.0' 2 | name: branch-pipeline 3 | displayName: BranchPipeline 4 | stages: 5 | - stage: 6 | name: compile 7 | displayName: 编译 8 | steps: 9 | - step: build@maven 10 | name: build_maven 11 | displayName: Maven 构建 12 | # 支持6、7、8、9、10、11六个版本 13 | jdkVersion: 8 14 | # 支持2.2.1、3.2.5、3.3.9、3.5.2、3.5.3、3.5.4、3.6.1、3.6.3八个版本 15 | mavenVersion: 3.3.9 16 | # 构建命令 17 | commands: 18 | - mvn -B clean package -Dmaven.test.skip=true 19 | # 非必填字段,开启后表示将构建产物暂存,但不会上传到制品库中,7天后自动清除 20 | artifacts: 21 | # 构建产物名字,作为产物的唯一标识可向下传递,支持自定义,默认为BUILD_ARTIFACT。在下游可以通过${BUILD_ARTIFACT}方式引用来获取构建物地址 22 | - name: BUILD_ARTIFACT 23 | # 构建产物获取路径,是指代码编译完毕之后构建物的所在路径,如通常jar包在target目录下。当前目录为代码库根目录 24 | path: 25 | - ./target 26 | - step: publish@general_artifacts 27 | name: publish_general_artifacts 28 | displayName: 上传制品 29 | # 上游构建任务定义的产物名,默认BUILD_ARTIFACT 30 | dependArtifact: BUILD_ARTIFACT 31 | # 上传到制品库时的制品命名,默认output 32 | artifactName: output 33 | dependsOn: build_maven 34 | - stage: 35 | name: release 36 | displayName: 发布 37 | steps: 38 | - step: publish@release_artifacts 39 | name: publish_release_artifacts 40 | displayName: '发布' 41 | # 上游上传制品任务的产出 42 | dependArtifact: output 43 | # 发布制品版本号 44 | version: '1.0.0.0' 45 | # 是否开启版本号自增,默认开启 46 | autoIncrement: true 47 | triggers: 48 | push: 49 | branches: 50 | exclude: 51 | - master 52 | include: 53 | - .* 54 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER._Premission/IConfiguation/RigisterObjLoad.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Win32; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Runtime.InteropServices; 6 | using System.Text; 7 | using System.Xml.Serialization; 8 | using UPPERIOC; 9 | 10 | namespace UPPERIOC2.UPPER.Premission 11 | { 12 | public class RigisterObjLoad 13 | { 14 | public static RigisterObjLoad GetInstance(string root) 15 | { 16 | RigisterObjLoad[] r = UPPERIOCApplication.Container.GetAllInstance() ; 17 | if (r == null || r.Length == 0) 18 | { 19 | throw new Exception("至少注册一个RigisterObjLoad 的实现类"); 20 | 21 | } 22 | r[0].RegistryRoot = root; 23 | return r[0]; 24 | } 25 | private string RegistryRoot; 26 | 27 | public virtual void SaveObjectToRegistry(string keyName, object obj) 28 | { 29 | if (obj == null) 30 | { 31 | return; 32 | } 33 | XmlSerializer xml = new XmlSerializer(obj.GetType()); 34 | StringWriter sw = new StringWriter(); 35 | xml.Serialize(sw, obj); 36 | // Registry.SetValue(RegistryRoot, keyName, sw.ToString()); 37 | } 38 | 39 | public virtual T LoadObjectFromRegistry(string keyName) where T : new() 40 | { 41 | XmlSerializer xml = new XmlSerializer(typeof(T)); 42 | // string t = (string)Registry.GetValue(RegistryRoot, keyName, null); 43 | // if (t == null) 44 | { 45 | return default(T); 46 | } 47 | 48 | // return (T)xml.Deserialize(sw); 49 | 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER/_Inter/VersionModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.Design; 4 | using System.IO; 5 | using System.Runtime.Serialization; 6 | using System.Text; 7 | using System.Xml.Serialization; 8 | 9 | namespace UPPERIOC2.UPPER.Model 10 | { 11 | public class VersionModel 12 | { 13 | public VersionModel() 14 | { 15 | InitModel(); 16 | } 17 | 18 | public virtual double NowVersion { get; set; } 19 | 20 | public virtual void SaveModel() 21 | { 22 | var serializer = new XmlSerializer(typeof(VersionModel)); 23 | var path = Path.Combine(Directory.GetCurrentDirectory(), "Version.xml"); 24 | 25 | using (var writer = new StreamWriter(path)) 26 | { 27 | serializer.Serialize(writer, this); 28 | } 29 | } 30 | 31 | public virtual void InitModel() 32 | { 33 | var serializer = new XmlSerializer(typeof(VersionModel)); 34 | var path = Path.Combine(Directory.GetCurrentDirectory(), "Version.xml"); 35 | 36 | if (File.Exists(path)) 37 | { 38 | using (var reader = new StreamReader(path)) 39 | { 40 | var loadedModel = (VersionModel)serializer.Deserialize(reader); 41 | if (loadedModel != null) 42 | { 43 | NowVersion = loadedModel.NowVersion; 44 | } 45 | } 46 | } 47 | // 如果文件不存在,可以设置一个默认值或抛出异常 48 | else 49 | { 50 | Console.WriteLine("Version.xml file not found. Using default version."); 51 | // 设定一个默认值 52 | NowVersion = 0.0; 53 | } 54 | } 55 | 56 | 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER/MoudleManager/UPPERMoudleManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UPPERIOC.UPPER.IOC.Center.Configuation; 3 | using UPPERIOC.UPPER.IOC.Moudle; 4 | using UPPERIOC.UPPER.Translate.IConfigration; 5 | using UPPERIOC.UPPER.UFileLog.IConfiguation; 6 | using UPPERIOC.UPPER.UFILELOG.Moudle; 7 | using UPPERIOC2.UPPER.MLOCK.IConfiguation; 8 | using UPPERIOC2.UPPER.Translate.Moudle; 9 | using UPPERIOC2.UPPER.UFileModel.IConfiguaion; 10 | using UPPERIOC2.UPPER.UFileModel.Moudle; 11 | 12 | namespace UPPERIOC.UPPER.IOC.Center.Configuation 13 | { 14 | public static class UPPERMoudleManager 15 | { 16 | public static void UPPERIOCMoudle(this ModuleConfiguaion md) 17 | { 18 | md.AddModule(); 19 | } 20 | 21 | public static void UPPERMLockMoudle(this ModuleConfiguaion md,MLockConfiguation conf) 22 | { 23 | if (conf != null) 24 | { 25 | md.Provider.Rigister(conf.GetType(),conf); 26 | } 27 | md.AddModule(); 28 | } 29 | 30 | public static void UPPERTranslateMoudle(this ModuleConfiguaion md,ITranslateConfig conf) 31 | { 32 | if (conf != null) 33 | { 34 | md.Provider.Rigister(conf.GetType(), conf); 35 | } 36 | 37 | md.AddModule(); 38 | } 39 | 40 | public static void UPPERLogFileMoudle(this ModuleConfiguaion md,IFileLogConfiguation conf) 41 | { 42 | if (conf != null) 43 | { 44 | md.Provider.Rigister(conf.GetType(), conf); 45 | } 46 | md.AddModule(); 47 | } 48 | 49 | public static void UPPERFileModelMoudle(this ModuleConfiguaion md,IUFileModelConfiguation conf) 50 | { 51 | 52 | if (conf != null) 53 | { 54 | md.Provider.Rigister(conf.GetType(), conf); 55 | } 56 | md.AddModule(); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER.MLOCK/Center/RegistryRegisterConsole.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Runtime.InteropServices; 5 | using System.Security; 6 | using System.Text; 7 | using UPPERIOC.UPPER.IOC.Moudle; 8 | using UPPERIOC2.UPPER.MLOCK.IConfiguation; 9 | using UPPERIOC2.UPPER.Util; 10 | using static UPPERIOC.UPPER.IOC.Moudle.UPPERMLockModule; 11 | 12 | namespace UPPERIOC2.UPPER.MLOCK.Center 13 | { 14 | public class RegistryRegisterConsole 15 | { 16 | 17 | 18 | 19 | internal static bool CompareSecureStrings(SecureString secureString, string plainString) 20 | { 21 | // Convert SecureString to plain string 22 | IntPtr secureStringPtr = IntPtr.Zero; 23 | try 24 | { 25 | var s = new SecureString(); 26 | for (int i = 0; i < plainString.Length; i++) 27 | { 28 | s.AppendChar(plainString[i]); 29 | 30 | } 31 | 32 | return s.Equals(secureString); 33 | 34 | } 35 | finally 36 | { 37 | // Ensure the secure string memory is cleared 38 | if (secureStringPtr != IntPtr.Zero) 39 | { 40 | Marshal.ZeroFreeGlobalAllocUnicode(secureStringPtr); 41 | } 42 | } 43 | } 44 | internal static void Rigister(MLockConfiguation m) 45 | { 46 | 47 | var r = HashHelper.EncryptWithSalt(m.Solt); 48 | RegisterHelper.Instance.SaveLockFile(m.Listenaddr, m.LockName,r); 49 | 50 | Console.WriteLine("注册成功,使用愉快"); 51 | 52 | } 53 | internal static bool ValidateSecureString(SecureString secureString) 54 | { 55 | // 确保传入的是SecureString类型 56 | if (secureString == null) 57 | throw new ArgumentException("secureString"); 58 | 59 | // 将SecureString转换为常规字符串进行验证 60 | IntPtr ptr = Marshal.SecureStringToBSTR(secureString); 61 | try 62 | { 63 | return ptr != IntPtr.Zero && Marshal.ReadInt32(ptr) != 0; 64 | } 65 | finally 66 | { 67 | // 释放非托管资源 68 | Marshal.ZeroFreeBSTR(ptr); 69 | } 70 | } 71 | 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER/Moudle_/Initializer/ModuleInitializer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.CompilerServices; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using UPPERIOC.UPPER.Event.AppEvent.Impl; 8 | using UPPERIOC.UPPER.IOC.Center.Configuation; 9 | using UPPERIOC.UPPER.IOC.Moudle; 10 | using UPPERIOC2.UPPER.UIOC.Center; 11 | 12 | namespace UPPERIOC.UPPER.Moudle_.Initializer 13 | { 14 | public static class ModuleInitializer 15 | { 16 | public static void InitModules(ModuleConfiguaion config) 17 | { 18 | var modules = config.Modules ; 19 | modules.RemoveAll(x => x is UPPERIOCModule); // 主模块留在外部控制 20 | 21 | var core = new UPPERIOCModule(); 22 | core.OnPreInitialize(config.Provider); 23 | modules.ForEach(m => { 24 | if (m is IModulePreInitialization i) 25 | { 26 | i.OnPreInitialize(config.Provider); 27 | } 28 | }); 29 | U.E.PublishEvent(new ApplicationModuleInitializedEvent()); 30 | 31 | core.OnInitialize(config.Provider); 32 | modules.ForEach(m => { 33 | if (m is IModuleInitialization i) 34 | { 35 | i.OnInitialize(config.Provider); 36 | } 37 | }); 38 | U.E.PublishEvent(new ApplicationModulePreCreationEvent()); 39 | 40 | core.OnPostConstruct(config.Provider); 41 | modules.ForEach(m => { 42 | if (m is IModulePostConstruction i) 43 | { 44 | i.OnPostConstruct(config.Provider); 45 | } 46 | }); 47 | U.E.PublishEvent(new ApplicationInstanceCreatedEvent()); 48 | 49 | core.OnPostInitialize(config.Provider); 50 | modules.ForEach(m => { 51 | if (m is IModulePostInitialization i) 52 | { 53 | i.OnPostInitialize(config.Provider); 54 | } 55 | }); 56 | U.E.PublishEvent(new ApplicationInitEndEvent()); 57 | } 58 | 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER/Moudle_/MoudleLoader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace UPPERIOC.UPPER.Moudle_ 6 | { 7 | public class ModuleLoader 8 | { 9 | private enum VisitState { NotVisited, Visiting, Visited } 10 | 11 | private readonly Dictionary _moduleMap; 12 | private readonly Dictionary _visitStates = new(); 13 | private readonly List _sortedModules = new(); 14 | 15 | public ModuleLoader(List modules) 16 | { 17 | _moduleMap = modules.ToDictionary(m => m.GetType(), m => m); 18 | } 19 | 20 | /// 21 | /// 获取模块的加载顺序(拓扑顺序) 22 | /// 23 | public List GetLoadOrder() 24 | { 25 | _visitStates.Clear(); 26 | _sortedModules.Clear(); 27 | 28 | foreach (var module in _moduleMap.Values) 29 | { 30 | Visit(module); 31 | } 32 | 33 | return new List(_sortedModules); 34 | } 35 | 36 | /// 37 | /// 获取模块的注销顺序(反向拓扑顺序) 38 | /// 39 | public List GetUnloadOrder() 40 | { 41 | return GetLoadOrder().AsEnumerable().Reverse().ToList(); 42 | } 43 | 44 | private void Visit(IUPPERModule module) 45 | { 46 | var type = module.GetType(); 47 | 48 | if (_visitStates.TryGetValue(type, out var state)) 49 | { 50 | if (state == VisitState.Visited) 51 | return; 52 | if (state == VisitState.Visiting) 53 | throw new Exception($"模块 {type.Name} 存在循环依赖"); 54 | } 55 | 56 | _visitStates[type] = VisitState.Visiting; 57 | 58 | foreach (var depType in module.Dependencies ?? Array.Empty()) 59 | { 60 | if (!_moduleMap.TryGetValue(depType, out var depModule)) 61 | { 62 | throw new Exception($"模块 {type.Name} 依赖的模块 {depType.Name} 未在模块列表中注册"); 63 | } 64 | 65 | Visit(depModule); 66 | } 67 | 68 | _visitStates[type] = VisitState.Visited; 69 | _sortedModules.Add(module); // 加入结果(拓扑顺序) 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER.Translate/Moudle/UPPERTranslateModule.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using UPPERIOC.UPPER; 7 | using UPPERIOC.UPPER.IOC.Center.IProvider; 8 | using UPPERIOC.UPPER.Moudle_; 9 | using UPPERIOC.UPPER.Translate.IConfigration; 10 | using UPPERIOC2.UPPER.Translate.Center; 11 | using UPPERIOC2.UPPER.Translate.Model; 12 | using UPPERIOC2.UPPER.UFileModel.Center; 13 | using UPPERIOC2.UPPER.UFileModel.Model; 14 | using UPPERIOC2.UPPER.UFileModel.Moudle; 15 | 16 | namespace UPPERIOC2.UPPER.Translate.Moudle 17 | { 18 | public class UPPERTranslateModule : IUPPERModule, IModulePostConstruction, IModuleInitialization, IModulePostInitialization, IModulePreInitialization 19 | { 20 | public override Type[] Dependencies { get => new Type[] { typeof(UFileModel.Moudle.UPPERFileModelModule) }; } 21 | 22 | public void OnPostConstruct(IContainerProvider containerProvider) 23 | { 24 | 25 | } 26 | 27 | public void OnPostInitialize(IContainerProvider containerProvider) 28 | { 29 | var cof = containerProvider.GetInstanceAndSub(); 30 | 31 | TranslateCenter.Instance.SetLanguage(cof.ToLanguage); 32 | } 33 | 34 | public void OnInitialize(IContainerProvider containerProvider) 35 | { 36 | if (F.I == null) 37 | { 38 | var err = "TranslateMoudle使用到了UPPERFileModelMoudle,而UPPERFileModelMoudle未注册"; 39 | LogCenter.Log(UPPERIOC.UPPER.enums.LogType.Error,err); 40 | throw new Exception(err); 41 | } 42 | TranslateModel tm = F.I.GetModel(new TranslateModel()); 43 | TranslateCenter.Instance = new TranslateCenter(containerProvider); 44 | 45 | 46 | //TranslateCenter.Instance.TranslateModel = tm; 47 | // if (TranslateCenter.Instance.TranslateBlock == null && string.IsNullOrWhiteSpace(TranslateCenter.Instance.L)) 48 | { 49 | // TranslateCenter.Instance.TranslateBlock = tm.Translateblocks.Find(x => x.Name == TranslateCenter.Instance.L); 50 | // if (TranslateCenter.Instance.TranslateBlock == null) 51 | // { 52 | // TranslateCenter.Instance.TranslateBlock = new Translateblock(); 53 | // tm.Translateblocks.Add(TranslateCenter.Instance.TranslateBlock); 54 | // } 55 | } 56 | } 57 | 58 | public void OnPreInitialize(IContainerProvider containerProvider) 59 | { 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER/MainApplication/UPPERIOCApplication.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using System.Windows.Forms; 3 | using UPPERIOC.UPPER.Event.AppEvent; 4 | using UPPERIOC.UPPER.Event.AppEvent.Impl; 5 | using UPPERIOC.UPPER.IOC.Center.Configuation; 6 | using UPPERIOC.UPPER.IOC.Center.IProvider; 7 | using UPPERIOC.UPPER.MainApplication.Dispatcher; 8 | using UPPERIOC.UPPER.MainApplication.Log_; 9 | using UPPERIOC.UPPER.Moudle_; 10 | using UPPERIOC.UPPER.Moudle_.Initializer; 11 | using UPPERIOC2.UPPER.Model; 12 | using UPPERIOC2.UPPER.UIOC.Center; 13 | 14 | namespace UPPERIOC 15 | { 16 | public class UPPERIOCApplication 17 | { 18 | public static IContainerProvider Container { get; set; } 19 | public static ApplicationEventManager EventManager { get; set; } 20 | public static VersionModel vm; 21 | internal static List Log; 22 | 23 | public static void RunInstance(ModuleConfiguaion config) 24 | { 25 | LogManager.Init(config.Logs); 26 | Container = config.Provider; 27 | EventManager = EventDispatcher.InitAndRegister(Container); 28 | 29 | EventManager.PublishEvent(new ApplicationPreInitializationEvent()); 30 | 31 | ModuleInitializer.InitModules(config); 32 | AppDomain.CurrentDomain.ProcessExit += (_, __) => 33 | { 34 | EventManager.PublishEvent(new ApplicationStoppingEvent()); 35 | config.UnLoadModules.ForEach(module => { 36 | if (module is IModulePreDestruction pred) 37 | { 38 | pred.OnPreDestroy(Container); 39 | } 40 | }); 41 | EventManager.PublishEvent(new ApplicationStoppedEvent()); 42 | }; 43 | } 44 | public static void RunInstance(Action configAction = null,Action eventAction = null) 45 | { 46 | var config = new ModuleConfiguaion(); 47 | configAction?.Invoke(config); 48 | config.Provider = config.Provider; 49 | U._e = config.EventManager; 50 | eventAction?.Invoke(config.EventManager); 51 | RunInstance(config); 52 | } 53 | 54 | public static void RegisterVersionModel(VersionModel model) 55 | { 56 | if (model == null) return; 57 | vm = model; 58 | } 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /UPPER.Test.Share/UPPER.Test.Share.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {F780C7B8-F373-486E-BD5E-A67364027B28} 8 | Library 9 | Properties 10 | UPPER.Test.Share 11 | UPPER.Test.Share 12 | v4.7.2 13 | 512 14 | true 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 2.0.4.54 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /UPPERIOC/Util/AnimationUtil.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | 9 | namespace UPPERIOC2.UPPER.Util 10 | { 11 | public class AnimationUtil 12 | { 13 | 14 | private bool _isRunning = false; 15 | public static AnimationUtil Instance { get; private set; } = new AnimationUtil(); 16 | public ConcurrentQueue>> Data = new ConcurrentQueue>>(); 17 | public AnimationUtil() { 18 | _isRunning = true; 19 | Task.Factory.StartNew(() => { 20 | List>> Data = new List>>(); 21 | List>> DelTemp= new List>>(); 22 | while (_isRunning) 23 | { 24 | 25 | if (this.Data.TryDequeue(out var x)) 26 | { 27 | Data.Add(x); 28 | } 29 | using (var e = Data.GetEnumerator()) 30 | { 31 | while (e.MoveNext()) 32 | { 33 | e.Current.Key -= 5; 34 | if (e.Current.Key < 0) 35 | { 36 | DelTemp.Add(e.Current); 37 | } 38 | e.Current.Value.Invoke(e.Current.Key); 39 | } 40 | } 41 | Data.RemoveAll(item=> DelTemp.Contains(item)); 42 | DelTemp.Clear(); 43 | Thread.Sleep(5); 44 | } 45 | }); 46 | } 47 | ~AnimationUtil() { 48 | _isRunning &= false; 49 | } 50 | public void SetAnimation(int AllTime,Action Invoke) 51 | { 52 | Data.Enqueue(new KeyValuePair>(AllTime , Invoke)); 53 | } 54 | } 55 | public class KeyValuePair { 56 | public TKey Key { get; set; } 57 | public TValue Value { get; set; } 58 | public KeyValuePair(TKey key, TValue value) 59 | { 60 | Key = key; 61 | Value = value; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /TestDemo/MFileLogTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Runtime.CompilerServices; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using UPPERIOC; 9 | using UPPERIOC.UPPER; 10 | using UPPERIOC.UPPER.enums; 11 | using UPPERIOC.UPPER.IOC.Center.Configuation; 12 | using UPPERIOC.UPPER.UFileLog.IConfiguation; 13 | using Xunit; 14 | 15 | namespace UPPERTest 16 | { 17 | public class MFileLogTest 18 | { 19 | public class FIleLogConfig : IFileLogConfiguation 20 | { 21 | public bool PrintMs { get => true; set => throw new NotImplementedException(); } 22 | public string DirectoryName { get => "UPPER"; set => throw new NotImplementedException(); } 23 | public string DefaultExt { get =>".txt"; set => throw new NotImplementedException(); } 24 | public List WhichTypePrint { get => Enum.GetValues().ToList(); set => throw new NotImplementedException(); } 25 | public string FileNameTimeFormat { get => "yyyyMMdd"; set => throw new NotImplementedException(); } 26 | public int HowManyHourSave { get => 48; set => throw new NotImplementedException(); } 27 | 28 | public bool MutiFileName => false; 29 | } 30 | [Fact] 31 | public void MFileWriten() 32 | { 33 | // 启动应用并注册日志配置 34 | UPPERIOCApplication.RunInstance(md => 35 | { 36 | md.UPPERLogFileMoudle(new FIleLogConfig()); 37 | }); 38 | 39 | // 写入日志 40 | LogCenter.Log(LogType.Error, "Hello,UPPER"); 41 | LogCenter.Log(LogType.Info, "Hello,UPPER"); 42 | 43 | // 获取日志文件路径 44 | string logFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "UPPER"); 45 | string logFileName = $"{DateTime.Now:yyyyMMdd}.txt"; 46 | string logFilePath = Path.Combine(logFolder, logFileName); 47 | 48 | // 等待日志写入完成(如有异步写入) 49 | System.Threading.Thread.Sleep(500); // 可视情况调整 50 | 51 | Assert.True(File.Exists(logFilePath), $"日志文件未找到: {logFilePath}"); 52 | 53 | string content = File.ReadAllText(logFilePath); 54 | 55 | // 验证内容 56 | Assert.Contains("Error", content); 57 | Assert.Contains("Info", content); 58 | Assert.Contains("Hello,UPPER", content); 59 | 60 | // 删除日志文件(清理) 61 | File.Delete(logFilePath); 62 | Assert.False(File.Exists(logFilePath), "日志文件未成功删除"); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /UPPERIOC/targets/upperioc.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(RootNamespace) 5 | 6 | <_UPPERIOCMSBuildMinVersion>16.8.0 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | <_UPPERIOCAnalyzer Include="@(Analyzer)" Condition="'%(Analyzer.NuGetPackageId)' == 'IOCG'" /> 19 | 20 | 21 | 22 | 26 | 27 | 28 | 29 | 30 | 32 | 33 | 34 | 35 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 53 | 54 | 57 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /UPPER.ApplicationEventTest/UPPER.Test.ApplicationEventTest.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {58362791-4E08-46DB-9C63-F3A83D0CC7C0} 8 | Exe 9 | UPPER.ApplicationEventTest 10 | UPPER.ApplicationEventTest 11 | v4.7.2 12 | 512 13 | true 14 | true 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 2.0.4.54 55 | 56 | 57 | 2.9.3 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER.UFileLog/Moudle/UPPERLogFileModule.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using UPPERIOC.UPPER.UFileLog.IConfiguation; 8 | using UPPERIOC.UPPER.IOC.Annaiation; 9 | using UPPERIOC.UPPER.IOC.Center.IProvider; 10 | using UPPERIOC.UPPER.IOC.Moudle; 11 | using UPPERIOC.UPPER.UFileLog.DefineLog; 12 | using UPPERIOC.UPPER.Moudle_; 13 | 14 | 15 | namespace UPPERIOC.UPPER.UFILELOG.Moudle 16 | { 17 | public class UPPERLogFileModule : IUPPERModule, IModulePostConstruction, IModuleInitialization, IModulePostInitialization, IModulePreInitialization 18 | { 19 | IContainerProvider? containerProvider; 20 | public override Type[] Dependencies { get => new Type[] { }; } 21 | 22 | public void OnPostConstruct(IContainerProvider containerProvider) 23 | { 24 | var con = (IFileLogConfiguation)containerProvider.GetInstance(typeof(IFileLogConfiguation)); 25 | LogCenter.AddLogger(containerProvider.Rigister()); 26 | BindExceptionHandler(); 27 | 28 | } 29 | 30 | public void OnPreInitialize(IContainerProvider containerProvider) 31 | { 32 | 33 | } 34 | 35 | public void OnPostInitialize(IContainerProvider containerProvider) 36 | { 37 | 38 | } 39 | private static void BindExceptionHandler() 40 | { 41 | //设置应用程序处理异常方式:ThreadException处理 42 | //Application.SetUnhandledExceptionMode(UnhandledExceptionMode.Automatic); 43 | //处理UI线程异常 44 | // Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); 45 | //处理未捕获的异常 46 | AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); 47 | } 48 | 49 | private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) 50 | { 51 | if (e.ExceptionObject is Exception ex) 52 | { 53 | HandleEx(ex); 54 | } 55 | else 56 | { 57 | LogCenter.Log(UPPERIOC.UPPER.enums.LogType.Error, $"全局异常:{e.ExceptionObject.ToString()}\r\n"); 58 | 59 | } 60 | 61 | } 62 | 63 | private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e) 64 | { 65 | HandleEx(e.Exception); 66 | } 67 | private static void HandleEx(Exception ex) 68 | { 69 | LogCenter.Log(UPPERIOC.UPPER.enums.LogType.Error, $"全局异常:{ex.Message}\r\n{ex.StackTrace}"); 70 | throw ex; 71 | } 72 | 73 | 74 | public void OnInitialize(IContainerProvider containerProvider) 75 | { 76 | this.containerProvider = containerProvider; 77 | 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # ============================================================ 2 | # Standard .gitignore for WinForms / Visual Studio projects 3 | # Based on GitHub's VisualStudio.gitignore plus WinForms‑specific entries 4 | # ============================================================ 5 | 6 | ############## 7 | # OS files 8 | ############## 9 | # Windows 10 | Thumbs.db 11 | ehthumbs.db 12 | Desktop.ini 13 | $RECYCLE.BIN/ 14 | 15 | # macOS 16 | .DS_Store 17 | 18 | # Linux 19 | *~ 20 | 21 | ############## 22 | # User‑specific Visual Studio / IDE files 23 | ############## 24 | *.rsuser 25 | *.suo 26 | *.user 27 | *.userosscache 28 | *.sln.docstates 29 | *.vcxproj.user 30 | *.code-workspace 31 | 32 | ############## 33 | # Build results 34 | ############## 35 | [Bb]in/ 36 | [Oo]bj/ 37 | [Ll]og/ 38 | [Dd]ebug*/ 39 | [Rr]elease*/ 40 | x64/ 41 | x86/ 42 | [Bb]uild/ 43 | [Tt]emp/ 44 | [Test]Results/ 45 | [Uu]nit[Tt]est+[Rr]esult*/ 46 | *.bak 47 | *.tmp 48 | 49 | ############## 50 | # NuGet packages 51 | ############## 52 | # Solution‑level or project‑level packages folders 53 | [Pp]ackages/ 54 | **/[Pp]ackages/ 55 | # Package files 56 | *.nupkg 57 | *.snupkg 58 | # Local NuGet cache (v3) 59 | ~/.nuget/packages/ 60 | 61 | ############## 62 | # Publish / Click‑Once / Setup artifacts 63 | ############## 64 | [Pp]ublish/ 65 | **/Properties/PublishProfiles/ 66 | AppPackages/ 67 | BundleArtifacts/ 68 | 69 | ############## 70 | # .NET build artifacts 71 | ############## 72 | *.dll 73 | *.exe 74 | *.apphost 75 | *.deps.json 76 | *.runtimeconfig.json 77 | *.mdb 78 | *.pdb 79 | 80 | ############## 81 | # Code Coverage & Profiling 82 | ############## 83 | *.coverage 84 | *.coveragexml 85 | *.vspx 86 | *.vsp 87 | *.sap 88 | 89 | ############## 90 | # Rider / ReSharper / VS Code / VS Cache 91 | ############## 92 | .idea/ 93 | .vs/ 94 | .vscode/ 95 | _ReSharper*/ 96 | *.[Rr]e[Ss]harper 97 | *.DotSettings.user 98 | 99 | ############## 100 | # Static Analysis & Intellisense 101 | ############## 102 | *.ruleSet 103 | *.gch 104 | *.ipch 105 | *.cache 106 | *.dbmdl 107 | 108 | ############## 109 | # Database / Data files 110 | ############## 111 | *.mdf 112 | *.ldf 113 | *.ndf 114 | *.sdf 115 | *.db 116 | *.sql 117 | *.sqlite 118 | 119 | ############## 120 | # Miscellaneous generated/intermediate files 121 | ############## 122 | *.ipdb 123 | *.iobj 124 | *.obj 125 | *.tlog 126 | *.ilk 127 | *.meta 128 | *.pch 129 | *.tlh 130 | *.tli 131 | *_i.c 132 | *_p.c 133 | *_i.h 134 | *.jfm 135 | *.snk 136 | *.log 137 | *.publishsettings 138 | 139 | ############## 140 | # Visual Studio solution‑specific cache you listed 141 | ############## 142 | /UpperComAutoTest/MyConfiguation/ErrorUpload.cs 143 | ProjectEvaluation/ 144 | /.vs/ProjectEvaluation 145 | /.vs/UpperComAutoTest 146 | /.vs/upperioc 147 | /.vs/.gitignore 148 | /.vs/VSWorkspaceState.json 149 | -------------------------------------------------------------------------------- /TestDemo/MLockTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Microsoft.Win32; 7 | using UPPERIOC; 8 | using UPPERIOC.UPPER.Event.AppEvent.Impl; 9 | using UPPERIOC.UPPER.IOC.Center.Configuation; 10 | using UPPERIOC2.UPPER.MLOCK.IConfiguation; 11 | using UPPERIOC2.UPPER.UIOC.Center; 12 | using Xunit; 13 | 14 | namespace UPPERTest 15 | { 16 | public class MLockTest 17 | { 18 | public class MLock:MLockConfiguation 19 | { 20 | public bool isre = true; 21 | public override string Solt { get; set; } = "UPPERIOC"; 22 | public override string Listenaddr { get; set; } = "addr"; 23 | public override string LockName { get; set; } = "xxx"; 24 | public override void Noregister() 25 | { 26 | Console.Write("没有注册"); 27 | isre = false; 28 | } 29 | } 30 | [Fact] 31 | public void MLockisok() 32 | { 33 | MLock m = new MLock(); 34 | m.UnloadRegister(); 35 | UPPERIOCApplication.RunInstance(md => { 36 | 37 | md.UPPERMLockMoudle(new MLock()); 38 | }); 39 | var mm = U.C.GetInstance(); 40 | Assert.Equal(false, mm.isre); 41 | } 42 | public class UnMLock : MLockConfiguation 43 | { 44 | public bool isre = false; 45 | public override string Solt { get; set; } = "UPPERIOC"; 46 | public override string Listenaddr { get; set; } = "addr"; 47 | public override string LockName { get; set; } = "xxx"; 48 | public override void Noregister() 49 | { 50 | Console.Write("注册中");//模拟注册操作 51 | Register(); 52 | isre = false; 53 | } 54 | protected override void Register() 55 | { 56 | base.Register(); 57 | isre = true; 58 | } 59 | } 60 | [Fact] 61 | public void UnMLockisOk() 62 | { 63 | UPPERIOCApplication.RunInstance(md => { 64 | var xx = new MLock(); 65 | md.UPPERMLockMoudle(xx); 66 | xx.UnloadRegister(); 67 | 68 | }); 69 | { 70 | var mm = U.C.GetInstance(); 71 | Assert.Equal(false, mm.isre); 72 | } 73 | UnMLock m = new UnMLock(); 74 | UPPERIOCApplication.RunInstance(md => { 75 | md.UPPERMLockMoudle(m); 76 | }); 77 | UPPERIOCApplication.RunInstance(md => { 78 | md.UPPERMLockMoudle(new MLock()); 79 | }); 80 | { 81 | var mm = U.C.GetInstance(); 82 | Assert.Equal(true, mm.isre); 83 | m.UnloadRegister(); 84 | } 85 | 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /UPPER.Test.MoudleLifecycle/Program.cs: -------------------------------------------------------------------------------- 1 | //// 监听者类:监听所有生命周期事件 2 | //using System.Collections.Generic; 3 | //using System; 4 | //using UPPERIOC.UPPER.Event.AppEvent.Impl; 5 | //using UPPERIOC; 6 | //using Xunit; 7 | //using System.IO; 8 | //using UPPERIOC2.UPPER.UIOC.Center; 9 | //using System.Linq; 10 | //using System.Diagnostics; 11 | //using System; 12 | 13 | using UPPERIOC; 14 | using UPPERIOC.UPPER.IOC.Center.Interface; 15 | using UPPERIOC.UPPER.IOC.Center.IProvider; 16 | 17 | namespace UPPER.Test.ApplicationEventTests 18 | { 19 | public class ProgramML 20 | { 21 | 22 | 23 | public class UPPERMLifecycleValidatorModule : IUPPERModule, 24 | IModulePreInitialization, 25 | IModuleInitialization, 26 | IModulePostInitialization, 27 | IModulePostConstruction, 28 | IModulePreDestruction 29 | { 30 | public static List LifecycleLog { get; } = new(); 31 | 32 | public override Type[] Dependencies => null; 33 | 34 | public void OnPostConstruct(IContainerProvider provider) 35 | { 36 | LifecycleLog.Add("OnPostConstruct"); 37 | Console.WriteLine("模块生命周期:OnPostConstruct"); 38 | } 39 | 40 | public void OnPreInitialize(IContainerProvider provider) 41 | { 42 | LifecycleLog.Add("OnPreInitialize"); 43 | Console.WriteLine("模块生命周期:OnPreInitialize"); 44 | } 45 | 46 | public void OnInitialize(IContainerProvider provider) 47 | { 48 | LifecycleLog.Add("OnInitialize"); 49 | Console.WriteLine("模块生命周期:OnInitialize"); 50 | } 51 | 52 | public void OnPostInitialize(IContainerProvider provider) 53 | { 54 | LifecycleLog.Add("OnPostInitialize"); 55 | Console.WriteLine("模块生命周期:OnPostInitialize"); 56 | } 57 | 58 | public void OnPreDestroy(IContainerProvider provider) 59 | { 60 | LifecycleLog.Add("OnPreDestroy"); 61 | Console.WriteLine("模块生命周期:OnPreDestroy"); 62 | } 63 | } 64 | public static void Main(string[] orgs) 65 | { 66 | if (orgs.Length != 1) 67 | { 68 | throw new Exception("未从正确的入口点进入代码"); 69 | } 70 | UPPERIOCApplication.RunInstance(md => { 71 | md.AddModule(); 72 | }); 73 | AppDomain.CurrentDomain.ProcessExit += (__, ___) => { 74 | if (UPPERMLifecycleValidatorModule.LifecycleLog.Count != 5) 75 | { 76 | throw new Exception("模块生命周期未正确执行"); 77 | } 78 | var li = new List() { "OnPreInitialize", "OnInitialize", "OnPostConstruct", "OnPostInitialize", "OnPreDestroy", }; 79 | if (!UPPERMLifecycleValidatorModule.LifecycleLog.SequenceEqual(li)) 80 | { 81 | throw new Exception("模块生命周期执行顺序错误"); 82 | } 83 | File.WriteAllText(orgs[0],"ok"); 84 | }; 85 | } 86 | } 87 | } -------------------------------------------------------------------------------- /UPPERIOC/UPPER.UFileLog/DefineLog/FileLog.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using UPPERIOC.UPPER.enums; 7 | using UPPERIOC.UPPER.UFileLog.IConfiguation; 8 | using System.IO; 9 | using UPPERIOC.UPPER.MainApplication.Log_; 10 | 11 | namespace UPPERIOC.UPPER.UFileLog.DefineLog 12 | { 13 | public class FileLog : ILog 14 | { 15 | IFileLogConfiguation Config; 16 | 17 | public FileLog(IFileLogConfiguation? Config) 18 | { 19 | if (Config == null) 20 | { 21 | throw new Exception("请将FileLog的配置类IFileLogConfiguation 实现交托容器管理"); 22 | } 23 | this.Config = Config; 24 | logt = Config.WhichTypePrint?.ToArray(); 25 | } 26 | LogType[]? logt; 27 | public LogType[] CanLogType { get { 28 | if (logt == null) 29 | { 30 | return new LogType[0]; 31 | } 32 | return logt; 33 | } 34 | } 35 | 36 | public void Log(LogType LogType, string Msg) 37 | { 38 | lock (Config) 39 | { 40 | var logtime = DateTime.Now; 41 | //路径 42 | var diname = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Config.DirectoryName); 43 | DirectoryInfo di = new DirectoryInfo(diname); 44 | if (!Directory.Exists(diname)) 45 | { 46 | Directory.CreateDirectory(diname); 47 | } 48 | //文件名 49 | var muti = ""; 50 | if (Config.MutiFileName) 51 | { 52 | muti = LogType.ToString(); 53 | } 54 | var filename = muti+ logtime.ToString(Config.FileNameTimeFormat) + Config.DefaultExt; 55 | DelTimeOutLog(di, logtime); 56 | var fullname = Path.Combine(diname, filename); 57 | if (!File.Exists(fullname)) 58 | { 59 | File.Create(fullname).Close(); 60 | } 61 | StringBuilder sb = new StringBuilder(); 62 | sb.Append(Enum.GetName(LogType.GetType(), LogType)); 63 | sb.Append(" - "); 64 | var sbf = "HH:mm:ss"; 65 | if (Config.PrintMs) 66 | { 67 | sbf += ":ffff"; 68 | 69 | } 70 | 71 | sb.Append(logtime.ToString(sbf)); 72 | sb.Append(":"); 73 | sb.Append(Msg); 74 | sb.Append("\n"); 75 | File.AppendAllText(fullname, sb.ToString()); 76 | } 77 | } 78 | 79 | private void DelTimeOutLog(DirectoryInfo di, DateTime now) 80 | { 81 | foreach (var item in di.GetFiles()) 82 | { 83 | if ((now - item.LastWriteTime).TotalHours > Config.HowManyHourSave) 84 | { 85 | try 86 | { 87 | 88 | item.Delete(); 89 | } 90 | catch (Exception) 91 | { 92 | 93 | } 94 | } 95 | } 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER.MLOCK/FileRigisterConsole.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Runtime.InteropServices; 5 | using System.Security; 6 | using System.Text; 7 | using UPPERIOC.UPPER.IOC.Moudle; 8 | using UPPERIOC2.UPPER.MLOCK.IConfiguation; 9 | using UPPERIOC2.UPPER.Util; 10 | using static UPPERIOC.UPPER.IOC.Moudle.UPPERMLockModule; 11 | 12 | namespace UPPERIOC2.UPPER.MLOCK 13 | { 14 | public class FileRigisterConsole 15 | { 16 | 17 | 18 | public static bool CompareSecureStrings(SecureString secureString, string plainString) 19 | { 20 | // Convert SecureString to plain string 21 | IntPtr secureStringPtr = IntPtr.Zero; 22 | try 23 | { 24 | var s = new SecureString(); 25 | for (int i = 0; i < plainString.Length; i++) 26 | { 27 | s.AppendChar(plainString[i]); 28 | 29 | } 30 | 31 | return s.Equals(secureString); 32 | // secureStringPtr = SecureStringMarshal.SecureStringToGlobalAllocUnicode(secureString); 33 | // string secureStringPlain = Marshal.PtrToStringUni(secureStringPtr); 34 | 35 | // Compare the two strings 36 | //return secureStringPlain.Equals(plainString); 37 | } 38 | finally 39 | { 40 | // Ensure the secure string memory is cleared 41 | if (secureStringPtr != IntPtr.Zero) 42 | { 43 | Marshal.ZeroFreeGlobalAllocUnicode(secureStringPtr); 44 | } 45 | } 46 | } 47 | 48 | 49 | internal static void Rigister(MLockConfiguation m) { 50 | //Console.WriteLine("欢迎使用注册器,请输入需要注册的验证码"); 51 | // 使用SecureString来存储密码,避免在内存中留下明文密码 52 | //SecureString password = new SecureString(); 53 | 54 | // 读取用户输入直到回车 55 | //while (true) 56 | //{ 57 | // ConsoleKeyInfo key = Console.ReadKey(true); // 第二个参数true表示不将按键显示在控制台上 58 | 59 | // if (key.Key == ConsoleKey.Enter) 60 | // { 61 | // break; // 如果按下的是回车键,则退出循环 62 | // } 63 | // else if (key.Key == ConsoleKey.Backspace) 64 | // { 65 | // // 如果按下的是退格键,并且SecureString中有字符,则移除最后一个字符 66 | // if (password.Length > 0) 67 | // { 68 | // password.RemoveAt(password.Length - 1); 69 | // Console.Write("\b \b"); // 使用退格和空格覆盖之前的字符,然后再次退格 70 | // } 71 | // } 72 | // else if (key.KeyChar >= 32) // 忽略控制字符 73 | // { 74 | // // 将输入的字符添加到SecureString中 75 | // password.AppendChar(key.KeyChar); 76 | // // 这里不打印任何字符,因为我们要隐藏输入 77 | // } 78 | //}; 79 | 80 | //if (!CompareSecureStrings(password,"admin")) 81 | //{ 82 | // Console.WriteLine("注册失败,密码错误"); 83 | // return; 84 | //} 85 | var r = HashHelper.EncryptWithSalt(m.Solt); 86 | var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, m.Listenaddr); 87 | File.Delete(path); 88 | File.WriteAllText(path, r, Encoding.ASCII); 89 | 90 | Console.WriteLine("注册成功,使用愉快"); 91 | // Console.ReadLine(); 92 | 93 | } 94 | public static bool ValidateSecureString(SecureString secureString) 95 | { 96 | // 确保传入的是SecureString类型 97 | if (secureString == null) 98 | throw new ArgumentException("secureString"); 99 | 100 | // 将SecureString转换为常规字符串进行验证 101 | IntPtr ptr = System.Runtime.InteropServices.Marshal.SecureStringToBSTR(secureString); 102 | try 103 | { 104 | return ptr != IntPtr.Zero && System.Runtime.InteropServices.Marshal.ReadInt32(ptr) != 0; 105 | } 106 | finally 107 | { 108 | // 释放非托管资源 109 | System.Runtime.InteropServices.Marshal.ZeroFreeBSTR(ptr); 110 | } 111 | } 112 | 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /UPPER.Test.ApplicationEventTests/Program.cs: -------------------------------------------------------------------------------- 1 | // 监听者类:监听所有生命周期事件 2 | using System.Collections.Generic; 3 | using System; 4 | using UPPERIOC.UPPER.Event.AppEvent.Impl; 5 | using UPPERIOC; 6 | using Xunit; 7 | using System.IO; 8 | using UPPERIOC2.UPPER.UIOC.Center; 9 | using System.Linq; 10 | using System.Diagnostics; 11 | 12 | namespace UPPER.Test.ApplicationEventTests { 13 | public class ProgramEntry 14 | { 15 | 16 | public class FullLifecycleListener : 17 | IUPPERApplicationListener, 18 | IUPPERApplicationListener, 19 | IUPPERApplicationListener, 20 | IUPPERApplicationListener, 21 | IUPPERApplicationListener, 22 | IUPPERApplicationListener, 23 | IUPPERApplicationListener 24 | { 25 | private readonly List _eventLog; 26 | 27 | public FullLifecycleListener(List eventLog) 28 | { 29 | _eventLog = eventLog; 30 | } 31 | 32 | public string MoudleName => "FullLifecycleListener"; 33 | 34 | public void OnEvent(ApplicationPreInitializationEvent e) => _eventLog.Add(nameof(ApplicationPreInitializationEvent)); 35 | public void OnEvent(ApplicationModuleInitializedEvent e) => _eventLog.Add(nameof(ApplicationModuleInitializedEvent)); 36 | public void OnEvent(ApplicationModulePreCreationEvent e) => _eventLog.Add(nameof(ApplicationModulePreCreationEvent)); 37 | public void OnEvent(ApplicationInstanceCreatedEvent e) => _eventLog.Add(nameof(ApplicationInstanceCreatedEvent)); 38 | public void OnEvent(ApplicationInitEndEvent e) => _eventLog.Add(nameof(ApplicationInitEndEvent)); 39 | public void OnEvent(ApplicationStoppingEvent e) => _eventLog.Add(nameof(ApplicationStoppingEvent)); 40 | public void OnEvent(ApplicationStoppedEvent e) => _eventLog.Add(nameof(ApplicationStoppedEvent)); 41 | } 42 | 43 | private static List _eventLog = new List(); 44 | public static void Main(string[] args) 45 | { 46 | if (args.Length != 1) 47 | { 48 | return; 49 | } 50 | var tpfile = args[0]; 51 | // var tpfile = "C://x.txt"; // 输出的文件路径 52 | _eventLog.Clear(); 53 | 54 | UPPERIOCApplication.RunInstance(md => { }, e => { 55 | // 注册监听器 56 | e.RegisterListener(new FullLifecycleListener(_eventLog)); 57 | }); 58 | 59 | // 依生命周期顺序触发事件 60 | AppDomain.CurrentDomain.ProcessExit += (__, ___) => { 61 | // 预期触发顺序 62 | var expectedOrder = new List 63 | { 64 | nameof(ApplicationPreInitializationEvent), 65 | nameof(ApplicationModuleInitializedEvent), 66 | nameof(ApplicationModulePreCreationEvent), 67 | nameof(ApplicationInstanceCreatedEvent), 68 | nameof(ApplicationInitEndEvent), 69 | nameof(ApplicationStoppingEvent), 70 | nameof(ApplicationStoppedEvent) 71 | }; 72 | 73 | // 验证触发顺序与预期一致 74 | Assert.Equal(expectedOrder, _eventLog); // 这里你可以添加断言或其它验证逻辑 75 | File.WriteAllText(tpfile, "ok"); 76 | 77 | // 将事件顺序写入文件 78 | }; 79 | } 80 | } 81 | } -------------------------------------------------------------------------------- /UPPERIOC/UPPER/IOC/DefaultProvider/Builder/InstanceBuilder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System; 7 | using System.Collections.Concurrent; 8 | using System.Collections.Generic; 9 | using System.Linq; 10 | using System.Reflection; 11 | using UPPERIOC.UPPER.IOC.Extend; 12 | using UPPERIOC2.UPPER.UFileModel.Model; 13 | using UPPERIOC2.UPPER.UFileModel.Center; 14 | using UPPERIOC.UPPER.IOC.Annaiation; 15 | 16 | namespace UPPERIOC.UPPER.IOC.DefaultProvider.Builder 17 | { 18 | 19 | public class InstanceBuilder 20 | { 21 | private readonly ConcurrentDictionary _constructorCache = new(); 22 | private readonly ConcurrentDictionary _propertyCache = new(); 23 | private readonly Func _resolveFunc; 24 | private readonly Func _resolveWithParams; 25 | 26 | public InstanceBuilder(Func resolveFunc, Func resolveWithParams) 27 | { 28 | _resolveFunc = resolveFunc; 29 | _resolveWithParams = resolveWithParams; 30 | } 31 | 32 | public object CreateInstance(Type type, bool subRegister = false, string name = null) 33 | { 34 | if (type == null) return null; 35 | 36 | // Check if type is allowed to be instantiated 37 | if (!type.HasBaseClassWithAttribute() && subRegister) 38 | { 39 | return null; 40 | } 41 | 42 | var constructor = GetConstructor(type); 43 | var parameters = constructor.GetParameters(); 44 | var paramValues = new object[parameters.Length]; 45 | 46 | for (int i = 0; i < parameters.Length; i++) 47 | { 48 | var paramType = parameters[i].ParameterType; 49 | var paramName = name; 50 | object dependency = _resolveWithParams(paramType, true, paramName); 51 | 52 | if (dependency == null) 53 | { 54 | dependency = CreateInstance(paramType, true, paramName); 55 | } 56 | 57 | paramValues[i] = dependency; 58 | } 59 | 60 | object instance = constructor.Invoke(paramValues); 61 | 62 | // Special handling for IModel 63 | if (typeof(IModel).IsAssignableFrom(type) && instance is IModel model) 64 | { 65 | instance = F.I.GetModel(model); 66 | } 67 | 68 | InjectProperties(instance, name); 69 | 70 | return instance; 71 | } 72 | 73 | private ConstructorInfo GetConstructor(Type type) 74 | { 75 | return _constructorCache.GetOrAdd(type, t => 76 | { 77 | var ctors = t.GetConstructors(); 78 | var selected = ctors.FirstOrDefault(c => c.GetCustomAttribute() != null); 79 | return selected ?? ctors.FirstOrDefault() ?? throw new Exception($"请至少为{t.Name}类保留一个开放的构造函数"); 80 | }); 81 | } 82 | 83 | private void InjectProperties(object instance, string name) 84 | { 85 | var props = _propertyCache.GetOrAdd(instance.GetType(), t => 86 | t.GetProperties().Where(p => p.GetCustomAttribute() != null).ToArray()); 87 | 88 | foreach (var prop in props) 89 | { 90 | var attr = prop.GetCustomAttribute(); 91 | var propInstance = _resolveWithParams(prop.PropertyType, false, attr?.Name ?? name); 92 | prop.SetValue(instance, propInstance); 93 | } 94 | } 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /IOCCodeGenerator/IOCCodeGenerator.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | bin\$(Configuration)\ 6 | netstandard2.0 7 | preview 8 | true 9 | true 10 | UPPERIOC.Generators 11 | true 12 | enable 13 | true 14 | true 15 | true 16 | 17 | $(DefineConstants);ROSLYN_4 18 | 19 | 20 | 21 | True 22 | latest 23 | True 24 | MIT 25 | 26 | True 27 | latest 28 | True 29 | MIT 30 | zh-Hans 31 | True 32 | UPPERIOC的生成器组件 33 | 34 | True 35 | 36 | 37 | true 38 | true 39 | IOCG 40 | 1.0.0.21 41 | IOCG 42 | www 43 | True 44 | snupkg 45 | UPPERIOC.png 46 | README.md 47 | git 48 | Wwwwww 49 | True 50 | zh 51 | https://github.com/mrwangshipei/UPPERIOC 52 | https://github.com/mrwangshipei/UPPERIOC 53 | iocg 54 | 发布版本 55 | 1.0.0.1 56 | IOCCodeGenerator 57 | netstandard2.0 58 | C:\Program Files (x86)\Microsoft SDKs\NuGetPackages 59 | OnOutputUpdated 60 | 61 | 62 | 63 | 64 | False 65 | 66 | 67 | 68 | 69 | 70 | True 71 | \ 72 | 73 | 74 | True 75 | \ 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UPPERIOC 2 | 3 | UPPERIOC 是一款专为 **WinForms** 和 **WPF** 上位机项目设计的轻量级 **IOC**(控制反转)插件系统,旨在简化模块化设计,提升系统解耦度,支持依赖注入、插件动态加载、事件总线等功能,适用于工业控制、数据采集、设备通信等领域。 4 | 5 | --- 6 | 7 |

8 | 9 | 10 | 11 | 12 | 13 | GitHub 14 | 15 | GitHub last commit 16 | GitHub Repo stars 17 |

18 | 19 | --- 20 | 21 | ## 目录 22 | 23 | - [项目简介](#项目简介) 24 | - [功能亮点](#功能亮点) 25 | - [快速开始](#快速开始) 26 | - [系统架构](#系统架构) 27 | - [插件开发](#插件开发) 28 | - [示例项目](#示例项目) 29 | - [常见问题](#常见问题) 30 | - [许可证](#许可证) 31 | 32 | ## 项目简介 33 | 34 | UPPERIOC 旨在通过依赖注入、插件扩展等机制,使得上位机系统的模块化开发更加高效和灵活。通过实现 **插件化** 架构,你可以动态加载、卸载和更新系统中的功能模块,而无需修改主程序代码,从而提高系统的可维护性和扩展性。 35 | 36 | ## 功能亮点 37 | 38 | - **IOC 容器**:自动管理对象的生命周期和依赖关系,实现模块之间的解耦。 39 | - **插件系统**:支持动态加载和卸载插件,模块功能可以按需扩展。 40 | - **事件总线**:模块之间的通信通过事件机制实现,不直接依赖。 41 | - **注入机制**:支持通过属性注入和构造函数注入依赖对象。 42 | 43 | ## 快速开始 44 | 45 | ### 安装 46 | 47 | 首先,您需要通过 NuGet 安装 UPPERIOC: 48 | 49 | ```bash 50 | dotnet add package UPPERIOC 51 | ``` 52 | 53 | ### 基本用法 54 | 55 | 0. **容器的初始化:** 56 | 57 | 在上位机的Program.cs,窗体打开之前使用如下代码初始化: 58 | ```csharp 59 | UpperIocApplication.RunInstance(md=>{}); 60 | ``` 61 | 62 | 1. **注册依赖:** 63 | 64 | ```csharp 65 | U.C.Register(); 66 | // or 67 | MainForm m = new(); 68 | U.C.Register(m); 69 | ``` 70 | 71 | 2. **注入依赖:** 72 | 73 | ```csharp 74 | var f = U.C.GetInstance(); 75 | public class MainForm 76 | { 77 | [IOCProperties] 78 | public IMyService MyService { get; set; } 79 | 80 | public MainForm() 81 | { 82 | // 使用 MyService 83 | } 84 | } 85 | ``` 86 | 87 | 3. **插件加载:** 88 | 89 | ```csharp 90 | UpperIocApplication.RunInstance(md=>{ 91 | md.AddModule(); 92 | }); 93 | ``` 94 | 95 | 4. **发布事件:** 96 | 97 | ```csharp 98 | U.E.Publish(); 99 | ``` 100 | 101 | ## 系统架构 102 | 103 | 系统架构通过 **IOC 容器**、**插件加载器** 和 **事件总线** 实现解耦。各模块之间的交互通过注入和事件驱动进行。 104 | 105 | ### 架构图 106 | 107 | ```plaintext 108 | 109 | ## 1. 事件系统加载 110 | - 加载事件系统 111 | - 推送事件 "事件加载成功" 112 | 113 | ## 2. 日志中心加载 114 | - 加载日志中心 115 | - 推送事件 "日志中心加载成功" 116 | 117 | ## 3. IOC 和插件生命周期混合加载 118 | - 初始化 IOC 容器 119 | - 插件加载开始 120 | - 插件初始化 121 | - 插件生命周期事件推送 122 | - IOC 生命周期事件推送 123 | 124 | ## 4. 生命周期事件推送 125 | - 推送插件初始化成功事件 126 | - 推送 IOC 容器初始化成功事件 127 | 128 | ## 5. 注册软件退出事件 129 | - 注册容器注销前事件 130 | - 注册容器注销后事件 131 | 132 | ## 6. 退出操作 133 | - 容器注销 134 | - 触发 "容器注销前" 事件 135 | - 触发 "容器注销后" 事件 136 | ``` 137 | 138 | ### 关键模块 139 | 140 | - **IOC 容器**:负责管理服务的注册与注入。 141 | - **插件系统**:动态加载、卸载插件。 142 | - **事件总线**:实现松散耦合。 143 | 144 | ## 插件开发 145 | 146 | UPPERIOC 提供了简洁的插件开发接口,帮助你快速构建可插拔的功能模块。 147 | 148 | ### 插件基本模板 149 | 150 | 每个插件需要实现 `IUPPERModule` 接口: 151 | 152 | ```csharp 153 | public class MyPlugin : IUPPERModule 154 | { 155 | 156 | } 157 | ``` 158 | 可以通过实现生命周期接口来注册生命周期 159 | 160 | ## 示例项目 161 | 162 | 你可以参考以下示例项目来快速上手: 163 | 164 | - **WinForms 插件示例**: [还未完成](./examples/WinformDemo/README.md) 165 | - **WPF 插件示例**: [还未完成](./examples/WpfDemo/README.md) 166 | 167 | ## 常见问题 168 | 169 | ### 1. 如何定义插件间的依赖? 170 | 171 | 可以通过 IOC 容器管理插件之间的依赖关系,确保插件按正确顺序加载。 172 | 173 | ### 2. 是否支持跨项目使用? 174 | 175 | 是的,你可以将 UPPERIOC 作为一个共享库引入到多个项目中。 176 | 177 | ## 许可证 178 | 179 | 该项目使用 [MIT 许可证](./LICENSE)。 180 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER/Moudle_/ModuleConfiguaion.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Linq; 5 | using System.Security.Permissions; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using UPPERIOC.UPPER.Event.AppEvent; 9 | using UPPERIOC.UPPER.Event.AppEvent.Impl; 10 | using UPPERIOC.UPPER.IOC.Center.IProvider; 11 | using UPPERIOC.UPPER.IOC.DefaultProvider; 12 | using UPPERIOC.UPPER.MainApplication.Log_; 13 | using UPPERIOC.UPPER.Moudle_; 14 | 15 | 16 | namespace UPPERIOC.UPPER.IOC.Center.Configuation 17 | { 18 | public class ModuleConfiguaion 19 | { 20 | private List _modules = new(); 21 | private readonly List _logs = new(); 22 | private IContainerProvider _containerProvider; 23 | private readonly object _lock = new(); 24 | private ModuleLoader loader; 25 | public ApplicationEventManager EventManager { get; private set; } 26 | 27 | public List Modules 28 | { 29 | get 30 | { 31 | loader = new ModuleLoader(_modules); 32 | _modules = loader.GetLoadOrder(); 33 | return _modules; 34 | } 35 | } 36 | public List UnLoadModules 37 | { 38 | get 39 | { 40 | loader = new ModuleLoader(_modules); 41 | _modules = loader.GetUnloadOrder(); 42 | return _modules; 43 | } 44 | } 45 | public IReadOnlyList Logs => _logs; 46 | 47 | public IContainerProvider Provider 48 | { 49 | get 50 | { 51 | if (_containerProvider == null) 52 | { 53 | lock (_lock) 54 | { 55 | if (_containerProvider == null) 56 | { 57 | _containerProvider = new UPPERDefaultProvider(); 58 | 59 | EventManager = _containerProvider.Rigister(new ApplicationEventManager()) as ApplicationEventManager; 60 | } 61 | } 62 | } 63 | return _containerProvider; 64 | } 65 | set 66 | { 67 | lock (_lock) 68 | { 69 | _containerProvider = value; 70 | EventManager = _containerProvider.Rigister(new ApplicationEventManager()) as ApplicationEventManager; 71 | } 72 | } 73 | } 74 | 75 | public void SetProvider() where T : IContainerProvider, new() 76 | { 77 | if (_containerProvider != null) 78 | { 79 | throw new Exception("SetProvider()函数必须在配置中置顶"); 80 | } 81 | Provider = new T(); 82 | } 83 | 84 | public void AddModule() where T : IUPPERModule, new() 85 | { 86 | _modules.Add(new T()); 87 | } 88 | 89 | public void AddModule(IUPPERModule module) 90 | { 91 | if (module != null) _modules.Add(module); 92 | } 93 | 94 | public void AddLogger() where T : ILog, new() 95 | { 96 | _logs.Add(new T()); 97 | } 98 | 99 | public void AddLogger(ILog log) 100 | { 101 | if (log != null) _logs.Add(log); 102 | } 103 | 104 | public static ModuleConfiguaion Configure(Action config) 105 | { 106 | var cfg = new ModuleConfiguaion(); 107 | config(cfg); 108 | return cfg; 109 | } 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /TestDemo/ModuleTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using UPPER.Test.ApplicationEventTests; 9 | using UPPERIOC; 10 | using UPPERIOC.UPPER.IOC.Center.Interface; 11 | using UPPERTest.Util; 12 | using Xunit; 13 | 14 | namespace UPPERTest 15 | { 16 | namespace Sub { 17 | public class ModuleA : IUPPERModule 18 | { 19 | public override Type[] Dependencies => new Type[] 20 | { 21 | typeof(ModuleB) 22 | }; 23 | } 24 | 25 | public class ModuleB : IUPPERModule 26 | { 27 | public override Type[] Dependencies => new Type[] 28 | { 29 | typeof(ModuleC) 30 | }; 31 | } 32 | 33 | public class ModuleC : IUPPERModule 34 | { 35 | public override Type[] Dependencies => new Type[] 36 | { 37 | typeof(ModuleA) 38 | }; 39 | } 40 | public class ModuleTests { 41 | [Fact] 42 | public void TestModuleLifecycle() 43 | { 44 | FileTempFile f = new FileTempFile(); 45 | var assemblyPath = typeof(ProgramML).Assembly.Location; 46 | assemblyPath = assemblyPath.Replace(".dll", ".exe"); 47 | //传入f._tempFile到程序中应该如何传; 48 | var process = Process.Start(new ProcessStartInfo 49 | { 50 | FileName = assemblyPath, 51 | Arguments = $"\"{f._tempFile}\"", 52 | RedirectStandardOutput = true, 53 | UseShellExecute = false, 54 | CreateNoWindow = true 55 | }); 56 | 57 | process.WaitForExit(); 58 | 59 | Assert.True(File.Exists(f._tempFile), "ProcessExit 未触发或未生成文件"); 60 | Assert.Equal(File.ReadAllText(f._tempFile), "ok"); 61 | } 62 | [Fact] 63 | public void DetectsTripleCircularDependency() 64 | { 65 | string exm = ""; 66 | try 67 | { 68 | UPPERIOCApplication.RunInstance(md => { 69 | md.AddModule(); 70 | md.AddModule(); 71 | md.AddModule(); 72 | }); 73 | } 74 | catch (Exception ex) 75 | { 76 | exm = ex.Message; 77 | } 78 | Assert.Contains("存在循环依赖", exm); 79 | } 80 | } 81 | } 82 | public class ModuleTests 83 | { 84 | public class ModuleA : IUPPERModule 85 | { 86 | public override Type[] Dependencies => new Type[] 87 | { 88 | typeof(ModuleB) 89 | }; 90 | } 91 | 92 | public class ModuleB : IUPPERModule 93 | { 94 | public override Type[] Dependencies => new Type[] 95 | { 96 | typeof(ModuleA) 97 | }; 98 | } 99 | 100 | [Fact] 101 | public void DetectsCircularDependency() { 102 | string exm = ""; 103 | try 104 | { 105 | UPPERIOCApplication.RunInstance(md => { 106 | md.AddModule(); 107 | md.AddModule(); 108 | }); 109 | } 110 | catch (Exception ex) 111 | { 112 | exm = ex.Message; 113 | } 114 | Assert.Contains("存在循环依赖", exm); 115 | } 116 | 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Upperioc Code of Conduct 2 | 3 | Like the technical community as a whole, the Upperioc team and community is made up of a mixture of professionals and volunteers from all over the world, working on every aspect of the mission - including mentorship, teaching, and connecting people. 4 | 5 | Diversity is one of our huge strengths, but it can also lead to communication issues and unhappiness. To that end, we have a few ground rules that we ask people to adhere to. This code applies equally to founders, mentors and those seeking help and guidance. 6 | 7 | This isn’t an exhaustive list of things that you can’t do. Rather, take it in the spirit in which it’s intended - a guide to make it easier to enrich all of us and the technical communities in which we participate. 8 | 9 | This code of conduct applies to all spaces managed by the Upperioc project or ZhaoCai. This includes IRC, the mailing lists, the issue tracker, DSF events, and any other forums created by the project team which the community uses for communication. In addition, violations of this code outside these spaces may affect a person's ability to participate within them. 10 | 11 | If you believe someone is violating the code of conduct, we ask that you report it by emailing [wsp001112@gmail.com](mailto:wsp001112@gmail.com). For more details please see our 12 | 13 | - **Be friendly and patient.** 14 | - **Be welcoming.** We strive to be a community that welcomes and supports people of all backgrounds and identities. This includes, but is not limited to members of any race, ethnicity, culture, national origin, colour, immigration status, social and economic class, educational level, sex, sexual orientation, gender identity and expression, age, size, family status, political belief, religion, and mental and physical ability. 15 | - **Be considerate.** Your work will be used by other people, and you in turn will depend on the work of others. Any decision you take will affect users and colleagues, and you should take those consequences into account when making decisions. Remember that we're a world-wide community, so you might not be communicating in someone else's primary language. 16 | - **Be respectful.** Not all of us will agree all the time, but disagreement is no excuse for poor behavior and poor manners. We might all experience some frustration now and then, but we cannot allow that frustration to turn into a personal attack. It’s important to remember that a community where people feel uncomfortable or threatened is not a productive one. Members of the Upperioc community should be respectful when dealing with other members as well as with people outside the Upperioc community. 17 | - **Be careful in the words that you choose.** We are a community of professionals, and we conduct ourselves professionally. Be kind to others. Do not insult or put down other participants. Harassment and other exclusionary behavior aren't acceptable. This includes, but is not limited to: 18 | - Violent threats or language directed against another person. 19 | - Discriminatory jokes and language. 20 | - Posting sexually explicit or violent material. 21 | - Posting (or threatening to post) other people's personally identifying information ("doxing"). 22 | - Personal insults, especially those using racist or sexist terms. 23 | - Unwelcome sexual attention. 24 | - Advocating for, or encouraging, any of the above behavior. 25 | - Repeated harassment of others. In general, if someone asks you to stop, then stop. 26 | - **When we disagree, try to understand why.** Disagreements, both social and technical, happen all the time and Upperioc is no exception. It is important that we resolve disagreements and differing views constructively. Remember that we’re different. The strength of Upperioc comes from its varied community, people from a wide range of backgrounds. Different people have different perspectives on issues. Being unable to understand why someone holds a viewpoint doesn’t mean that they’re wrong. Don’t forget that it is human to err and blaming each other doesn’t get us anywhere. Instead, focus on helping to resolve issues and learning from mistakes. 27 | 28 | Original text courtesy of the [Speak Up! project](http://web.archive.org/web/20141109123859/http://speakup.io/coc.html). 29 | 30 | ## Questions? 31 | 32 | If you have questions, please see . If that doesn't answer your questions, feel free to [contact us](mailto:wsp001112@gmail.com). 33 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER.Translate/Center/TranslateCenter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.ComponentModel; 5 | using System.Drawing; 6 | using System.Globalization; 7 | using System.Linq; 8 | using System.Security.Principal; 9 | using System.Text; 10 | using System.Threading.Tasks; 11 | using System.Windows.Forms; 12 | using UPPERIOC.UPPER.IOC.Center.IProvider; 13 | using UPPERIOC2.UPPER.Translate.Model; 14 | using UPPERIOC2.UPPER.UFileModel.Center; 15 | using UPPERIOC2.UPPER.Util; 16 | using static System.Net.Mime.MediaTypeNames; 17 | 18 | namespace UPPERIOC2.UPPER.Translate.Center 19 | { 20 | public class TranslateCenter 21 | { 22 | public static TranslateCenter Instance { get; set; } = new TranslateCenter(); 23 | internal TranslateModel TranslateModel; 24 | internal Translateblock TranslateBlock; 25 | internal IContainerProvider ipd; 26 | internal string L; 27 | List root = new List(25); 28 | List Ignore= new List(25); 29 | internal TranslateCenter(IContainerProvider ipd) { 30 | 31 | this.ipd = ipd; 32 | } 33 | internal TranslateCenter() 34 | { 35 | 36 | } 37 | public void SetRootWindows(Component com) { 38 | if (ipd == null) 39 | { 40 | return; 41 | } 42 | if (com is MenuStrip mt) { 43 | foreach (Component c in mt.Items) { 44 | 45 | SetRootWindows(c); 46 | } 47 | mt.Text = GetText(mt.Text); 48 | 49 | } 50 | else if (com is ToolStrip it) 51 | { 52 | foreach (ToolStripItem item in it.Items) 53 | { 54 | SetRootWindows(item); 55 | } 56 | it.Text = GetText(it.Text); 57 | 58 | }else if (com is ToolStripItem ita) 59 | { 60 | ita.Text = GetText(ita.Text); 61 | 62 | } 63 | else if (com is Control con) 64 | { 65 | foreach (Control item in con.Controls) 66 | { 67 | SetRootWindows(item); 68 | } 69 | con.Text = GetText(con.Text); 70 | } 71 | 72 | /* con.ControlAdded -= SetControlAdd; 73 | con.ControlAdded += SetControlAdd; 74 | con.TextChanged -= SetTextChange; 75 | con.TextChanged += SetTextChange;*/ 76 | } 77 | internal void SetLanguage(string lan) 78 | { 79 | L = lan; 80 | if (null == TranslateModel) 81 | { 82 | TranslateModel =F.I.GetModel(new TranslateModel()); 83 | } 84 | if (null != TranslateModel) 85 | { 86 | TranslateBlock = TranslateModel.Translateblocks.Find(x=> x.Name == lan); 87 | if (TranslateBlock == null) 88 | { 89 | TranslateBlock = new Translateblock(); 90 | TranslateBlock.Name = lan; 91 | TranslateModel.Translateblocks.Add(TranslateBlock); 92 | } 93 | } 94 | } 95 | public void SetIgnoreCon(Control con) 96 | { 97 | Ignore.Add(con); 98 | } 99 | private void SetControlAdd(object sender, ControlEventArgs e) 100 | { 101 | 102 | if (Ignore.Contains(e.Control)) 103 | { 104 | return; 105 | } 106 | e.Control.ControlAdded -= SetControlAdd; 107 | e.Control.ControlAdded += SetControlAdd; 108 | if (!string.IsNullOrWhiteSpace(e.Control.Text)) 109 | { 110 | e.Control.Text = GetText(e.Control.Text); 111 | 112 | } 113 | 114 | e.Control.TextChanged -= SetTextChange; 115 | e.Control.TextChanged += SetTextChange; 116 | 117 | } 118 | 119 | private void SetTextChange(object sender, EventArgs e) 120 | { 121 | Control con = sender as Control; 122 | if (!string.IsNullOrWhiteSpace(con.Text) && con.Text != GetText(con.Text)) 123 | { 124 | con.TextChanged -= SetTextChange; 125 | con.Text = GetText(con.Text); 126 | con.TextChanged += SetTextChange; 127 | } 128 | } 129 | 130 | public string GetText(string text) 131 | { 132 | if (ipd == null) 133 | { 134 | return text; 135 | } 136 | if (string.IsNullOrWhiteSpace(text)) 137 | { 138 | return text; 139 | } 140 | 141 | var str = TranslateBlock.Values.Find(x => x.Key == text && !string.IsNullOrWhiteSpace(x.Value)).Value; 142 | if (string.IsNullOrWhiteSpace(str)) 143 | { 144 | str = TranslateUtil.Transcale(text); 145 | if (string.IsNullOrWhiteSpace(str)) 146 | { 147 | str = text; 148 | } 149 | TranslateBlock.Values.Add(new KeyValue(text,str)); 150 | F.I.SaveModel(TranslateModel); 151 | } 152 | if (string.IsNullOrWhiteSpace(str)) 153 | { 154 | return text; 155 | } 156 | return str; 157 | } 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /UPPERIOC/Util/HashHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Management; 4 | using System.Security.Cryptography; 5 | using System.Text; 6 | using System.Windows.Forms; 7 | using System.Runtime.InteropServices; 8 | using UPPERIOC.UPPER; 9 | namespace UPPERIOC2.UPPER.Util 10 | { 11 | public class HashHelper 12 | { 13 | public static string EncryptWithSalt(string salt,string machineCode = "") 14 | { 15 | if (string.IsNullOrWhiteSpace(machineCode)) 16 | { 17 | machineCode = GenerateMachineId(); 18 | 19 | } 20 | using (var sha256 = SHA256.Create()) 21 | { 22 | var saltedMachineCode = Encoding.UTF8.GetBytes($"{machineCode}{salt}"); 23 | var hash = sha256.ComputeHash(saltedMachineCode); 24 | 25 | // 将哈希值转换为十六进制字符串 26 | var hashString = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); 27 | 28 | return hashString; 29 | } 30 | } 31 | internal static bool VerifyWithSalt(string salt, string storedHash) 32 | { 33 | //string machineCode = GenerateMachineId(); 34 | 35 | var computedHash = EncryptWithSalt(salt); 36 | return computedHash == storedHash; 37 | } 38 | static string GenerateMachineId() 39 | { 40 | // 获取多个系统属性以生成唯一标识符 41 | string cpuId = GetCpuId(); 42 | string biosId = GetBiosId(); 43 | string baseBoardId = GetBaseBoardId(); 44 | 45 | // 将所有属性合并成一个字符串 46 | string combinedId = $"{cpuId}{biosId}{baseBoardId}"; 47 | 48 | // 使用SHA256哈希算法对合并后的字符串进行哈希处理 49 | using (SHA256 sha256Hash = SHA256.Create()) 50 | { 51 | byte[] data = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(combinedId)); 52 | 53 | // 将哈希值转换为十六进制字符串 54 | StringBuilder sBuilder = new StringBuilder(); 55 | 56 | for (int i = 0; i < data.Length; i++) 57 | { 58 | sBuilder.Append(data[i].ToString("x2")); 59 | } 60 | 61 | return sBuilder.ToString(); 62 | } 63 | } 64 | [ComVisible(true)] 65 | private static string GetCpuId() 66 | { 67 | string cpuInfo = string.Empty; 68 | try 69 | { 70 | string s = "SELECT ProcessorId FROM Win32_Processor"; 71 | ManagementObjectSearcher searcher = new ManagementObjectSearcher(s); 72 | 73 | foreach (ManagementObject mo in searcher.Get()) 74 | { 75 | cpuInfo = (string)mo["ProcessorId"]; 76 | break; // 通常只需要第一个CPU的ID 77 | } 78 | 79 | } 80 | catch (ManagementException ex) 81 | { 82 | LogCenter.Log(UPPERIOC.UPPER.enums.LogType.Error,"WMI 查询失败!"); 83 | LogCenter.Log(UPPERIOC.UPPER.enums.LogType.Error, "错误消息: " + ex.Message); 84 | LogCenter.Log(UPPERIOC.UPPER.enums.LogType.Error, "错误代码: " + ex.ErrorCode); 85 | if (ex.InnerException != null) 86 | { 87 | LogCenter.Log(UPPERIOC.UPPER.enums.LogType.Error, "内部异常: " + ex.InnerException.Message); 88 | } 89 | cpuInfo = "UnKnowCpuInfo"; 90 | 91 | } 92 | 93 | 94 | return cpuInfo; 95 | } 96 | [ComVisible(true)] 97 | 98 | private static string GetBiosId() 99 | { 100 | string biosId = string.Empty; 101 | 102 | ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT SerialNumber,SMBIOSBIOSVersion FROM Win32_BIOS"); 103 | try 104 | { 105 | foreach (ManagementObject mo in searcher.Get()) 106 | { 107 | biosId = (string)mo["SerialNumber"]; 108 | if (!string.IsNullOrEmpty(biosId)) break; // 如果SerialNumber为空,则尝试其他属性 109 | biosId = (string)mo["SMBIOSBIOSVersion"]; 110 | break; 111 | } 112 | 113 | } 114 | catch (Exception) 115 | { 116 | biosId = "UnknowBiosId"; 117 | } 118 | 119 | return biosId; 120 | } 121 | [ComVisible(true)] 122 | 123 | private static string GetBaseBoardId() 124 | { 125 | string baseBoardId = string.Empty; 126 | try 127 | { 128 | ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT SerialNumber FROM Win32_BaseBoard"); 129 | 130 | foreach (ManagementObject mo in searcher.Get()) 131 | { 132 | baseBoardId = (string)mo["SerialNumber"]; 133 | if (!string.IsNullOrEmpty(baseBoardId)) break; // 如果SerialNumber为空,则可能没有其他合适的属性 134 | } 135 | 136 | 137 | } 138 | catch (Exception) 139 | { 140 | baseBoardId = "UnKnowBaseBoardIdid"; 141 | 142 | } 143 | return baseBoardId; 144 | } 145 | 146 | internal static bool VerifyWithSalt(string solt, object value) 147 | { 148 | throw new NotImplementedException(); 149 | } 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /UPPERIOC.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.9.34723.18 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UPPER.Test", "TestDemo\UPPER.Test.csproj", "{91BD652E-C624-4F1B-B500-C5816A440579}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IOCCodeGenerator", "IOCCodeGenerator\IOCCodeGenerator.csproj", "{58037466-8377-498F-BB03-CBA62AF571FC}" 9 | EndProject 10 | Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "UPPER.Shared", "UPPER.Shared\UPPER.Shared.shproj", "{CF82D5A3-E4E9-447B-8EB3-6200954CFE4E}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UPPERIOC", "UPPERIOC\UPPERIOC.csproj", "{7BC98436-8116-4547-A174-9D0AC126A3CC}" 13 | EndProject 14 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Test", "Test", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}" 15 | EndProject 16 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestProgrem", "TestProgrem", "{2C8ECB36-0D14-46F1-9EAF-6B3C50E3E1D6}" 17 | EndProject 18 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UPPER.Test.ApplicationEventTests", "UPPER.Test.ApplicationEventTests\UPPER.Test.ApplicationEventTests.csproj", "{90875408-4071-413E-AEF7-D1607F03A6B0}" 19 | EndProject 20 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UPPER.Test.MoudleLifecycle", "UPPER.Test.MoudleLifecycle\UPPER.Test.MoudleLifecycle.csproj", "{D22F4CD3-7B98-4E4E-81DE-9A54C983D576}" 21 | EndProject 22 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UPPER.TestTests", "UPPER.TestTests\UPPER.TestTests.csproj", "{ABA2D77D-B97B-4F5A-BE05-E734420D3F9B}" 23 | EndProject 24 | Global 25 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 26 | Debug|Any CPU = Debug|Any CPU 27 | Release|Any CPU = Release|Any CPU 28 | EndGlobalSection 29 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 30 | {91BD652E-C624-4F1B-B500-C5816A440579}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 31 | {91BD652E-C624-4F1B-B500-C5816A440579}.Debug|Any CPU.Build.0 = Debug|Any CPU 32 | {91BD652E-C624-4F1B-B500-C5816A440579}.Release|Any CPU.ActiveCfg = Release|Any CPU 33 | {91BD652E-C624-4F1B-B500-C5816A440579}.Release|Any CPU.Build.0 = Release|Any CPU 34 | {58037466-8377-498F-BB03-CBA62AF571FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 35 | {58037466-8377-498F-BB03-CBA62AF571FC}.Debug|Any CPU.Build.0 = Debug|Any CPU 36 | {58037466-8377-498F-BB03-CBA62AF571FC}.Release|Any CPU.ActiveCfg = Release|Any CPU 37 | {58037466-8377-498F-BB03-CBA62AF571FC}.Release|Any CPU.Build.0 = Release|Any CPU 38 | {7BC98436-8116-4547-A174-9D0AC126A3CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 39 | {7BC98436-8116-4547-A174-9D0AC126A3CC}.Debug|Any CPU.Build.0 = Debug|Any CPU 40 | {7BC98436-8116-4547-A174-9D0AC126A3CC}.Release|Any CPU.ActiveCfg = Release|Any CPU 41 | {7BC98436-8116-4547-A174-9D0AC126A3CC}.Release|Any CPU.Build.0 = Release|Any CPU 42 | {90875408-4071-413E-AEF7-D1607F03A6B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 43 | {90875408-4071-413E-AEF7-D1607F03A6B0}.Debug|Any CPU.Build.0 = Debug|Any CPU 44 | {90875408-4071-413E-AEF7-D1607F03A6B0}.Release|Any CPU.ActiveCfg = Release|Any CPU 45 | {90875408-4071-413E-AEF7-D1607F03A6B0}.Release|Any CPU.Build.0 = Release|Any CPU 46 | {D22F4CD3-7B98-4E4E-81DE-9A54C983D576}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 47 | {D22F4CD3-7B98-4E4E-81DE-9A54C983D576}.Debug|Any CPU.Build.0 = Debug|Any CPU 48 | {D22F4CD3-7B98-4E4E-81DE-9A54C983D576}.Release|Any CPU.ActiveCfg = Release|Any CPU 49 | {D22F4CD3-7B98-4E4E-81DE-9A54C983D576}.Release|Any CPU.Build.0 = Release|Any CPU 50 | {ABA2D77D-B97B-4F5A-BE05-E734420D3F9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 51 | {ABA2D77D-B97B-4F5A-BE05-E734420D3F9B}.Debug|Any CPU.Build.0 = Debug|Any CPU 52 | {ABA2D77D-B97B-4F5A-BE05-E734420D3F9B}.Release|Any CPU.ActiveCfg = Release|Any CPU 53 | {ABA2D77D-B97B-4F5A-BE05-E734420D3F9B}.Release|Any CPU.Build.0 = Release|Any CPU 54 | EndGlobalSection 55 | GlobalSection(SolutionProperties) = preSolution 56 | HideSolutionNode = FALSE 57 | EndGlobalSection 58 | GlobalSection(NestedProjects) = preSolution 59 | {91BD652E-C624-4F1B-B500-C5816A440579} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8} 60 | {2C8ECB36-0D14-46F1-9EAF-6B3C50E3E1D6} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8} 61 | {90875408-4071-413E-AEF7-D1607F03A6B0} = {2C8ECB36-0D14-46F1-9EAF-6B3C50E3E1D6} 62 | {D22F4CD3-7B98-4E4E-81DE-9A54C983D576} = {2C8ECB36-0D14-46F1-9EAF-6B3C50E3E1D6} 63 | EndGlobalSection 64 | GlobalSection(ExtensibilityGlobals) = postSolution 65 | SolutionGuid = {222FD9B0-85B4-43F1-B03B-A85920FDCC8F} 66 | EndGlobalSection 67 | GlobalSection(SharedMSBuildProjectFiles) = preSolution 68 | UPPER.Shared\UPPER.Shared.projitems*{58037466-8377-498f-bb03-cba62af571fc}*SharedItemsImports = 5 69 | UPPER.Shared\UPPER.Shared.projitems*{cf82d5a3-e4e9-447b-8eb3-6200954cfe4e}*SharedItemsImports = 13 70 | EndGlobalSection 71 | EndGlobal 72 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER.UFileModel/Entry/DirectoryEx.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Xml; 3 | using System.Xml.Schema; 4 | using System.Xml.Serialization; 5 | 6 | namespace Kernal 7 | { 8 | #region 可序列化字典类 + public class DictionaryEx 9 | /// 10 | /// 可序列化字典类 11 | /// 12 | /// 键泛型 13 | /// 值泛型 14 | [System.Serializable] 15 | public class DictionaryEx 16 | : Dictionary, IXmlSerializable 17 | { 18 | #region 构造函数 19 | 20 | #region 默认构造函数 + public DictionaryEx() 21 | /// 22 | /// 默认构造函数 23 | /// 24 | public DictionaryEx() 25 | : base() 26 | { 27 | 28 | } 29 | #endregion 30 | 31 | #region 构造函数 + public DictionaryEx(int capacity) 32 | /// 33 | /// 构造函数 34 | /// 35 | /// 可包含的初始元素数 36 | public DictionaryEx(int capacity) 37 | : base(capacity) 38 | { 39 | 40 | } 41 | #endregion 42 | 43 | #region 构造函数 + public DictionaryEx(IEqualityComparer comparer) 44 | /// 45 | /// 构造函数 46 | /// 47 | /// 比较键时要使用的 比较器 实现,或者为 null,以便为键类型使用默认的 比较器 48 | public DictionaryEx(IEqualityComparer comparer) 49 | : base(comparer) 50 | { 51 | 52 | } 53 | #endregion 54 | 55 | #region 构造函数 + public DictionaryEx(IDictionary dictionary) 56 | /// 57 | /// 构造函数 58 | /// 59 | /// 初始数据 60 | public DictionaryEx(IDictionary dictionary) 61 | : base(dictionary) 62 | { 63 | 64 | } 65 | #endregion 66 | 67 | #region 构造函数 + public DictionaryEx(int capacity, IEqualityComparer comparer) 68 | /// 69 | /// 构造函数 70 | /// 71 | /// 可包含的初始元素数 72 | /// 比较键时要使用的 比较器 实现,或者为 null,以便为键类型使用默认的 比较器 73 | public DictionaryEx(int capacity, IEqualityComparer comparer) 74 | : base(capacity, comparer) 75 | { 76 | 77 | } 78 | #endregion 79 | 80 | #region 构造函数 + public DictionaryEx(IDictionary dictionary, IEqualityComparer comparer) 81 | /// 82 | /// 构造函数 83 | /// 84 | /// 初始数据 85 | /// 比较键时要使用的 比较器 实现,或者为 null,以便为键类型使用默认的 比较器 86 | public DictionaryEx(IDictionary dictionary, IEqualityComparer comparer) 87 | : base(dictionary, comparer) 88 | { 89 | 90 | } 91 | #endregion 92 | 93 | #endregion 94 | 95 | #region 取得概要 + public XmlSchema GetSchema() 96 | /// 97 | /// 取得概要 98 | /// 注:根据MSDN的文档,此方法为保留方法,一定返回 null。 99 | /// 100 | /// Xml概要 101 | public XmlSchema GetSchema() 102 | { 103 | return null; 104 | } 105 | #endregion 106 | 107 | #region 从 XML 对象中反序列化生成本对象 + public void ReadXml(XmlReader reader) 108 | /// 109 | /// 从 XML 对象中反序列化生成本对象 110 | /// 111 | /// 包含反序列化对象的 XmlReader 流 112 | public void ReadXml(XmlReader reader) 113 | { 114 | XmlSerializer keySerializer = new XmlSerializer(typeof(TKey)); 115 | XmlSerializer valueSerializer = new XmlSerializer(typeof(TValue)); 116 | bool wasEmpty = reader.IsEmptyElement; 117 | reader.Read(); 118 | if (wasEmpty) return; 119 | 120 | while (reader.NodeType != XmlNodeType.EndElement) 121 | { 122 | reader.ReadStartElement("Item"); 123 | reader.ReadStartElement("Key"); 124 | TKey key = (TKey)keySerializer.Deserialize(reader); 125 | reader.ReadEndElement(); 126 | reader.ReadStartElement("Value"); 127 | TValue value = (TValue)valueSerializer.Deserialize(reader); 128 | reader.ReadEndElement(); 129 | this.Add(key, value); 130 | reader.ReadEndElement(); 131 | reader.MoveToContent(); 132 | } 133 | 134 | reader.ReadEndElement(); 135 | } 136 | #endregion 137 | 138 | #region 将本对象序列化为 XML 对象 + public void WriteXml(XmlWriter writer) 139 | /// 140 | /// 将本对象序列化为 XML 对象 141 | /// 142 | /// 待写入的 XmlWriter 对象 143 | public void WriteXml(XmlWriter writer) 144 | { 145 | XmlSerializer keySerializer = new XmlSerializer(typeof(TKey)); 146 | XmlSerializer valueSerializer = new XmlSerializer(typeof(TValue)); 147 | foreach (TKey key in this.Keys) 148 | { 149 | writer.WriteStartElement("Item"); 150 | writer.WriteStartElement("Key"); 151 | keySerializer.Serialize(writer, key); 152 | writer.WriteEndElement(); 153 | writer.WriteStartElement("Value"); 154 | TValue value = this[key]; 155 | valueSerializer.Serialize(writer, value); 156 | writer.WriteEndElement(); 157 | writer.WriteEndElement(); 158 | } 159 | } 160 | #endregion 161 | } 162 | #endregion 163 | } -------------------------------------------------------------------------------- /UPPERIOC/UPPER/IOC/Moudle/UPPERIOCModule.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Runtime.InteropServices; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using UPPERIOC.UPPER.Event.AppEvent; 9 | using UPPERIOC.UPPER.Event.AppEvent.Impl; 10 | using UPPERIOC.UPPER.IOC.Annaiation; 11 | using UPPERIOC.UPPER.IOC.Center.IProvider; 12 | using UPPERIOC.UPPER.IOC.Extend; 13 | using UPPERIOC.UPPER.Moudle_; 14 | using UPPERIOC2.UPPER.UIOC.Center; 15 | 16 | namespace UPPERIOC.UPPER.IOC.Moudle 17 | { 18 | public class UPPERIOCModule : IUPPERModule, IModulePostConstruction, IModuleInitialization, IModulePostInitialization, IModulePreInitialization 19 | { 20 | ApplicationEventManager ma; 21 | IContainerProvider containerProvider; 22 | 23 | public override Type[] Dependencies { get; } = new Type[0]; 24 | 25 | 26 | public void OnPostConstruct(IContainerProvider containerProvider) 27 | { 28 | 29 | } 30 | 31 | public void OnPreInitialize(IContainerProvider containerProvider) 32 | { 33 | 34 | } 35 | 36 | public void OnPostInitialize(IContainerProvider containerProvider) 37 | { 38 | 39 | } 40 | public void OnInitialize(IContainerProvider containerProvider) 41 | { 42 | 43 | 44 | this.containerProvider = containerProvider; 45 | U.C = containerProvider; 46 | try 47 | { 48 | 49 | var mainAssembly = GetAllReferencedAssemblies(Assembly.GetEntryAssembly()) 50 | .FindAll(assembly => { 51 | try 52 | { 53 | return assembly.GetTypes().Any(type => type.Name == "IOCGeneratedRegistration"); 54 | 55 | } 56 | catch (Exception ex ) 57 | { 58 | return false; 59 | } 60 | } 61 | ); 62 | 63 | if (mainAssembly != null) 64 | { 65 | foreach (var item in mainAssembly) 66 | { 67 | var type = item.GetType("UPPER.Generated.IOCGeneratedRegistration"); 68 | var method = type?.GetMethod("RegisterAll", BindingFlags.Public | BindingFlags.Static); 69 | if (method != null) 70 | { 71 | try 72 | { 73 | 74 | method?.Invoke(null, new object[] { containerProvider }); // 调用静态方法 75 | Console.WriteLine("RegisterAll invoked successfully."); 76 | } 77 | catch (Exception ee) 78 | { 79 | LogCenter.Log(enums.LogType.Error,"RegisterAll Error:" + ee.Message + ee.StackTrace); 80 | 81 | Console.WriteLine("RegisterAll Error:" + ee.Message + ee.StackTrace); 82 | } 83 | } 84 | 85 | } 86 | 87 | } 88 | Console.WriteLine($"Error invoking Fail"); 89 | 90 | } 91 | catch (Exception ex) 92 | { 93 | Console.WriteLine($"Error invoking RegisterAll: {ex}"); 94 | } 95 | } 96 | public static List GetAllReferencedAssemblies(Assembly assembly) 97 | { 98 | var referencedAssemblies = new HashSet(); 99 | var queue = new Queue(); 100 | queue.Enqueue(assembly); 101 | 102 | while (queue.Count > 0) 103 | { 104 | var currentAssembly = queue.Dequeue(); 105 | if (!referencedAssemblies.Contains(currentAssembly)) 106 | { 107 | referencedAssemblies.Add(currentAssembly); 108 | foreach (var reference in currentAssembly.GetReferencedAssemblies()) 109 | { 110 | try 111 | { 112 | var referencedAssembly = Assembly.Load(reference); 113 | if (!referencedAssemblies.Contains(referencedAssembly)) 114 | { 115 | queue.Enqueue(referencedAssembly); 116 | } 117 | } 118 | catch (Exception ex) 119 | { 120 | // 忽略找不到的程序集 121 | } 122 | } 123 | } 124 | } 125 | 126 | return referencedAssemblies.ToList(); 127 | } 128 | 129 | 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /UPPERIOC/Util/RegisterHelper.cs: -------------------------------------------------------------------------------- 1 | namespace UPPERIOC2.UPPER.Util 2 | { 3 | public class RegisterHelper 4 | { 5 | public static RegisterHelper Instance = new RegisterHelper(); 6 | 7 | /// 8 | /// 允许用户将自定义实现替换默认的注册表/文件操作逻辑。 9 | /// 10 | public static void SetRegisterWriter(RegisterHelper instanc) 11 | { 12 | Instance = instanc; 13 | } 14 | public object _lockobj = new object(); 15 | // 读取注册表值或文件值 16 | internal virtual string GetLockFile(string keyName, string valueName) 17 | { 18 | #if NET462 19 | // 在 .NET Framework 4.6.2 下使用注册表 20 | lock (_lockobj) 21 | return ReadFromRegistry(keyName, valueName); 22 | #else 23 | // 在 .NET Standard 2.0 下,根据平台判断使用注册表或文件存储 24 | if (IsWindows() && SupportsRegistry()) 25 | { 26 | lock (_lockobj) 27 | return ReadFromRegistry(keyName, valueName); 28 | } 29 | else 30 | { 31 | lock (_lockobj) 32 | return ReadFromFile(keyName, valueName); 33 | } 34 | #endif 35 | } 36 | 37 | // 写入注册表值或文件值 38 | internal virtual void SaveLockFile(string keyName, string valueName, object value) 39 | { 40 | #if NET462 41 | // 在 .NET Framework 4.6.2 下使用注册表 42 | lock (_lockobj) 43 | WriteToRegistry(keyName, valueName, value); 44 | #else 45 | // 在 .NET Standard 2.0 下,根据平台判断使用注册表或文件存储 46 | if (IsWindows() && SupportsRegistry()) 47 | { 48 | lock (_lockobj) 49 | WriteToRegistry(keyName, valueName, value); 50 | } 51 | else 52 | { 53 | lock (_lockobj) 54 | WriteToFile(keyName, valueName, value); 55 | } 56 | #endif 57 | } 58 | 59 | internal virtual void UnloadLockFile(string keyName, string valueName) 60 | { 61 | #if NET462 62 | // 在 .NET Framework 4.6.2 下使用注册表 63 | WriteToRegistry(keyName, valueName, "nothingisthere"); 64 | #else 65 | // 在 .NET Standard 2.0 下,根据平台判断使用注册表或文件存储 66 | if (IsWindows() && SupportsRegistry()) 67 | { 68 | lock (_lockobj) 69 | WriteToRegistry(keyName, valueName, "nothingisthere"); 70 | } 71 | else 72 | { 73 | lock (_lockobj) 74 | WriteToFile(keyName, valueName, "nothingisthere"); 75 | } 76 | #endif 77 | } 78 | 79 | private string ReadFromRegistry(string keyName, string valueName) 80 | { 81 | #if NET462 || (NETSTANDARD && WINDOWS && INCLUDE_REGISTRY) 82 | 83 | #endif 84 | using (var key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(keyName)) 85 | { 86 | if (key != null) 87 | { 88 | var value = key.GetValue(valueName); 89 | if (value != null) 90 | { 91 | return value.ToString(); 92 | } 93 | } 94 | } 95 | return null; 96 | } 97 | 98 | private void WriteToRegistry(string keyName, string valueName, object value) 99 | { 100 | 101 | using (var key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(keyName)) 102 | { 103 | key.SetValue(valueName, value); 104 | } 105 | } 106 | 107 | #if !NET462 108 | private string ReadFromFile(string keyName, string valueName) 109 | { 110 | string filePath = GetFilePath(keyName, valueName); 111 | if (System.IO.File.Exists(filePath)) 112 | { 113 | return System.IO.File.ReadAllText(filePath); 114 | } 115 | return null; 116 | } 117 | 118 | private void WriteToFile(string keyName, string valueName, object value) 119 | { 120 | string filePath = GetFilePath(keyName, valueName); 121 | string directoryPath = System.IO.Path.GetDirectoryName(filePath); 122 | if (!System.IO.Directory.Exists(directoryPath)) 123 | { 124 | System.IO.Directory.CreateDirectory(directoryPath); 125 | } 126 | System.IO.File.WriteAllText(filePath, value.ToString()); 127 | } 128 | 129 | // 获取文件路径 130 | private string GetFilePath(string keyName, string valueName) 131 | { 132 | string baseDirectory = AppDomain.CurrentDomain.BaseDirectory; 133 | return System.IO.Path.Combine(baseDirectory, keyName, $"{valueName}.txt"); 134 | } 135 | 136 | // 判断是否是 Windows 平台 137 | private bool IsWindows() 138 | { 139 | return System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows); 140 | } 141 | 142 | // 判断是否支持注册表操作 143 | private bool SupportsRegistry() 144 | { 145 | return true; 146 | } 147 | #endif 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /UPPERIOC/Util/Extend/StaticExtend.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Reflection; 6 | using UPPERIOC.UPPER.IOC.MyTypeInfo; 7 | 8 | namespace UPPERIOC.UPPER.IOC.Extend 9 | { 10 | public static class StaticExtend 11 | { 12 | // 判断是否有指定特性存在于基类上 13 | public static bool HasBaseClassWithAttribute(this Type type) where TAttribute : Attribute 14 | { 15 | while (type != null && type != typeof(object)) 16 | { 17 | if (type.GetCustomAttribute() != null) 18 | return true; 19 | 20 | type = type.BaseType; 21 | } 22 | return false; 23 | } 24 | 25 | // 判断是否是单例(根据名称) 26 | public static bool? IsSingleBean(this ConcurrentDictionary dict, string typeName) 27 | { 28 | var entry = dict.FirstOrDefault(x => x.Key.TypeName == typeName); 29 | return entry.Key?.SingleBean; 30 | } 31 | 32 | // 判断是否是单例(根据类型) 33 | public static bool? IsSingleBean(this ConcurrentDictionary dict, Type type) 34 | { 35 | var entry = dict.FirstOrDefault(item => item.Key.Type.IsCompatibleWith(type)); 36 | return entry.Key?.SingleBean; 37 | } 38 | 39 | // 查找第一个满足条件的键值对 40 | public static KeyValuePair? Find(this ConcurrentDictionary dict, Func, bool> predicate) 41 | { 42 | foreach (var item in dict) 43 | { 44 | if (predicate(item)) 45 | return item; 46 | } 47 | return null; 48 | } 49 | 50 | // 获取所有符合类型的实例 51 | public static object[] GetAllInstances(this ConcurrentDictionary dict, Type type) 52 | { 53 | return dict 54 | .Where(item => item.Key.Type.IsCompatibleWith(type)) 55 | .Select(item => item.Value) 56 | .ToArray(); 57 | } 58 | 59 | // 获取实例(通过类型或名称) 60 | public static object GetInstance(this ConcurrentDictionary dict, Type type = null, string name = null, bool includeSub = false) 61 | { 62 | if (type != null) 63 | { 64 | return includeSub 65 | ? dict.FirstOrDefault(item => item.Key.Type.IsCompatibleWith(type)).Value 66 | : dict.FirstOrDefault(item => item.Key.Type == type).Value; 67 | } 68 | 69 | if (!string.IsNullOrEmpty(name)) 70 | { 71 | return dict.FirstOrDefault(item => item.Key.TypeName == name).Value; 72 | } 73 | 74 | return null; 75 | } 76 | 77 | // 类型兼容性判断(支持泛型判断) 78 | public static bool IsCompatibleWith(this Type actual, Type target) 79 | { 80 | if (actual == null || target == null) 81 | return false; 82 | 83 | if (actual == target) 84 | return true; 85 | 86 | if (actual.IsGenericType && target.IsGenericType) 87 | { 88 | if (actual.GetGenericTypeDefinition() != target.GetGenericTypeDefinition()) 89 | return false; 90 | 91 | var actualArgs = actual.GetGenericArguments(); 92 | var targetArgs = target.GetGenericArguments(); 93 | if (actualArgs.Length != targetArgs.Length) 94 | return false; 95 | 96 | for (int i = 0; i < actualArgs.Length; i++) 97 | { 98 | if (actualArgs[i] != targetArgs[i]) 99 | return false; 100 | } 101 | 102 | return true; 103 | } 104 | 105 | return target.IsAssignableFrom(actual); 106 | } 107 | 108 | // 判断一个类型是否处于另一个类型的继承链中 109 | public static bool IsInBaseTypeHierarchy(this Type type, Type baseType) 110 | { 111 | if (baseType == null || (!baseType.IsClass && !baseType.IsInterface)) 112 | return false; 113 | 114 | if (type == baseType) 115 | return true; 116 | 117 | var current = type.BaseType; 118 | while (current != null) 119 | { 120 | if (current == baseType) 121 | return true; 122 | current = current.BaseType; 123 | } 124 | 125 | return baseType.IsInterface && type.GetInterfaces().Contains(baseType); 126 | } 127 | 128 | // 自定义 FirstOrDefault 带默认值 129 | public static KeyValuePair FirstOrDefaultOr(this IEnumerable> source, Func, bool> predicate, KeyValuePair defaultValue) 130 | { 131 | foreach (var item in source) 132 | { 133 | if (predicate(item)) 134 | return item; 135 | } 136 | return defaultValue; 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /UPPERIOC/UPPERIOC.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UPPERIOC 6 | preview 7 | 8 | True 9 | net462;netstandard2.0 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 2.0.4.62 29 | UPPERIOC 30 | Wwwwww 31 | 一个自带插件的IOC容器 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | true 43 | analyzers\dotnet\roslyn3.8\cs 44 | 45 | 46 | 47 | 48 | 49 | true 50 | analyzers\dotnet\roslyn3.8\cs 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | true 68 | true 69 | True 70 | MIT 71 | True 72 | latest 73 | enable 74 | C:\Program Files (x86)\Microsoft SDKs\NuGetPackages 75 | UPPERIOC 76 | True 77 | true 78 | snupkg 79 | README.md 80 | False 81 | https://gitee.com/laowangm_m/upper-com-auto-test 82 | UPPERIOC.png 83 | https://gitee.com/laowangm_m/upper-com-auto-test 84 | gitee 85 | ioc 86 | 初始版本 87 | enable 88 | False 89 | 2.0.0 90 | 5d9e1ecd-9e2e-4d37-86f4-fcb71f419384 91 | zh 92 | OnOutputUpdated 93 | 94 | 95 | embedded 96 | 97 | 98 | embedded 99 | 100 | 101 | embedded 102 | True 103 | 104 | 105 | embedded 106 | 107 | 108 | True 109 | embedded 110 | 111 | 112 | embedded 113 | 114 | 115 | 116 | True 117 | \ 118 | 119 | 120 | 121 | 122 | 123 | C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Windows.Forms.dll 124 | 125 | 126 | 127 | 128 | 129 | True 130 | \ 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | -------------------------------------------------------------------------------- /TestDemo/IoCTests.cs: -------------------------------------------------------------------------------- 1 | using Xunit; 2 | using UPPERIOC.UPPER.IOC.Center.IProvider; 3 | using TestDemo.Entity; 4 | using UPPERIOC.UPPER.IOC.DefaultProvider; 5 | using System.Collections.Concurrent; 6 | using System.Threading.Tasks; 7 | using System; 8 | 9 | public class IoCTests 10 | { 11 | private readonly UPPERDefaultProvider _container; 12 | 13 | public IoCTests() 14 | { 15 | _container = new UPPERDefaultProvider(); 16 | } 17 | 18 | [Fact] 19 | public void Register_And_Resolve_SimpleService() 20 | { 21 | var obj = _container.Rigister(); 22 | Assert.NotNull(obj); 23 | var resolved = _container.GetInstance(); 24 | Assert.NotNull(resolved); 25 | Assert.Equal("Hello", resolved.GetData()); 26 | } 27 | 28 | [Fact] 29 | public void Register_And_Resolve_ComplexService_With_Dependency() 30 | { 31 | _container.Rigister(); 32 | var obj = _container.Rigister(); 33 | 34 | Assert.NotNull(obj); 35 | Assert.NotNull(obj.Simple); 36 | Assert.Equal("Hello", obj.Simple.GetData()); 37 | } 38 | 39 | [Fact] 40 | public void Register_With_Name_And_Resolve_By_Name() 41 | { 42 | var name = "MySimple"; 43 | var reg = _container.Rigister(name); 44 | 45 | var resolved = _container.GetInstance(name); 46 | Assert.NotNull(resolved); 47 | Assert.Equal("Hello", resolved.GetData()); 48 | } 49 | 50 | [Fact] 51 | public void Register_Interface_And_Resolve_Concrete_Implementation() 52 | { 53 | _container.Rigister(); 54 | var service = _container.GetInstanceAndSub(); 55 | Assert.NotNull(service); 56 | Assert.Equal("Pong", service.Ping()); 57 | } 58 | 59 | [Fact] 60 | public void Register_Multiple_Instances_Should_Be_Different_When_Single_False() 61 | { 62 | var obj1 = _container.Rigister( false); 63 | var obj2 = _container.GetInstance(typeof(SimpleService)); 64 | Assert.NotNull(obj1); 65 | Assert.NotNull(obj2); 66 | Assert.NotSame(obj1, obj2); 67 | } 68 | 69 | [Fact] 70 | public void Property_Injection_Should_Work() 71 | { 72 | _container.Rigister(); 73 | var result = _container.Rigister(); 74 | 75 | Assert.NotNull(result); 76 | Assert.NotNull(result.InjectedProp); 77 | Assert.Equal("Hello", result.InjectedProp.GetData()); 78 | } 79 | [Fact] 80 | public void Concurrent_Resolve_Should_Be_Thread_Safe() 81 | { 82 | _container.Rigister(false); // 非单例,避免因共享导致误判 83 | 84 | var exceptions = new ConcurrentQueue(); 85 | var results = new ConcurrentBag(); 86 | 87 | Parallel.For(0, 1000, i => 88 | { 89 | try 90 | { 91 | var instance = _container.GetInstance(); 92 | if (instance == null || instance.GetData() != "Hello") 93 | { 94 | exceptions.Enqueue(new Exception("Resolved instance invalid")); 95 | } 96 | results.Add(instance); 97 | } 98 | catch (Exception ex) 99 | { 100 | exceptions.Enqueue(ex); 101 | } 102 | }); 103 | 104 | Assert.Empty(exceptions); // 不应有异常 105 | Assert.Equal(1000, results.Count); // 所有实例都应返回 106 | } 107 | 108 | [Fact] 109 | public void Concurrent_Register_And_Resolve_Should_Not_Throw() 110 | { 111 | var exceptions = new ConcurrentQueue(); 112 | 113 | Parallel.For(0, 100, i => 114 | { 115 | try 116 | { 117 | _container.Rigister(false); 118 | var resolved = _container.GetInstance(); 119 | if (resolved == null || resolved.GetData() != "Hello") 120 | { 121 | exceptions.Enqueue(new Exception("Invalid resolution")); 122 | } 123 | } 124 | catch (Exception ex) 125 | { 126 | exceptions.Enqueue(ex); 127 | } 128 | }); 129 | 130 | Assert.Empty(exceptions); // 并发注册和解析不应抛出异常 131 | } 132 | [Fact] 133 | public void Concurrent_Resolve_ComplexService_Should_Be_Thread_Safe() 134 | { 135 | _container.Rigister(); 136 | _container.Rigister(); 137 | 138 | var exceptions = new ConcurrentQueue(); 139 | var results = new ConcurrentBag(); 140 | 141 | Parallel.For(0, 1000, i => 142 | { 143 | try 144 | { 145 | var instance = _container.GetInstance(); 146 | if (instance == null || instance.Simple == null || instance.Simple.GetData() != "Hello") 147 | { 148 | exceptions.Enqueue(new Exception("Constructor injection failed")); 149 | } 150 | results.Add(instance); 151 | } 152 | catch (Exception ex) 153 | { 154 | exceptions.Enqueue(ex); 155 | } 156 | }); 157 | 158 | Assert.Empty(exceptions); 159 | Assert.Equal(1000, results.Count); 160 | } 161 | [Fact] 162 | public void Concurrent_Resolve_PropertyInjectedService_Should_Be_Thread_Safe() 163 | { 164 | _container.Rigister(); 165 | _container.Rigister(); 166 | 167 | var exceptions = new ConcurrentQueue(); 168 | var results = new ConcurrentBag(); 169 | 170 | Parallel.For(0, 1000, i => 171 | { 172 | try 173 | { 174 | var instance = _container.GetInstance(); 175 | if (instance == null || instance.InjectedProp == null || instance.InjectedProp.GetData() != "Hello") 176 | { 177 | exceptions.Enqueue(new Exception("Property injection failed")); 178 | } 179 | results.Add(instance); 180 | } 181 | catch (Exception ex) 182 | { 183 | exceptions.Enqueue(ex); 184 | } 185 | }); 186 | 187 | Assert.Empty(exceptions); 188 | Assert.Equal(1000, results.Count); 189 | } 190 | 191 | } 192 | -------------------------------------------------------------------------------- /UPPERIOC/UPPER._Premission/Center/PremissionCenter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | using UPPERIOC.UPPER.IOC.Center.IProvider; 8 | using UPPERIOC2.UPPER.Premission.IConfiguation; 9 | using UPPERIOC2.UPPER.Premission.Model; 10 | using UPPERIOC2.UPPER.Util; 11 | 12 | namespace UPPERIOC2.UPPER.Premission.Center 13 | { 14 | public class PremissionCenter 15 | { 16 | public static IContainerProvider pd; 17 | public static PremissionCenter Instance { get => pd.GetInstance(); } 18 | List users = new List(); 19 | string Locatstr = "HKEY_LOCAL_MACHINE\\SOFTWARE\\"; 20 | public IPremissionConfiguation c; 21 | public PermissionModel pm; 22 | RigisterObjLoad rod; 23 | public User CurrentUser; 24 | internal void Load() 25 | { 26 | var r = pd.GetAllInstance(); 27 | if (r == null || r.Length == 0) 28 | { 29 | throw new Exception("请配置至少一个IPremissionConfiguation实现类于容器中"); 30 | } 31 | c = r[0]; 32 | rod = RigisterObjLoad.GetInstance(Locatstr+ c.ApplicationName); 33 | pm = rod.LoadObjectFromRegistry(c.ApplicationName); 34 | if (pm == null) 35 | { 36 | if (!c.AllowNull) 37 | { 38 | throw new Exception("配置异常,联系管理"); 39 | } 40 | else 41 | { 42 | pm = c.InitModel(); 43 | SaveChange(); 44 | } 45 | //pm = new PermissionModel(); 46 | } 47 | CurrentUser = c.Login(pm); 48 | if (CurrentUser == null && !c.AllowNull) 49 | { 50 | throw new Exception("登录失败"); 51 | } 52 | } 53 | public void AddUserToGroup(User user, RoleGroup gp) 54 | { 55 | user.RoleGroup = gp.id; 56 | //gp.users.Add(user.id); 57 | 58 | } 59 | public void AddRoleToGroup(Role r,RoleGroup rp) 60 | { 61 | rp.Roles.Add(r.id); 62 | 63 | } 64 | public bool TryDo(int premission,Action act) 65 | { 66 | User Cu = CurrentUser; 67 | if(PermissionInterceptor.Intercept(premission, false)) 68 | { 69 | act.Invoke(); 70 | return true; 71 | } 72 | CurrentUser = Cu; 73 | return false; 74 | } 75 | public void Must(int premission,string def ="") { 76 | User CurrentUser = this.CurrentUser; 77 | while (true) 78 | { 79 | if (pm.rolegps.Find(item => CurrentUser?.RoleGroup == item.id)?.Roles?.Contains(premission) == true) 80 | { 81 | break; 82 | } 83 | bool r = c.NotPremission(); 84 | 85 | 86 | 87 | CurrentUser = c.Login(pm,def); 88 | 89 | } 90 | } 91 | public List GetRoleByRoleGroup(RoleGroup rp) 92 | { 93 | List lr = new List(); 94 | 95 | 96 | foreach (var item in rp.Roles) 97 | { 98 | var i = pm.roles.Find(item1 => item == item1.id); 99 | if (i != null) 100 | { 101 | lr.Add(i); 102 | 103 | } 104 | } 105 | return lr; 106 | } 107 | public RoleGroup AddRoleGroup(RoleGroup GroupName) 108 | { 109 | GroupName.id = pm.RoleGPid; 110 | pm.rolegps.Add(GroupName); 111 | pm.RoleGPid++; 112 | return GroupName; 113 | } 114 | public Role AddRole(Role Role) 115 | { 116 | Role.id = pm.Roleid; 117 | pm.roles.Add(Role); 118 | pm.Roleid++; 119 | return Role; 120 | } 121 | public User UpdateById(User us,string pwd = null) { 122 | var changeu = pm.users.Find(item=> item.id == us.id); 123 | changeu.Name = us.Name; 124 | changeu.RoleGroup = us.RoleGroup; 125 | if (!string.IsNullOrWhiteSpace(pwd)) 126 | { 127 | string Token = HashHelper.EncryptWithSalt(c.Solt, pwd); 128 | changeu.Token = Token; 129 | 130 | } 131 | changeu.UserName = us.UserName; 132 | //changeu.ActPath = us.ActPath; 133 | if (changeu.ActPath != us.ActPath) 134 | { 135 | changeu.ActPath = AddPic(us.ActPath); 136 | 137 | } 138 | return changeu; 139 | 140 | } 141 | 142 | public Role UpdateById(Role us) 143 | { 144 | var changeu = pm.roles.Find(item => item.id == us.id); 145 | changeu.Name = us.Name; 146 | changeu.Backup = us.Backup; 147 | return changeu; 148 | 149 | } 150 | public RoleGroup UpdateById(RoleGroup us) 151 | { 152 | var changeu = pm.rolegps.Find(item => item.id == us.id); 153 | changeu.Backup= us.Backup; 154 | changeu.GpName= us.GpName; 155 | changeu.Roles= us.Roles; 156 | //changeu.users= us.users; 157 | return changeu; 158 | 159 | } 160 | 161 | public void RemoveChange() { 162 | pm = rod.LoadObjectFromRegistry(c.ApplicationName); 163 | 164 | } 165 | public string AddPic(string str) 166 | { 167 | var fi = FileUtil.RelativePathToFileInfo(str); 168 | if (fi== null || !fi.Exists) 169 | { 170 | return ""; 171 | } 172 | var dpa = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, c.PicSavePath); 173 | if (!Directory.Exists(dpa)) 174 | { 175 | Directory.CreateDirectory(dpa); 176 | } 177 | var dstr = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, c.PicSavePath, pm.PicNum + ""); 178 | fi.CopyTo(dstr,true); 179 | pm.PicNum++; 180 | return FileUtil.FileInfoToRelativePath(new FileInfo(dstr)); 181 | } 182 | public User AddUser(string UserName,string password,string ActPath,string Name) 183 | { 184 | string Token = HashHelper.EncryptWithSalt(c.Solt, password); 185 | 186 | var user= new User { id = (int)pm.Userid, UserName = UserName, Token = Token, ActPath = ActPath, Name = Name }; 187 | pm.users.Add(user); 188 | pm.Userid++; 189 | user.ActPath = AddPic(user.ActPath); 190 | return user; 191 | 192 | } 193 | public bool CanInvoke(int Role ,bool needlogin, User CurrentUser = null) 194 | { 195 | if (CurrentUser == null) 196 | { 197 | CurrentUser = this.CurrentUser; 198 | } 199 | try 200 | { 201 | 202 | if (CurrentUser == null && !c.AllowNull) 203 | { 204 | 205 | 206 | //return false; 207 | } 208 | if (pm.rolegps == null && !c.AllowNull) 209 | { 210 | //CurrentUser = c.Login(pm); 211 | 212 | //return false; 213 | } 214 | if (pm.rolegps.Find(item => CurrentUser?.RoleGroup == item.id)?.Roles?.Contains(Role) == true) 215 | { 216 | return true; 217 | } 218 | 219 | 220 | // return false; 221 | } 222 | catch (Exception) 223 | { 224 | 225 | throw; 226 | } 227 | finally { 228 | 229 | if (needlogin && CurrentUser!= null) 230 | { 231 | this.CurrentUser = CurrentUser; 232 | } 233 | } 234 | 235 | bool r = c.NotPremission(); 236 | CurrentUser = c.Login(pm); 237 | if (r) 238 | { 239 | //CurrentUser = c.Login(pm); 240 | return CanInvoke(Role, needlogin,CurrentUser); 241 | } 242 | return false; 243 | } 244 | 245 | public void SaveChange() { 246 | 247 | rod.SaveObjectToRegistry(c.ApplicationName, pm); 248 | } 249 | } 250 | } 251 | -------------------------------------------------------------------------------- /UPPERIOC/Util/TranslateUtil.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Net; 6 | using System.Security.Cryptography; 7 | using System.Text; 8 | using System.Threading; 9 | using System.Threading.Tasks; 10 | using UPPERIOC; 11 | using UPPERIOC.UPPER.Translate.IConfigration; 12 | 13 | namespace UPPERIOC2.UPPER.Util 14 | { 15 | public class TranslateUtil 16 | { 17 | public static string ExtractTranslation(string json,string key1) 18 | { 19 | if (string.IsNullOrWhiteSpace(json)) 20 | { 21 | throw new ArgumentException("JSON cannot be null or empty", nameof(json)); 22 | } 23 | 24 | string key = "\"" + key1+"\""; 25 | int keyIndex = json.IndexOf(key, StringComparison.Ordinal); 26 | 27 | if (keyIndex == -1) 28 | { 29 | return ""; 30 | } 31 | 32 | // Find the start of the value after the key 33 | int startIndex = json.IndexOf(':', keyIndex) + 1; 34 | 35 | // Ensure valid value extraction 36 | if (startIndex == 0) 37 | { 38 | return ""; 39 | } 40 | 41 | // Handle nested braces or direct strings 42 | int braceCount = 0; 43 | int endIndex = startIndex; 44 | bool inQuotes = false; 45 | 46 | for (int i = startIndex; i < json.Length; i++) 47 | { 48 | char currentChar = json[i]; 49 | 50 | if (currentChar == '"' && (i == 0 || json[i - 1] != '\\')) 51 | { 52 | inQuotes = !inQuotes; 53 | } 54 | 55 | if (!inQuotes) 56 | { 57 | if (currentChar == '{') 58 | { 59 | braceCount++; 60 | } 61 | else if (currentChar == '}') 62 | { 63 | braceCount--; 64 | } 65 | 66 | if (braceCount == 0 && (currentChar == '}' || currentChar == ',')) 67 | { 68 | endIndex = i + 1; 69 | break; 70 | } 71 | } 72 | } 73 | string result = json.Substring(startIndex, endIndex - startIndex).Trim(); 74 | 75 | // Return the result, or a message if no valid value was found 76 | return string.IsNullOrEmpty(result) ? "" : result.Replace("[", "").Replace("\"", "").Replace("\"", "").Replace("]", "").Replace(",", ""); 77 | 78 | } 79 | static object tl = new object(); 80 | public static string Transcale(string q) 81 | { 82 | var cof = UPPERIOCApplication.Container.GetInstanceAndSub(); 83 | if (cof == null) 84 | { 85 | return q; 86 | } 87 | if (cof.FromLanguage == cof.ToLanguage) 88 | { 89 | return q; 90 | } 91 | lock (tl) 92 | { 93 | Dictionary dic = new Dictionary(); 94 | string url = "https://openapi.youdao.com/api"; 95 | string appKey = cof.APPKey; 96 | string appSecret = cof.APPSeret; 97 | string salt = DateTime.Now.Millisecond.ToString(); 98 | 99 | dic.Add("from", cof.FromLanguage); 100 | dic.Add("to", cof.ToLanguage); 101 | dic.Add("signType", "v3"); 102 | TimeSpan ts = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)); 103 | long millis = (long)ts.TotalMilliseconds; 104 | string curtime = Convert.ToString(millis / 1000); 105 | dic.Add("curtime", curtime); 106 | string signStr = appKey + Truncate(q) + salt + curtime + appSecret; ; 107 | string sign = ComputeHash(signStr, new SHA256CryptoServiceProvider()); 108 | dic.Add("q", UrlEncode(q)); 109 | dic.Add("appKey", appKey); 110 | dic.Add("salt", salt); 111 | dic.Add("sign", sign); 112 | dic.Add("vocabId", "您的用户词表ID"); 113 | string re = Post(url, dic); 114 | Thread.Sleep(1000); 115 | Console.WriteLine(re); 116 | return ExtractTranslation(re, "translation"); 117 | } 118 | } 119 | public static string UrlEncode(string value) 120 | { 121 | if (string.IsNullOrEmpty(value)) 122 | { 123 | return string.Empty; 124 | } 125 | 126 | StringBuilder encoded = new StringBuilder(); 127 | foreach (char c in value) 128 | { 129 | if (IsSafe(c)) 130 | { 131 | encoded.Append(c); 132 | } 133 | else 134 | { 135 | // Convert character to its hexadecimal representation 136 | encoded.Append($"%{(int)c:X2}"); 137 | } 138 | } 139 | return encoded.ToString(); 140 | } 141 | 142 | private static bool IsSafe(char c) 143 | { 144 | // Safe characters as per URL encoding rules 145 | return char.IsLetterOrDigit(c) || "-_.~".IndexOf(c) >= 0; 146 | } 147 | 148 | protected static string ComputeHash(string input, HashAlgorithm algorithm) 149 | { 150 | Byte[] inputBytes = Encoding.UTF8.GetBytes(input); 151 | Byte[] hashedBytes = algorithm.ComputeHash(inputBytes); 152 | return BitConverter.ToString(hashedBytes).Replace("-", ""); 153 | } 154 | protected static string Post(string url, Dictionary dic) 155 | { 156 | string result = ""; 157 | HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); 158 | req.Method = "POST"; 159 | req.ContentType = "application/x-www-form-urlencoded"; 160 | StringBuilder builder = new StringBuilder(); 161 | int i = 0; 162 | foreach (var item in dic) 163 | { 164 | if (i > 0) 165 | builder.Append("&"); 166 | builder.AppendFormat("{0}={1}", item.Key, item.Value); 167 | i++; 168 | } 169 | byte[] data = Encoding.UTF8.GetBytes(builder.ToString()); 170 | req.ContentLength = data.Length; 171 | using (Stream reqStream = req.GetRequestStream()) 172 | { 173 | reqStream.Write(data, 0, data.Length); 174 | reqStream.Close(); 175 | } 176 | HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); 177 | if (resp.ContentType.ToLower().Equals("audio/mp3")) 178 | { 179 | SaveBinaryFile(resp, "合成的音频存储路径"); 180 | } 181 | else 182 | { 183 | Stream stream = resp.GetResponseStream(); 184 | using (StreamReader reader = new StreamReader(stream, Encoding.UTF8)) 185 | { 186 | result = reader.ReadToEnd(); 187 | } 188 | return (result); 189 | } 190 | return null; 191 | } 192 | 193 | protected static string Truncate(string q) 194 | { 195 | if (q == null) 196 | { 197 | return null; 198 | } 199 | int len = q.Length; 200 | return len <= 20 ? q : (q.Substring(0, 10) + len + q.Substring(len - 10, 10)); 201 | } 202 | 203 | private static bool SaveBinaryFile(WebResponse response, string FileName) 204 | { 205 | string FilePath = FileName + DateTime.Now.Millisecond.ToString() + ".mp3"; 206 | bool Value = true; 207 | byte[] buffer = new byte[1024]; 208 | 209 | try 210 | { 211 | if (File.Exists(FilePath)) 212 | File.Delete(FilePath); 213 | Stream outStream = System.IO.File.Create(FilePath); 214 | Stream inStream = response.GetResponseStream(); 215 | 216 | int l; 217 | do 218 | { 219 | l = inStream.Read(buffer, 0, buffer.Length); 220 | if (l > 0) 221 | outStream.Write(buffer, 0, l); 222 | } 223 | while (l > 0); 224 | 225 | outStream.Close(); 226 | inStream.Close(); 227 | } 228 | catch 229 | { 230 | Value = false; 231 | } 232 | return Value; 233 | } 234 | } 235 | } 236 | --------------------------------------------------------------------------------