public static void RegisterVersion(Version version, DateTime releaseDate, ReleaseMode mode) { var newv = new VersionMetaData() { Version = version, ReleaseDate = releaseDate, Mode = mode }; if (_versionData.ContainsKey(version)) { throw new ArgumentException("Can't register version " + version + " it is already registered.", "version"); } if (mode == ReleaseMode.Test && _versionData.Any(x => x.Value.Mode == ReleaseMode.Test)) { throw new ArgumentException("Can't have multiple versions in Test at once", "mode"); } _versionData.Add(version, newv); // Process versions // Reorder _versionData = _versionData.OrderByDescending(x => x.Key).ToDictionary(x => x.Key, x => x.Value); // Set all proper delete times VersionMetaData latestLive = null; VersionMetaData prevLive = null; foreach (var v in _versionData) { if (latestLive == null && v.Value.Mode == ReleaseMode.Live) { v.Value.DeleteDate = DateTime.MaxValue; prevLive = v.Value; latestLive = v.Value; continue; } // the version directly below the most recent version should not expire (we will always allow at least 2 API versions at any given time) if (prevLive.Version == version) { v.Value.DeleteDate = DateTime.MaxValue; prevLive = v.Value; continue; } if (v.Value.Mode == ReleaseMode.Test) { v.Value.DeleteDate = DateTime.MaxValue; continue; } // It should actually use the release b4 it v.Value.DeleteDate = prevLive.ReleaseDate.AddMonths(6); prevLive = v.Value; } }
public static void RegisterVersion(Version version, DateTime releaseDate, ReleaseMode mode) { var newv = new VersionMetaData() { Version = version, ReleaseDate = releaseDate, Mode = mode }; if (_versionData.ContainsKey(version)) { throw new ArgumentException("Can't register version " + version + " it is already registered.", "version"); } if (mode == ReleaseMode.Test && _versionData.Any(x => x.Value.Mode == ReleaseMode.Test)) { throw new ArgumentException("Can't have multiple versions in Test at once", "mode"); } _versionData.Add(version, newv); // Process versions // Reorder _versionData = _versionData.OrderByDescending(x => x.Key).ToDictionary(x => x.Key, x => x.Value); // Set all proper delete times var foundLive = false; var i = 0; foreach (var v in _versionData) { if (foundLive == false && i != 2 && v.Value.Mode == ReleaseMode.Live) { v.Value.DeleteDate = DateTime.MaxValue; foundLive = true; i++; continue; } if (v.Value.Mode == ReleaseMode.Test) { v.Value.DeleteDate = DateTime.MaxValue; i++; continue; } v.Value.DeleteDate = v.Value.ReleaseDate.AddMonths(6); i++; } }