45 lines
1.5 KiB
C#
45 lines
1.5 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 async void AddOrUpdateJsonKeyValueAsync(string key, string value)
|
|
{
|
|
|
|
var jsonFileFolder = Path.Combine(AppContext.BaseDirectory, StaticData.Folder.Resources);
|
|
|
|
if (!Directory.Exists(jsonFileFolder) ||
|
|
Directory.GetFiles(jsonFileFolder).Any(filePath => Path.GetExtension(filePath).Equals(".json", StringComparison.OrdinalIgnoreCase)))
|
|
{
|
|
throw new BusinessValidationFailedException("国际化Json文件目录有误");
|
|
}
|
|
|
|
//
|
|
foreach (var filePath in Directory.GetFiles(jsonFileFolder).Where(filePath => Path.GetExtension(filePath).Equals(".json", StringComparison.OrdinalIgnoreCase)))
|
|
{
|
|
var json = await File.ReadAllTextAsync(filePath);
|
|
|
|
JObject jsonObject = JObject.Parse(json, new JsonLoadSettings() { CommentHandling = CommentHandling.Load });
|
|
|
|
// 添加或更新指定的键值对
|
|
jsonObject[key] = value;
|
|
|
|
await File.WriteAllTextAsync(filePath, jsonObject.ToString());
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|