change - 增加配置文件修改功能SetValue

pull/8/head
wenjy 3 weeks ago
parent 0291c5e67b
commit 524c93f430

@ -1,6 +1,9 @@
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Xml;
#region << 版 本 注 释 >> #region << 版 本 注 释 >>
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
@ -58,6 +61,27 @@ namespace SlnMesnac.Config
/// </summary> /// </summary>
public string redisConfig { get; set; } public string redisConfig { get; set; }
/// <summary>
/// 修改配置文件
/// </summary>
/// <param name="appConfig"></param>
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; public AppConfig Value => this;
} }
} }

@ -7,6 +7,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.1" /> <PackageReference Include="Microsoft.Extensions.Options" Version="8.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup> </ItemGroup>
</Project> </Project>

Loading…
Cancel
Save