public RemoteStoreRepository(IOptions <ErrorCodeSetting> errorCodeConfiguration, ILoggerFactory loggerFactory, IJsonHelper jsonHelper)
 {
     _logger = loggerFactory.CreateLogger <RemoteStoreRepository>();
     _config = new ErrorCodeConfig();
     _errorCodeConfiguration = errorCodeConfiguration.Value;
     _jsonHelper             = jsonHelper;
 }
    // Use this for initialization
    void Start()
    {
        string error = ErrorCodeConfig.GetErrorById(10000);

        Debug.Log(error);

        string error1 = Error.GetErrorById(10001);

        Debug.Log(error1);

        string name = JsonTest.Config.name;

        Debug.Log(name);

        GoodsConfigGoods goods = GoodsConfig.GetGoodsById(10000);

        if (goods != null)
        {
            Debug.Log(goods.Name);
        }

        StudentItem student = StudentConfig.GetStudent(12345);

        if (student != null)
        {
            Debug.Log(student.Name);
        }
        else
        {
            Debug.Log("没有找到数据");
        }
    }
        private void LoadErrorCodeStore()
        {
            var islocalcache   = false;
            var localcachepath = System.IO.Path.Combine(AppContext.BaseDirectory, "localerrorcode.json");

            try
            {
                var client = _httpClientFactory.CreateClient();
                var url    = GetQueryConfigUrl();
                _logger.LogInformation($"loading errorcode from  {url}");
                var response = client.SendAsync(new HttpRequestMessage(HttpMethod.Get, url)).ConfigureAwait(false).GetAwaiter().GetResult();
                _logger.LogInformation($"errorcode server responds with {response.StatusCode} HTTP status code.");
                if (response.IsSuccessStatusCode)
                {
                    var codedto = _jsonHelper.DeserializeObject <ApiInfo>(response.Content.ReadAsStringAsync().Result);
                    if (codedto != null && codedto.Value != null && codedto.Value.Count > 0)
                    {
                        if (_config.KV == null)
                        {
                            _config.KV = new ConcurrentDictionary <string, string>();
                        }
                        foreach (var kv in codedto.Value)
                        {
                            _config.KV.AddOrUpdate(kv.ErrorCode, kv.ErrorMessage, (x, y) => kv.ErrorMessage);
                        }
                        islocalcache = true;
                    }
                    _logger.LogInformation($"Loaded errorcode {response}");
                }
                if (islocalcache)
                {
                    _logger.LogInformation($"错误码中心配置信息写入本地文件:{localcachepath}");
                    string dir = System.IO.Path.GetDirectoryName(localcachepath);
                    if (!System.IO.Directory.Exists(dir))
                    {
                        System.IO.Directory.CreateDirectory(dir);
                    }
                    var json = _jsonHelper.SerializeObject(_config);
                    System.IO.File.WriteAllText(localcachepath, json);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"errorCode load error from ding:", ex);
                if (System.IO.File.Exists(localcachepath))
                {
                    var json = System.IO.File.ReadAllText(localcachepath);
                    _config = _jsonHelper.DeserializeObject <ErrorCodeConfig>(json);
                }
                _logger.LogInformation($"errorCode load error from ding,local disk cache recovery success.");
            }
        }
        private void LoadErrorCodeStore()
        {
            var islocalcache   = false;
            var localcachepath = System.IO.Path.Combine(AppContext.BaseDirectory, "localerrorcode.json");

            try
            {
                var url = GetQueryConfigUrl();
                _logger.LogInformation($"loading errorcode from  {url}");
                var response = HttpUtil.Get <ApiInfo>(new HttpRequest(url), _jsonHelper);
                _logger.LogInformation($"errorcode server responds with {response.StatusCode} HTTP status code.");
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    if (response.Body != null && response.Body.Value != null && response.Body.Value.Count > 0)
                    {
                        if (_config.KV == null)
                        {
                            _config.KV = new ConcurrentDictionary <string, string>();
                        }
                        foreach (var kv in response.Body.Value)
                        {
                            _config.KV.AddOrUpdate(kv.ErrorCode, kv.ErrorMessage, (x, y) => kv.ErrorMessage);
                        }
                        islocalcache = true;
                    }
                    _logger.LogInformation($"Loaded errorcode {response.Body}");
                }
                if (islocalcache)
                {
                    _logger.LogInformation($"错误码中心配置信息写入本地文件:{localcachepath}");
                    string dir = System.IO.Path.GetDirectoryName(localcachepath);
                    if (!System.IO.Directory.Exists(dir))
                    {
                        System.IO.Directory.CreateDirectory(dir);
                    }
                    var json = _jsonHelper.SerializeObject(_config);
                    System.IO.File.WriteAllText(localcachepath, json);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"errorCode load error from ding:", ex);
                if (System.IO.File.Exists(localcachepath))
                {
                    var json = System.IO.File.ReadAllText(localcachepath);
                    _config = _jsonHelper.DeserializeObject <ErrorCodeConfig>(json);
                }
                _logger.LogInformation($"errorCode load error from ding,local disk cache recovery success.");
            }
        }
Example #5
0
        static void Main(string[] args)
        {
            ConfigManager.ResPath = @"C:\Users\123\Desktop\MyConfig";
            ConfigManager.Instance.DefaultConfigs = new List <Type>()
            {
                typeof(ErrorCodeConfig)
            };                                       //默认的预加载配置文件集
            ConfigManager.Instance.Init(null, null); //确定是否异步加载,及逻辑下的委托执行,
            Console.WriteLine(ErrorCodeConfig.GetErrorById(2));
            //Console.WriteLine(SkillsCfg.GetSkillsName(1));

            foreach (var item in SkillsJsonCfg.Config.Skills)
            {
                Console.WriteLine("ID:" + item.ID + "   " + "名称:" + item.IntoGameName);
            }
            foreach (var item in SkillConstenfig.Config.Skills)
            {
                Console.WriteLine("Destail::" + item.Destail + "   " + "SkillName:" + item.SkillName);
            }
            Console.ReadKey();
        }
Example #6
0
        public LanguageConfig(JObject config)
        {
            Languages = (config["languages"] as JArray).Select(s => s.ToString()).ToArray();

            //加载错误码信息
            string error_code_path   = Path.GetFullPath(config["error_code"]["path"].ToString()).TrimEnd('\\', '/');
            string error_code_prefix = config["error_code"]["prefix"].ToString();

            foreach (var item in Languages)
            {
                using StreamReader file     = File.OpenText($@"{error_code_path}/{error_code_prefix}{item}.json");
                using JsonTextReader reader = new JsonTextReader(file);
                JObject o = (JObject)JToken.ReadFrom(reader);
                Dictionary <string, string> error_dic = new Dictionary <string, string>();
                var pairs = o.GetEnumerator();

                while (pairs.MoveNext())
                {
                    error_dic.Add(pairs.Current.Key, pairs.Current.Value.ToString());
                }

                ErrorCodeConfig.Add(item, error_dic);
            }
        }
Example #7
0
    public string GetErrorCodeText(int wordID)
    {
        ErrorCodeConfig config = GetConfig <ErrorCodeConfig>();

        return(config.GetWordByID(wordID, (int)MCurrentLanguage));
    }