44 lines
1.3 KiB
C#
44 lines
1.3 KiB
C#
using IRaCIS.Core.Domain.Share;
|
|
using IRaCIS.Core.Infrastructure;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using static BeetleX.Redis.Commands.HSCAN;
|
|
using static IRaCIS.Core.Application.Service.Common.SystemMonitor;
|
|
|
|
namespace IRaCIS.Core.Application.Helper
|
|
{
|
|
public static class InternationalizationHelper
|
|
{
|
|
|
|
public static void AddOrUpdateJsonKeyValueAsync(string jsonFileFolder,string key ,string value)
|
|
{
|
|
|
|
|
|
|
|
if (!Directory.Exists(jsonFileFolder) ||
|
|
Directory.GetFiles(jsonFileFolder).Any(filePath => Path.GetExtension(filePath).Equals(".json", StringComparison.OrdinalIgnoreCase)))
|
|
{
|
|
throw new BusinessValidationFailedException("国际化Json文件目录有误");
|
|
}
|
|
|
|
var json = File.ReadAllText("appsettings.json");
|
|
|
|
JObject jsonObject = JObject.Parse(json, new JsonLoadSettings() { CommentHandling = CommentHandling.Load });
|
|
|
|
|
|
// 添加或更新指定的键值对
|
|
jsonObject[key] = value;
|
|
|
|
//jsonObject["testArray"] = JArray.FromObject(generalRules);
|
|
|
|
// 将更改保存回 Json 文件
|
|
File.WriteAllText(jsonFilePath, jsonObject.ToString());
|
|
|
|
}
|
|
}
|
|
}
|