From 524c93f4301150458264020778343b2ce2bf8263 Mon Sep 17 00:00:00 2001 From: wenjy Date: Fri, 27 Dec 2024 10:40:07 +0800 Subject: [PATCH] =?UTF-8?q?change=20-=20=E5=A2=9E=E5=8A=A0=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E4=BF=AE=E6=94=B9=E5=8A=9F=E8=83=BD?= =?UTF-8?q?SetValue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SlnMesnac.Config/AppConfig.cs | 24 ++++++++++++++++++++++++ SlnMesnac.Config/SlnMesnac.Config.csproj | 1 + 2 files changed, 25 insertions(+) diff --git a/SlnMesnac.Config/AppConfig.cs b/SlnMesnac.Config/AppConfig.cs index 1cfc66e..d2b0de6 100644 --- a/SlnMesnac.Config/AppConfig.cs +++ b/SlnMesnac.Config/AppConfig.cs @@ -1,6 +1,9 @@ using Microsoft.Extensions.Options; +using Newtonsoft.Json; using System; using System.Collections.Generic; +using System.IO; +using System.Xml; #region << 版 本 注 释 >> /*-------------------------------------------------------------------- @@ -58,6 +61,27 @@ namespace SlnMesnac.Config /// public string redisConfig { get; set; } + /// + /// 修改配置文件 + /// + /// + public void SetValue(AppConfig appConfig) + { + var jsonObject = JsonConvert.SerializeObject(new + { + AppConfig = new + { + logPath = appConfig.logPath, + SqlConfig = appConfig.sqlConfig, + PlcConfig = appConfig.plcConfig, + RfidConfig = appConfig.rfidConfig, + RedisConfig = appConfig.redisConfig, + } + }, Newtonsoft.Json.Formatting.Indented); + var appSettingsPath = Path.Combine(AppContext.BaseDirectory, "appsettings.json"); + File.WriteAllText(appSettingsPath, jsonObject); + } + public AppConfig Value => this; } } diff --git a/SlnMesnac.Config/SlnMesnac.Config.csproj b/SlnMesnac.Config/SlnMesnac.Config.csproj index 5ed17ce..daf8195 100644 --- a/SlnMesnac.Config/SlnMesnac.Config.csproj +++ b/SlnMesnac.Config/SlnMesnac.Config.csproj @@ -7,6 +7,7 @@ +