public bool Match(string suppliedValue, RolloutStrategyAttribute attr) { var vals = attr.Values.Where(v => v != null).Select(v => new Version(v.ToString())).ToList(); var version = new Version(suppliedValue); switch (attr.Conditional) { case RolloutStrategyAttributeConditional.EQUALS: case RolloutStrategyAttributeConditional.INCLUDES: return(vals.Any(v => version.Equals(v))); case RolloutStrategyAttributeConditional.ENDSWITH: break; case RolloutStrategyAttributeConditional.STARTSWITH: break; case RolloutStrategyAttributeConditional.GREATER: return(vals.Any(v => version.CompareTo(v) > 0)); case RolloutStrategyAttributeConditional.GREATEREQUALS: return(vals.Any(v => version.CompareTo(v) >= 0)); case RolloutStrategyAttributeConditional.LESS: return(vals.Any(v => version.CompareTo(v) < 0)); case RolloutStrategyAttributeConditional.LESSEQUALS: return(vals.Any(v => version.CompareTo(v) <= 0)); case RolloutStrategyAttributeConditional.NOTEQUALS: case RolloutStrategyAttributeConditional.EXCLUDES: return(!vals.Any(v => version.Equals(v))); case RolloutStrategyAttributeConditional.REGEX: break; case null: return(false); default: return(false); } return(false); }
public async Task StartAsync() { Release latestRelease = null; SemVer.Version latestVersion; if (!_localInstall) { if (File.Exists(Path.Combine(Directory.GetCurrentDirectory(), "LMS.Setup.exe"))) { Log.Debug("Setup file exists. let's go ahead and remove that."); File.Delete("LMS.Setup.exe"); } latestRelease = await GitHubOperations.GetLatestRelease(); latestVersion = GitHubOperations.GetLatestVersion(latestRelease); } else { latestVersion = new SemVer.Version(FileVersionInfo.GetVersionInfo(_setupFilename).ProductVersion); } SemVer.Version currentVersion = GetCurrentInstalledVersion(); Log.Information($"Installed: {currentVersion} Available: {latestVersion}"); if (currentVersion.CompareTo(latestVersion) < 0) { if (currentVersion.Equals(new SemVer.Version(1, 0, 0))) { Log.Debug("New installation."); if (_localInstall) { UpdateRequired(); } else { await UpdateRequired(latestRelease); } return; } Log.Debug("Existing installation."); Uninstall(); if (_localInstall) { UpdateRequired(); } else { await UpdateRequired(latestRelease); } return; } if (currentVersion.CompareTo(latestVersion) > 0) { Log.Warning("The installed version is newer than what is currently available."); Log.Warning("I'm going to uninstall the program."); Uninstall(); if (_localInstall) { UpdateRequired(); } else { await UpdateRequired(latestRelease); } return; } if (currentVersion.CompareTo(latestVersion) == 0) { Log.Information("No update is required at this time."); Log.Information("Checking installation folder integrity."); if (File.Exists(Path.Combine(GetProgramFilesPath(), "License Monitoring System", "LMS.exe"))) { Log.Information("All looks good!"); return; } Log.Warning("Executable is missing from the installation folder."); Log.Warning("Attempting to reinstall the application."); Uninstall(); if (_localInstall) { UpdateRequired(); } else { await UpdateRequired(latestRelease); } } }