/// <summary> /// /// </summary> /// <param name="json"></param> /// <returns></returns> public string Upgrade(string json) { // Determine the latest version supported by this upgrader List <System.Version> knownVersions = new List <System.Version>(); foreach (var u in upgraders) { knownVersions.Add(ImportUpgradeManager.ParseVersion(u.Key)); } System.Version latestVersion = knownVersions.Max(x => x); // Determine the version of the data JObject j = JObject.Parse(json); JToken versionToken = j.SelectToken("jCSET_VERSION[0].Version_Id"); if (versionToken == null) { throw new ApplicationException("Version could not be identifed corrupted assessment json"); } System.Version version = ConvertFromStringToVersion(versionToken.Value <string>()); version = NormalizeVersion(version); // correct version notation if necessary if (version == new System.Version("9.21.0.0")) { version = new System.Version("9.2.1.0"); } if (version == new System.Version("9.23.0.0")) { version = new System.Version("9.2.3.0"); } if (version == new System.Version("10.11.0.0")) { version = new System.Version("10.1.1.0"); } while (version < latestVersion) { ICSETJSONFileUpgrade fileUpgrade = upgraders[version.ToString()]; if (fileUpgrade != null) { json = fileUpgrade.ExecuteUpgrade(json); version = NormalizeVersion(fileUpgrade.GetVersion()); } } return(json); }
/// <summary> /// Determines if the import is from an older (pre 10.2) version /// and if it used the old pseudo-standard "ACET_V1". /// </summary> /// <returns></returns> private bool DetermineIfAcetPre10_2(JObject oAssessment) { var v = oAssessment.SelectTokens("$.jCSET_VERSION[*].Version_Id").FirstOrDefault().Value <string>(); var version = ImportUpgradeManager.ParseVersion(v); var usesAcetStandard = oAssessment.SelectTokens("$.jAVAILABLE_STANDARDS[*]") .Where(x => x["Set_Name"].Value <string>() == "ACET_V1" && x["Selected"].Value <Boolean>()).Any(); if (version < ImportUpgradeManager.ParseVersion("10.2") && usesAcetStandard) { return(true); } return(false); }
/// <summary> /// /// </summary> /// <returns></returns> public System.Version GetVersion() { return(ImportUpgradeManager.ParseVersion(versionString)); }