示例#1
0
        private ConfigVersion GetConfigVersion()
        {
            try
            {
                _logger.LogDebug("Reading JSON file");
                string json = File.ReadAllText(cfgFilePath);

                _logger.LogDebug("Parsing JSON file");
                JObject jsonobject = JObject.Parse(json);

                _logger.LogDebug("Getting version from JObject");
                string version = jsonobject.Value <string>("Version");

                _logger.LogDebug("Parsing version from: {0}", version.NullableToString());

                ConfigVersion versionenum = (ConfigVersion)Enum.Parse(typeof(ConfigVersion), version);
                if (!Enum.IsDefined(typeof(ConfigVersion), versionenum) && !versionenum.ToString().Contains(","))
                {
                    throw new InvalidOperationException($"{version} is not an underlying value of the ConfigVersion enumeration.");
                }

                _logger.LogInformation("Version found: {0}", versionenum.ToString());
                return(versionenum);
            }
            catch (Exception e)
            {
                _logger.LogError("Couldn't read version of config");
                _logger.LogTrace(e.Message);
                return(ConfigVersion.Unknown);
            }
        }
        protected override void UpgradeToCurrentVersion()
        {
            switch (ConfigVersion?.ToString())
            {
            default:
                Utility.DisplayLocalizedText("str_config_incompatible");
                ResetToDefault();
                Serialize();
                break;

            case "1.0":
                break;
            }
        }