Version.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using Microsoft.Office.Interop.Excel;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace Fuel01
  8. {
  9. public class Version
  10. {
  11. public Version(int principal, int secondary, int revision, int build)
  12. {
  13. Principal = principal;
  14. Secondary = secondary;
  15. Revision = revision;
  16. Build = build;
  17. }
  18. public Version(string version)
  19. {
  20. var versionDetails = version.Split('.');
  21. if (versionDetails.Length == 4)
  22. {
  23. Principal = Convert.ToInt32(versionDetails[0]);
  24. Secondary = Convert.ToInt32(versionDetails[1]);
  25. Revision = Convert.ToInt32(versionDetails[2]);
  26. Build = Convert.ToInt32(versionDetails[3]);
  27. }
  28. }
  29. public Version(string principal, string secondary, string revision, string build)
  30. {
  31. Principal = Convert.ToInt32(principal);
  32. Secondary = Convert.ToInt32(secondary);
  33. Revision = Convert.ToInt32(revision);
  34. Build = Convert.ToInt32(build);
  35. }
  36. public int Build { get; set; }
  37. public int Principal { get; set; }
  38. public int Revision { get; set; }
  39. public int Secondary { get; set; }
  40. public static double MakeVersionCompareNumber(double v1, double v2, double v3, double v4)
  41. => v1 * Math.Pow(10, 9) + v2 * Math.Pow(10, 6) + v3 * Math.Pow(10, 3) + v4;
  42. public static string NextVersion(int principal, int secondary, int revision, int build)
  43. {
  44. if (build < 98)
  45. {
  46. build = 0;
  47. revision++;
  48. }
  49. else
  50. {
  51. build++;
  52. }
  53. if (revision == 100)
  54. {
  55. revision = 0;
  56. secondary ++;
  57. }
  58. if (secondary == 100)
  59. {
  60. secondary = 0;
  61. principal ++;
  62. }
  63. return VersionString(principal, secondary, revision, build);
  64. }
  65. public static string NextVersion(string version)
  66. {
  67. var versionDetails = version.Split('.');
  68. if (versionDetails.Length == 4)
  69. {
  70. var ver2 = new Version(versionDetails[0], versionDetails[1], versionDetails[2], versionDetails[3]);
  71. var ver3 = NextVersion(ver2);
  72. return ver3;
  73. }
  74. else
  75. {
  76. return string.Empty;
  77. }
  78. }
  79. public static string NextVersion(Version version)
  80. {
  81. return NextVersion(version.Principal, version.Secondary, version.Revision, version.Build);
  82. }
  83. public static string VersionString(string p, string s, string r, string b) => $"{p}.{s}.{r}.{b}";
  84. public static string VersionString(int p, int s, int r, int b) => $"{p}.{s}.{r}.{b}";
  85. public Version NextVersion()
  86. {
  87. if (Build < 98)
  88. {
  89. Build++;
  90. return this;
  91. }
  92. else
  93. {
  94. Build = 0;
  95. Revision++;
  96. }
  97. if (Revision == 100)
  98. {
  99. Revision = 0;
  100. Secondary++;
  101. }
  102. if (Secondary == 100)
  103. {
  104. Secondary = 0;
  105. Principal++;
  106. }
  107. return this;
  108. }
  109. public override string ToString() => $"{Principal}.{Secondary}.{Revision}.{Build}";
  110. public bool VersionIsSup(Version v1)
  111. {
  112. return MakeVersionCompareNumber(Principal, Secondary, Revision, Build) > MakeVersionCompareNumber(v1.Principal, v1.Secondary, v1.Revision, v1.Build);
  113. }
  114. }
  115. }