|
@@ -0,0 +1,223 @@
|
|
|
+using System.Collections;
|
|
|
+using System.Collections.Concurrent;
|
|
|
+using System.Diagnostics;
|
|
|
+using Newtonsoft.Json.Linq;
|
|
|
+using WingServerCommon.Config.Parameters;
|
|
|
+using WingServerCommon.Log;
|
|
|
+
|
|
|
+namespace WingServerCommon.Config
|
|
|
+{
|
|
|
+ public class LanguageSetting
|
|
|
+ {
|
|
|
+ private static ConcurrentDictionary<string, IList<DataItemParameter>> _parameters;
|
|
|
+
|
|
|
+ private static ConcurrentDictionary<string, IParameter> _params;
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Init load appsetting
|
|
|
+ /// </summary>
|
|
|
+ static LanguageSetting()
|
|
|
+ {
|
|
|
+ _parameters = new ConcurrentDictionary<string, IList<DataItemParameter>>();
|
|
|
+ _params = new ConcurrentDictionary<string, IParameter>();
|
|
|
+ AddOrUpdateLanguageConfig();
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Add or Update Config File
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="filePath">Config File Path</param>
|
|
|
+ public static void AddOrUpdateLanguageConfig()
|
|
|
+ {
|
|
|
+ var languageJson = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resource", "Languge", "LanguageConfig.json"));
|
|
|
+ JObject obj = JObject.Parse(languageJson);
|
|
|
+ var languageKey = "LanguageConfigs";
|
|
|
+ var regionKey = "RegionConfigs";
|
|
|
+ var languageConfigs = obj["SystemLanguageConfig"][languageKey].ToObject<List<DataItemParameter>>();
|
|
|
+ var regionConfigs = obj["SystemLanguageConfig"][regionKey].ToObject<List<DataItemParameter>>();
|
|
|
+ //替换原先的值_parameters
|
|
|
+ if (_parameters?.Count > 0)
|
|
|
+ {
|
|
|
+ if (languageConfigs != null && _parameters.ContainsKey(languageKey))
|
|
|
+ {
|
|
|
+ _parameters[languageKey] = languageConfigs;
|
|
|
+ }
|
|
|
+ if (regionConfigs != null && _parameters.ContainsKey(regionKey))
|
|
|
+ {
|
|
|
+ _parameters[regionKey] = regionConfigs;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ _parameters.TryAdd(languageKey, languageConfigs);
|
|
|
+ _parameters.TryAdd(regionKey, regionConfigs);
|
|
|
+ }
|
|
|
+ ReloadPatientInfoConfig();
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Get parameter by specifed section name
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="sectionName"></typeparam>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static IDictionary<string, string> GetLanguageConfigParammeter(string sectionName)
|
|
|
+ {
|
|
|
+ if (_parameters.ContainsKey(sectionName))
|
|
|
+ {
|
|
|
+ _parameters.TryGetValue(sectionName, out IList<DataItemParameter> _value);
|
|
|
+ var dic = new Dictionary<string, string>();
|
|
|
+ if(_value?.Count > 0)
|
|
|
+ {
|
|
|
+ foreach (var item in _value)
|
|
|
+ {
|
|
|
+ if (!dic.Keys.Contains(item.Key))
|
|
|
+ {
|
|
|
+ dic.Add(item.Key, item.Value);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ dic[item.Key] = item.Value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return dic;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Logger.WriteLineWarn($"LanguageSetting GetLanguageConfigParammeter key is not exist, sectionName: {sectionName} not set correct");
|
|
|
+ }
|
|
|
+ throw new System.ArgumentException($"{sectionName} not set correct");
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Get parameter by specifed section name and return type
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="sectionName"></typeparam>
|
|
|
+ /// <typeparam name="isReturnVal"></typeparam>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static IList<string> GetLanguageConfigParammeter(string sectionName, bool isReturnVal)
|
|
|
+ {
|
|
|
+ if (_parameters.ContainsKey(sectionName))
|
|
|
+ {
|
|
|
+ _parameters.TryGetValue(sectionName, out IList<DataItemParameter> _value);
|
|
|
+ var resultData = new List<string>();
|
|
|
+ if (_value?.Count > 0)
|
|
|
+ {
|
|
|
+ if (isReturnVal)
|
|
|
+ {
|
|
|
+ resultData = _value.Select(c => c.Value).ToList();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ resultData = _value.Select(c => c.Key).ToList();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return resultData;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Logger.WriteLineWarn($"LanguageSetting GetLanguageConfigParammeter key is not exist, sectionName: {sectionName} not set correct");
|
|
|
+ }
|
|
|
+ throw new System.ArgumentException($"{sectionName} not set correct");
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// reload patient Info
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ private static void ReloadPatientInfoConfig()
|
|
|
+ {
|
|
|
+ var languageData = GetLanguageConfigParammeter("LanguageConfigs", true);
|
|
|
+ if (languageData?.Count > 0)
|
|
|
+ {
|
|
|
+ foreach(var item in languageData)
|
|
|
+ {
|
|
|
+ var configFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resource", "Languge", item, "patientInfo.json");
|
|
|
+ AddOrUpdateConfig(configFilePath, item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Add or Update Config File
|
|
|
+ /// </summary>
|
|
|
+ private static void AddOrUpdateConfig(string filePath, string language)
|
|
|
+ {
|
|
|
+ var _newParameters = ParameterDictionarySerializer.Deserialize(filePath);
|
|
|
+ //替换原先的值_parameters
|
|
|
+ if (_newParameters?.Count > 0)
|
|
|
+ {
|
|
|
+ foreach(var key in _newParameters.Keys)
|
|
|
+ {
|
|
|
+ var newKey = language + "_" + key;
|
|
|
+ if (_params != null && _params.ContainsKey(newKey))
|
|
|
+ {
|
|
|
+ _params[newKey] = _newParameters[key];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (_params == null)
|
|
|
+ {
|
|
|
+ _params = new ConcurrentDictionary<string, IParameter>();
|
|
|
+ }
|
|
|
+ _params.TryAdd(newKey, _newParameters[key]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Get parameter by specifed section name and parameter name and language
|
|
|
+ /// </summary>
|
|
|
+ /// <typeparam name="T"></typeparam>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static T GetParammeter<T>(string language, string sectionName, string paramName) where T : class
|
|
|
+ {
|
|
|
+ var key = language + "_" + sectionName + "_" + paramName;
|
|
|
+ if (_params.ContainsKey(key))
|
|
|
+ {
|
|
|
+ var res = _params.TryGetValue(key, out IParameter _value);
|
|
|
+ if (_value != null)
|
|
|
+ {
|
|
|
+ var parameter = _value as T;
|
|
|
+ if (parameter != null)
|
|
|
+ {
|
|
|
+ return parameter;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Logger.WriteLineWarn($"LanguageSetting GetParammeter key is not exist, language: {language} - sectionName: {sectionName} - paramName: {paramName} not set correct");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Logger.WriteLineWarn($"LanguageSetting GetParammeter key is not exist, language: {language} - sectionName: {sectionName} - paramName: {paramName} not set correct");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Logger.WriteLineWarn($"LanguageSetting GetParammeter key is not exist, language: {language} - sectionName: {sectionName} - paramName: {paramName} not set correct");
|
|
|
+ }
|
|
|
+ throw new System.ArgumentException($"{language} - {sectionName} - {paramName} not set correct");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 参数项实体
|
|
|
+ /// </summary>
|
|
|
+ public class DataItemParameter
|
|
|
+ {
|
|
|
+ /// <summary>
|
|
|
+ /// Key
|
|
|
+ /// </summary>
|
|
|
+ /// <value></value>
|
|
|
+ public string Key { get; set; } = string.Empty;
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Value
|
|
|
+ /// </summary>
|
|
|
+ /// <value></value>
|
|
|
+ public string Value { get; set; } = string.Empty;
|
|
|
+ }
|
|
|
+}
|