A:整体并简化代码

This commit is contained in:
jimmy committed 2025-12-22 19:50:09 +08:00
1 parent 2c83fc72e4
commit 2563288afe
26 files changed
+889 -566

No files matched your search

+361
View File
@@ -0,0 +1,361 @@
{
// ========================================
// Sharp-Basic 框架配置模板
//
// 这是一个完整的配置文件模板,包含了所有Sharp模块的配置示例
// 使用时可以根据项目需要选择性保留相关配置节
// ========================================
// ========================================
// 系统配置 (System)
// 约定配置节名称:System
// 用于:NetClient、NetServer 的默认HTTP配置
// ========================================
"System": {
// HTTP服务监听IP地址
// 支持:IP地址、localhost、域名
"HTTPIp": "127.0.0.1",
// HTTP服务监听端口
// 范围:1-65535
"HttpPort": 8080,
// HTTP请求超时时间(秒)
// 范围:1-600
"TimeoutSeconds": 30,
// HTTP协议
// 可选值:http、https
"Scheme": "http"
},
// ========================================
// 数据库配置 (Database)
// 约定配置节名称:Database
// 用于:Data 模块 - AddSharpDatabase<TContext>(configuration)
// ========================================
"Database": {
// 数据库提供程序
// 可选值:SqlServer、Sqlite、PostgreSQL、MySql、InMemory
"Provider": "SqlServer",
// 数据库连接字符串
// SqlServer示例:Server=.;Database=MyApp;Trusted_Connection=True;TrustServerCertificate=True;
// Sqlite示例:Data Source=app.db
// PostgreSQL示例:Host=localhost;Database=myapp;Username=postgres;Password=123456
// MySql示例:server=localhost;database=myapp;user=root;password=123456
"ConnectionString": "Server=.;Database=MyApp;Trusted_Connection=True;TrustServerCertificate=True;"
},
// ========================================
// 日志配置 (Logging)
// 约定配置节名称:Logging
// 用于:Log 模块 - AddLogging(b => b.AddSharpLog())
// ========================================
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
// Sharp日志扩展配置
"SharpLog": {
// 日志文件路径(相对或绝对路径)
"LogFilePath": "logs/app-.log",
// 日志滚动间隔
// 可选值:Infinite、Year、Month、Day、Hour、Minute
"RollingInterval": "Day",
// 单个日志文件最大大小(字节)
// null 表示不限制
"FileSizeLimitBytes": 10485760,
// 保留的日志文件数量
// null 表示不限制
"RetainedFileCountLimit": 31,
// 是否输出到控制台
"EnableConsole": true,
// 是否输出到文件
"EnableFile": true,
// 是否启用结构化日志(JSON格式)
"EnableStructuredLog": false
},
// ========================================
// HTTP客户端配置 (NetClient)
// 约定配置节名称:NetClient
// 用于:NetClient 模块 - AddNetClient(configuration.GetSection("NetClient"))
// ========================================
"NetClient": {
// 基础地址(留空则使用System配置)
"BaseAddress": "http://localhost:8080",
// 请求超时时间
"Timeout": "00:00:30",
// 是否启用日志
"EnableLogging": true,
// 是否包含关联ID
"IncludeCorrelationId": true,
// 关联ID请求头名称
"CorrelationIdHeaderName": "X-Correlation-ID",
// 是否使用Bearer Token认证
"UseBearerToken": false,
// 重试配置
"Retry": {
// 是否启用重试
"Enabled": true,
// 最大重试次数
"MaxRetries": 3,
// 重试延迟(秒)
"DelaySeconds": 2
},
// 默认请求头
"DefaultRequestHeaders": {
"User-Agent": "Sharp-NetClient/1.0",
"Accept": "application/json"
}
},
// ========================================
// HTTP服务端配置 (NetServer)
// 约定配置节名称:NetServer
// 用于:NetServer 模块 - AddNetServer(configManager)
// ========================================
"NetServer": {
// 监听URL列表(留空则使用System配置)
"ListenUrls": [
"http://localhost:8080/",
"http://0.0.0.0:8080/"
],
// 是否启用详细错误信息
"ShowDetailedErrors": true,
// 请求正文最大大小(字节)
"MaxRequestBodySize": 30000000,
// 请求超时时间
"RequestTimeout": "00:05:00"
},
// ========================================
// PLC配置 - 西门子 (Plc:Siemens)
// 约定配置节名称:Plc:Siemens
// 用于:Plc.Siemens 模块 - AddSiemensPlc(configuration.GetSection("Plc:Siemens"))
// ========================================
"Plc": {
"Siemens": {
// PLC IP地址
"IpAddress": "192.168.1.100",
// CPU类型
// 可选值:S71200、S71500、S7300、S7400、S7200、S7200Smart
"CpuType": "S71200",
// 机架号(S7-300/400)
"Rack": 0,
// 插槽号(S7-300/400)
"Slot": 1,
// 端口号
"Port": 102,
// 连接超时时间(毫秒)
"ConnectTimeout": 5000,
// 读写超时时间(毫秒)
"ReadWriteTimeout": 3000,
// 监控轮询间隔(毫秒)
"MonitorInterval": 500,
// 是否自动重连
"AutoReconnect": true,
// 重连间隔(毫秒)
"ReconnectInterval": 5000
}
},
// ========================================
// 串口配置 (SerialPort)
// 约定配置节名称:SerialPort
// 用于:Ports 模块 - AddSerialPortService()
// ========================================
"SerialPort": {
// 端口名称(如 COM1、/dev/ttyUSB0)
"PortName": "COM1",
// 波特率
// 常用值:9600、19200、38400、57600、115200
"BaudRate": 9600,
// 数据位
// 可选值:5、6、7、8
"DataBits": 8,
// 停止位
// 可选值:None、One、Two、OnePointFive
"StopBits": "One",
// 校验位
// 可选值:None、Odd、Even、Mark、Space
"Parity": "None",
// 读取超时时间(毫秒)
// -1 表示无限等待
"ReadTimeout": 1000,
// 写入超时时间(毫秒)
// -1 表示无限等待
"WriteTimeout": 1000,
// 接收缓冲区大小(字节)
"ReadBufferSize": 4096,
// 发送缓冲区大小(字节)
"WriteBufferSize": 2048
},
// ========================================
// 进程执行配置 (Process)
// 约定配置节名称:Process
// 用于:Process 模块 - AddSharpProcess()
// ========================================
"Process": {
// 默认工作目录
"WorkingDirectory": "",
// 默认超时时间(毫秒)
// -1 表示无限等待
"DefaultTimeout": 30000,
// 是否重定向标准输出
"RedirectStandardOutput": true,
// 是否重定向标准错误
"RedirectStandardError": true,
// 是否使用Shell执行
"UseShellExecute": false,
// 是否创建窗口
"CreateNoWindow": true
},
// ========================================
// Python配置 (Python)
// 约定配置节名称:Python
// 用于:Python 模块 - AddSharpPython()
// ========================================
"Python": {
// Python解释器路径
// 留空则自动查找系统PATH中的python
"PythonPath": "",
// Python脚本根目录
"ScriptDirectory": "scripts",
// 默认超时时间(毫秒)
"DefaultTimeout": 60000,
// 是否启用虚拟环境
"UseVirtualEnv": false,
// 虚拟环境路径
"VirtualEnvPath": ""
},
// ========================================
// 缓存配置 (Cache)
// 约定配置节名称:Cache
// 用于:Cache 模块 - AddSharpCache()
// ========================================
"Cache": {
// 默认过期时间(秒)
"DefaultExpirationSeconds": 600,
// 缓存大小限制(条目数)
// null 表示不限制
"SizeLimit": null,
// 内存压缩比例(0.0-1.0)
"CompactionPercentage": 0.25,
// 过期扫描频率(秒)
"ExpirationScanFrequency": 60
},
// ========================================
// 事件总线配置 (EventBus)
// 约定配置节名称:EventBus
// 用于:EventBus 模块 - AddEventBus()
// ========================================
"EventBus": {
// 是否启用异步处理
"EnableAsync": true,
// 异步事件队列容量
"QueueCapacity": 1000,
// 是否在异常时继续执行其他订阅者
"ContinueOnError": true,
// 是否启用死信队列
"EnableDeadLetterQueue": false,
// 死信队列容量
"DeadLetterQueueCapacity": 100
},
// ========================================
// WPF配置 (Wpf)
// 约定配置节名称:Wpf
// 用于:Wpf 模块 - AddSharpWpf()
// ========================================
"Wpf": {
// 默认对话框标题
"DefaultDialogTitle": "提示",
// 是否启用全局异常处理
"EnableGlobalExceptionHandler": true,
// 主题
// 可选值:Light、Dark
"Theme": "Light",
// 语言
// 可选值:zh-CN、en-US
"Language": "zh-CN"
},
// ========================================
// 环境变量覆盖说明
// ========================================
// 所有配置都可以通过环境变量覆盖,格式:
// SHARP__{节名}__{键名}
//
// 示例:
// SHARP__Database__Provider=Sqlite
// SHARP__Database__ConnectionString=Data Source=test.db
// SHARP__Plc__Siemens__IpAddress=192.168.1.200
// SHARP__System__HttpPort=9090
//
// 注意:双下划线 __ 用于分隔层级
// ========================================
}