Exemplo n.º 1
0
        private static T ConfigFactory <T>(string name = null) where T : IConfig
        {
            var configName = name ?? typeof(T).Name.Replace("Config", "");

            Logger.Log(LogLevel.Info, $"Loading {configName} application data...");

            try
            {
                var config = JsonConvert.DeserializeObject <T>(Cfg.GetConfigJsonAsync(configName).GetAwaiter().GetResult());

                Logger.Log(LogLevel.Info, $"{configName} application data load complete");

                config.LoadUserConfigAsync(Cfg.AppDataPath).GetAwaiter().GetResult();

                Logger.Log(LogLevel.Info, $"{configName} user data load complete");

                return(config);
            }
            catch (Exception e)
            {
                Logger.Log(LogLevel.Fatal, $"Unable to load {configName} application data");
                Logger.Log(LogLevel.Fatal, e.Message);
                Logger.Log(LogLevel.Fatal, e.StackTrace);

                throw;
            }
        }