/// <summary> /// Returns the current version based on specified versioning style. /// </summary> /// <param name="versions"> /// The versions. /// </param> /// <param name="versioningStyle"> /// The versioning style. /// </param> /// <returns> /// The current version. /// </returns> /// <exception cref="ArgumentNullException"> /// The <paramref name="versions"/> parameter is null. /// </exception> public static string GetCurrentVersion(ICollection<ProcessVersionInfo> versions, VersioningStyles versioningStyle) { if (versions == null || versions.Count == 0) { return null; } if (versioningStyle == VersioningStyles.Alphanumeric) { var versionInfo = versions.OrderByDescending(v => v.Id).First(); return versionInfo.VersionNumber; } return versions.Where(v => v.VersionNumber.Trim().Length == versions.Max(v1 => v1.VersionNumber.Trim().Length)).Max(v => v.VersionNumber.Trim()); }
/// <summary> /// Returns next version (numeric or char) based on input /// </summary> /// <param name="currentVersion">The current version.</param> /// <param name="versioningStyle">The versioning style.</param> /// <returns>next version</returns> /// <exception cref="System.ArgumentException"> /// Can not create version based on an empty string /// or /// Version must start with number or letter /// </exception> public static string GetNextVersion(string currentVersion, VersioningStyles? versioningStyle = null) { if (string.IsNullOrEmpty(currentVersion)) throw new ArgumentException("Can not create version based on an empty string", currentVersion); currentVersion = currentVersion.Trim(); if (versioningStyle == VersioningStyles.Alphanumeric) return NextAlphanumericVersionStyle(currentVersion); // We ignore the versioningStyle parameter for Char and Numeric styles // because it was added later, when the Alphanumeric style was added. if (currentVersion.All(char.IsNumber)) return NextNumericVersionStyle(currentVersion); if (currentVersion.All(char.IsLetter)) return NextCharVersionStyle(currentVersion); if (currentVersion.All(IsAlphanumeric)) return NextAlphanumericVersionStyle(currentVersion); throw new ArgumentException("Invalid version number.", "currentVersion"); }