public bool Check(IUiInteraction uiProvider) { try { var value = ConfigurationManager.AppSettings[this.assemblyName + "-VersionCheck"]; bool doCheck; if (bool.TryParse(value, out doCheck)) { if (!doCheck) { return(true); } } var myVersion = new VersionCheck(); var formatter = new XmlSerializer(typeof(VersionCheck)); var httpHelper = new HttpHelper(VersionBaseUrl, false) { UiDispatcher = uiProvider }; var versionContentFromServer = httpHelper.GetContent(VersionXmlUrl, "[NOCACHE]"); if (!string.IsNullOrEmpty(versionContentFromServer)) { var reader = new StringReader(versionContentFromServer); var serverVersion = (VersionCheck)formatter.Deserialize(reader); return(serverVersion.IsLessOrEqual(myVersion)); } return(true); } catch { // catch simply all - if there's a problem, we will check next time return(true); } }
/// <summary> /// Performs a comparison of two version information structures by comparing /// major and minor version and revision (1.2.3.4 vs. 4.5.6.7). Revision and /// build will not be compared. /// </summary> /// <param name="greaterInstance"> /// the version to compare to /// </param> /// <returns> /// true in case of this instance <= <paramref name="greaterInstance"/> /// </returns> public bool IsLessOrEqual(VersionCheck greaterInstance) { if (this.Major > greaterInstance.Major) { return(false); } if (this.Major < greaterInstance.Major) { return(true); } if (this.Minor > greaterInstance.Minor) { return(false); } if (this.Minor < greaterInstance.Minor) { return(true); } return(true); }