示例#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);
            }
        }
示例#2
0
        public void Load()
        {
            Logger.Info("Loading config...");
            ConfigVersion version = GetConfigVersion();

            Logger.Info("Detected config version: {0}", version);

            if (version == ConfigVersion.UNKNOWN)
            {
                if (!File.Exists(configPath))
                {
                    Logger.Info("Config file doesn't exist");
                }
                else
                {
                    Logger.Info("Config file couldn't be parsed");
                }
            }

            if (version == ConfigVersion.UNKNOWN)
            {
                LoadNew();
            }
            else if (version == ConfigVersion.LEGACY)
            {
                LoadLegacy();
            }
            else if (version == ConfigVersion.v0 || version == ConfigVersion.v1)
            {
                LoadV0or1(version == ConfigVersion.v1);
            }

            LoadUsernames();
            Logger.Info("Config loading complete");
        }
示例#3
0
    void OnLoadVersionConfig(string jsonName, string json)
    {
        if (jsonName != ConfigVersion.jsonName)
        {
            return;
        }

        // new one
        json = ConfigBase.CheckAndReturn(json);
        if (null == json)
        {
            return;
        }

        ConfigVersion.FromJson(json);
        ConfigVersion.HasLoad = true;

        newMap = new Dictionary <string, int>();
        foreach (ConfigVersion config in ConfigVersion.datas)
        {
            newMap.Add(config.configName, config.confVersion);
        }

        Loaded = true;

        foreach (string jsName in newMap.Keys)
        {
            if (HasNewVersion(jsName))
            {
                DownloadConfig(jsName);
            }
        }
    }
示例#4
0
    static ConfigVersion FromJson(Dictionary <string, object> inDict)
    {
        ConfigVersion data = new ConfigVersion();

        data.configName  = inDict["configName"].GetJsonConverter().toStr();
        data.confVersion = inDict["confVersion"].GetJsonConverter().toInt();

        return(data);
    }
        internal static bool IsVersionMatch(string versionString, ConfigVersion version)
        {
            if (IsVersionInvalid(versionString))
            {
                return(version == ConfigVersion.Invalid);
            }

            SemVersion.TryParse(versionString, out SemVersion semVer, true);
            return(version switch
            {
                ConfigVersion.V1 => semVer.Major == 1,
                _ => false
            });
        protected override void UpgradeToCurrentVersion()
        {
            switch (ConfigVersion?.ToString())
            {
            default:
                Utility.DisplayLocalizedText("str_config_incompatible");
                ResetToDefault();
                Serialize();
                break;

            case "1.0":
                break;
            }
        }
示例#7
0
    public static void FromJson(string json)
    {
        List <object> list = json.listFromJson();

        _map   = new Dictionary <string, ConfigVersion>(list.Count);
        _datas = new List <ConfigVersion>(list.Count);

        for (int i = 0; i < list.Count; i++)
        {
            Dictionary <string, object> inDict = list[i] as Dictionary <string, object>;
            ConfigVersion data = FromJson(inDict);
            _map.Add(data.configName, data);
            _datas.Add(data);
        }
    }
示例#8
0
        public ConfigVersion GetVersion(String fileName)
        {
            ConfigVersion result = new ConfigVersion();
            XmlDocument doc = new XmlDocument();
            doc.Load(fileName);

            XmlAttribute aName = doc.DocumentElement.Attributes["Name"];
            XmlAttribute aVersion = doc.DocumentElement.Attributes["Version"];
            if (aName == null)
                throw new Exception("Configuration node must contain 'Name' attribute.");
            if (aVersion == null)
                throw new Exception("Configuration node must contain 'Version' attribute.");

            result.Name =aName.Value;
            result.Version = aVersion.Value;
            return result;
        }
示例#9
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (configVersion_ != null)
            {
                hash ^= ConfigVersion.GetHashCode();
            }
            if (Name.Length != 0)
            {
                hash ^= Name.GetHashCode();
            }
            if (Id.Length != 0)
            {
                hash ^= Id.GetHashCode();
            }
            if (Title.Length != 0)
            {
                hash ^= Title.GetHashCode();
            }
            if (ProducerProjectId.Length != 0)
            {
                hash ^= ProducerProjectId.GetHashCode();
            }
            hash ^= apis_.GetHashCode();
            hash ^= types_.GetHashCode();
            hash ^= enums_.GetHashCode();
            if (documentation_ != null)
            {
                hash ^= Documentation.GetHashCode();
            }
            if (backend_ != null)
            {
                hash ^= Backend.GetHashCode();
            }
            if (http_ != null)
            {
                hash ^= Http.GetHashCode();
            }
            if (quota_ != null)
            {
                hash ^= Quota.GetHashCode();
            }
            if (authentication_ != null)
            {
                hash ^= Authentication.GetHashCode();
            }
            if (context_ != null)
            {
                hash ^= Context.GetHashCode();
            }
            if (usage_ != null)
            {
                hash ^= Usage.GetHashCode();
            }
            hash ^= endpoints_.GetHashCode();
            if (control_ != null)
            {
                hash ^= Control.GetHashCode();
            }
            hash ^= logs_.GetHashCode();
            hash ^= metrics_.GetHashCode();
            hash ^= monitoredResources_.GetHashCode();
            if (logging_ != null)
            {
                hash ^= Logging.GetHashCode();
            }
            if (monitoring_ != null)
            {
                hash ^= Monitoring.GetHashCode();
            }
            if (systemParameters_ != null)
            {
                hash ^= SystemParameters.GetHashCode();
            }
            if (sourceInfo_ != null)
            {
                hash ^= SourceInfo.GetHashCode();
            }
            if (experimental_ != null)
            {
                hash ^= Experimental.GetHashCode();
            }
            return(hash);
        }
        public void Test__GetConfigVersionInternal__ReturnsExpected(string semVer, ConfigVersion expected)
        {
            ConfigVersion actual = ConfigurationUtility.GetConfigVersionInternal(semVer);

            Assert.AreEqual(expected, actual);
        }
        public void Test__IsVersionMatch__ReturnsExpected(string semVer, ConfigVersion version, bool expected)
        {
            bool actual = ConfigurationUtility.IsVersionMatch(semVer, version);

            Assert.AreEqual(expected, actual);
        }
示例#12
0
 public bool Equals(Asp330Device that)
 {
     if (that is null)
     {
         return(false);
     }
     if (ReferenceEquals(this, that))
     {
         return(true);
     }
     if (!Asp330TestId.Equals(that.Asp330TestId))
     {
         return(false);
     }
     if (!Asp330Sn.Equals(that.Asp330Sn))
     {
         return(false);
     }
     if (!Asp330Model.Equals(that.Asp330Model))
     {
         return(false);
     }
     if (!SamSn.Equals(that.SamSn))
     {
         return(false);
     }
     if (!LcdContrast.Equals(that.LcdContrast))
     {
         return(false);
     }
     if (!CpuSn.Equals(that.CpuSn))
     {
         return(false);
     }
     if (!UimSn.Equals(that.UimSn))
     {
         return(false);
     }
     if (!PimSn.Equals(that.PimSn))
     {
         return(false);
     }
     if (!Asp330Firmware.Equals(that.Asp330Firmware))
     {
         return(false);
     }
     if (!BootVersion.Equals(that.BootVersion))
     {
         return(false);
     }
     if (!LangVersion.Equals(that.LangVersion))
     {
         return(false);
     }
     if (!ConfigVersion.Equals(that.ConfigVersion))
     {
         return(false);
     }
     if (!ConfigFileNumber.Equals(that.ConfigFileNumber))
     {
         return(false);
     }
     if (!Note.Equals(that.Note))
     {
         return(false);
     }
     if (!ResultCheckBox.Equals(that.ResultCheckBox))
     {
         return(false);
     }
     return(true);
 }