Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.24 KB | None | 0 0
  1. using System;
  2. using System.Data;
  3. using System.Linq;
  4. using Newtonsoft.Json.Linq;
  5.  
  6. namespace ConsoleApplication8
  7. {
  8. public struct VmSize
  9. {
  10. public string Name;
  11. public int Cores;
  12. public int MemoryMb;
  13. public int DataDiskLimit;
  14. //public string Label;
  15. public string Tier;
  16. public bool V2;
  17. public string Size;
  18. public bool PremiumDisk;
  19. public string Series;
  20. public bool Promo;
  21.  
  22. //"name": "Standard_M128s",
  23. //"numberOfCores": 128,
  24. //"osDiskSizeInMB": 1047552,
  25. //"resourceDiskSizeInMB": 4096000,
  26. //"memoryInMB": 2048000,
  27. //"maxDataDiskCount": 64
  28.  
  29. public VmSize(DataRow row)
  30. {
  31. Name = row["InstanceSize"].ToString();
  32. var n = Name.ToLower();
  33. var np = n.Split('_');
  34. var std = n.Contains("_");
  35.  
  36. Cores = int.Parse(row["Cores"].ToString());
  37. MemoryMb = int.Parse(row["MemoryInMb"].ToString());
  38. DataDiskLimit = int.Parse(row["MaxDataDiskCount"].ToString());
  39. //Label = row["RoleSizeLabel"].ToString();
  40. V2 = n.Contains("_v2");
  41. Tier = std ? np[0] : "Standard";
  42. Size = Name;
  43. PremiumDisk = false;
  44. if (std)
  45. {
  46. Size = np[1];
  47. PremiumDisk = Size.ToLower().Contains("s");
  48. }
  49. Promo = Name.IndexOf("Promo", StringComparison.OrdinalIgnoreCase) > -1;
  50.  
  51. switch (np.Length)
  52. {
  53. case 1: // basic VM, e.g., A0
  54. {
  55. Series = np[0];
  56. break;
  57. }
  58. case 2: // standard VM, e.g., Standard_DS2
  59. {
  60. Series = np[1];
  61. break;
  62. }
  63. case 3: // standard versioned vm e.g., Standard_DS2_v2
  64. {
  65. Series = $"{np[1]}{np[2]}";
  66. break;
  67. }
  68. case 4: // standard versioned vm special rate, e.g., Standard_DS2_v2_Promo
  69. {
  70. Series = $"{np[1]}{np[2]}";
  71. break;
  72. }
  73. default:
  74. {
  75. Series = np[0];
  76. break;
  77. }
  78. }
  79. Console.WriteLine($"{n}:{Series}");
  80. }
  81.  
  82. public VmSize(JToken row)
  83. {
  84. Name = row["name"].ToString();
  85. var n = Name.ToLower();
  86. var np = n.Split('_');
  87. var std = n.Contains("_");
  88. Cores = int.Parse(row["numberOfCores"].ToString());
  89. MemoryMb = int.Parse(row["memoryInMB"].ToString());
  90. DataDiskLimit = int.Parse(row["maxDataDiskCount"].ToString());
  91. //Label = row["RoleSizeLabel"].ToString();
  92. V2 = n.Contains("_v2");
  93. Tier = std ? np[0] : "Standard";
  94. Size = Name;
  95. PremiumDisk = false;
  96. Series = "";
  97. if (std)
  98. {
  99. Size = string.Join("_", np.Skip(1));
  100. PremiumDisk = Size.ToLower().Contains("s");
  101. }
  102. Promo = Name.IndexOf("Promo", StringComparison.OrdinalIgnoreCase) > -1;
  103.  
  104. switch (np.Length)
  105. {
  106. case 1: // basic VM, e.g., A0
  107. {
  108. Series = np[0];
  109. break;
  110. }
  111. case 2: // standard VM, e.g., Standard_DS2
  112. {
  113. Series = np[1];
  114. break;
  115. }
  116. case 3: // standard versioned vm e.g., Standard_DS2_v2
  117. {
  118. Series = $"{np[1]}{np[2]}";
  119. break;
  120. }
  121. case 4: // standard versioned vm special rate, e.g., Standard_DS2_v2_Promo
  122. {
  123. Series = $"{np[1]}{np[2]}";
  124. break;
  125. }
  126. default:
  127. {
  128. Series = np[0];
  129. break;
  130. }
  131. }
  132. }
  133. }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement