/// <summary> /// Returns a list of the oldest Semantic versions, keeping a minimum number of the newest as well as keeping anything newer than the minAgeToKeep. Basically keeps anything newer than MinAgeToKeep and then numberOfNewestToKeep after that. /// <para>It divides the list into 2 buckets. Those that meet the age requirement, are considered 1 entry. The 2nd bucket it NumberOfNewestToKeep minus 1. So if NumberOfNewest is 4 and 7 items meet the age requirement we could /// potentially keep the 7 newest plus 3 more (4 to keep minus the 7 newest (But we treat the 7 as 1 entry) for a total of 10 items...</para> /// </summary> /// <param name="numberOfNewestToKeep">The minimum number of the newest versions that should be kept</param> /// <param name="minAgeToKeep">The minimum age from right now that forces us to keep all of these versions. For instance 3d would ensure that any version that is newer than 3 days would be kept.</param> /// <returns></returns> public List <FileSemVer> OldestWithMinAge(int numberOfNewestToKeep, TimeUnit minAgeToKeep) { // A. First just get the oldest that meet the minimum number to keep List <FileSemVer> oldest = OldestWithMin(numberOfNewestToKeep); int startingCount = oldest.Count; long seconds = -1 * (minAgeToKeep.InSecondsLong); DateTime threshold = DateTime.Now.AddSeconds(seconds); // B. Now go thru the list and remove any that are newer than the age requirement. for (int i = oldest.Count - 1; i >= 0; i--) { FileSemVer fileSemVer = oldest [i]; DateTime created = _fileSystem.File.GetCreationTime(fileSemVer.FileName); // If the item does not meet the minimum age requirement we delete it from the list. if (created > threshold) { oldest.RemoveAt(i); } } // C. Now remove any that do not meet the numberOfNewestToKeep. // We treat all the min age versions as though they were just 1 version. if (oldest.Count != startingCount) { numberOfNewestToKeep--; return(OldestWithMin(numberOfNewestToKeep, oldest)); } return(oldest); }
/// <summary> /// Returns the latest FileSemVer Version # /// </summary> /// <returns>Null if no Versions matching criteria are found.</returns> public FileSemVer DirectoryMostRecentVersion() { if (!IsInitialized) { throw new ApplicationException("The SemVerUtil object has not been initialized."); } if (_versions.Count == 0) { return(null); } FileSemVer lastEntry = _versions.Last(); return(lastEntry); }