/Misc/DevOps/Tools/Aclara.Azure.Automation.Sidekicks.WinForm/Configuration/SidekickConfigurationManager.cs

https://bitbucket.org/jeffmccommas/acex · C# · 504 lines · 293 code · 122 blank · 89 comment · 0 complexity · d45b92ad4dc6478c2b49352bd6d31832 MD5 · raw file

  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace Aclara.Azure.Automation.Sidekicks.WinForm.Configuration
  9. {
  10. public class SidekickConfigurationManager
  11. {
  12. #region Private Constants
  13. #endregion
  14. #region Private Data Members
  15. private string _configurationFileName;
  16. private string _configurationFilePath;
  17. private SidekickConfiguration _sidekickConfiguration;
  18. #endregion
  19. #region Public Properties
  20. /// <summary>
  21. /// Property: Configuration file name.
  22. /// </summary>
  23. public string ConfigurationFileName
  24. {
  25. get { return _configurationFileName; }
  26. set { _configurationFileName = value; }
  27. }
  28. /// <summary>
  29. /// Property: Configuration file path.
  30. /// </summary>
  31. public string ConfigurationFilePath
  32. {
  33. get { return _configurationFilePath; }
  34. set { _configurationFilePath = value; }
  35. }
  36. /// <summary>
  37. /// Property: Sidekick configuration.
  38. /// </summary>
  39. public SidekickConfiguration SidekickConfiguration
  40. {
  41. get { return _sidekickConfiguration; }
  42. set { _sidekickConfiguration = value; }
  43. }
  44. #endregion
  45. #region Public Constructors
  46. /// <summary>
  47. /// Preferred constructor.
  48. /// </summary>
  49. /// <param name="configurationFileName"></param>
  50. /// <param name="configurationFilePath"></param>
  51. public SidekickConfigurationManager(string configurationFileName, string configurationFilePath)
  52. {
  53. _configurationFileName = configurationFileName;
  54. _configurationFilePath = configurationFilePath;
  55. _sidekickConfiguration = new SidekickConfiguration();
  56. }
  57. #endregion
  58. #region Private Constructors
  59. /// <summary>
  60. /// Default constructor.
  61. /// </summary>
  62. public SidekickConfigurationManager()
  63. {
  64. }
  65. #endregion
  66. #region Public Methods
  67. public void InitializeConfiguration()
  68. {
  69. string configurationPathFileName = string.Empty;
  70. try
  71. {
  72. configurationPathFileName = Path.Combine(this.ConfigurationFilePath, this.ConfigurationFileName);
  73. using (StreamReader file = File.OpenText(configurationPathFileName))
  74. {
  75. JsonSerializer serializer = new JsonSerializer();
  76. this.SidekickConfiguration = (SidekickConfiguration)serializer.Deserialize(file, typeof(SidekickConfiguration));
  77. }
  78. }
  79. catch (Exception)
  80. {
  81. throw;
  82. }
  83. }
  84. #endregion
  85. #region Protected Methods
  86. #endregion
  87. #region Private Methods
  88. #endregion
  89. }
  90. public class SidekickConfiguration
  91. {
  92. [JsonProperty("Documents")]
  93. public Documents Documents { get; set; }
  94. [JsonProperty("AzureStorageAccount")]
  95. public AzureStorageAccountConnectionInfo AzureStorageAccount { get; set; }
  96. [JsonProperty("CassandraConnectionInfo")]
  97. public CassandraConnectionInfo CassandraConnectionInfo { get; set; }
  98. [JsonProperty("AzureRedisCacheConnectionInfo")]
  99. public AzureRedisCacheConnectionInfo RedisCacheConnectionInfo { get; set; }
  100. [JsonProperty("AzurePowerBIConnectionInfo")]
  101. public AzurePowerBIConnectionInfo AzurePowerBIConnectionInfo { get; set; }
  102. [JsonProperty("AzureCloudServiceInfo")]
  103. public AzureCloudServiceInfo AzureCloudServiceInfo { get; set; }
  104. [JsonProperty("ComponentInfo")]
  105. public ComponentInfo ComponentInfo { get; set; }
  106. }
  107. public class Documents
  108. {
  109. [JsonProperty("Document")]
  110. public List<Document> Document { get; set; }
  111. }
  112. /// <summary>
  113. /// Document configuration information.
  114. /// </summary>
  115. public class Document
  116. {
  117. [JsonProperty("Name")]
  118. public string Name { get; set; }
  119. [JsonProperty("FileName")]
  120. public string FileName { get; set; }
  121. [JsonProperty("Path")]
  122. public string Path { get; set; }
  123. [JsonProperty("Visible")]
  124. public string Visible { get; set; }
  125. }
  126. /// <summary>
  127. /// Azure storage account connection info.
  128. /// </summary>
  129. public class AzureStorageAccountConnectionInfo
  130. {
  131. [JsonProperty("AzureSubscription")]
  132. public List<AzureStorageAccount_AzureSubscription> AzureSubscription { get; set; }
  133. }
  134. /// <summary>
  135. /// Azure storage account connection info.
  136. /// </summary>
  137. public class AzureStorageAccount_AzureSubscription
  138. {
  139. [JsonProperty("SubscriptionName")]
  140. public string SubscriptionName { get; set; }
  141. [JsonProperty("Environment")]
  142. public List<AzureStorageAccount_Environment> Environment { get; set; }
  143. }
  144. /// <summary>
  145. /// Azure storage connection info: Environment.
  146. /// </summary>
  147. public class AzureStorageAccount_Environment
  148. {
  149. [JsonProperty("Name")]
  150. public string Name { get; set; }
  151. [JsonProperty("AccessKey")]
  152. public string AccessKey { get; set; }
  153. }
  154. /// <summary>
  155. /// Cassandra connection info.
  156. /// </summary>
  157. public class CassandraConnectionInfo
  158. {
  159. [JsonProperty("AzureSubscription")]
  160. public List<CassandraConnectionInfo_AzureSubscription> AzureSubscription { get; set; }
  161. }
  162. /// <summary>
  163. /// Cassandra connection info.
  164. /// </summary>
  165. public class CassandraConnectionInfo_AzureSubscription
  166. {
  167. [JsonProperty("SubscriptionName")]
  168. public string SubscriptionName { get; set; }
  169. [JsonProperty("Environment")]
  170. public List<CassandraConnectionInfo_Environment> Environment { get; set; }
  171. }
  172. /// <summary>
  173. /// Cassandra connection info: Environment.
  174. /// </summary>
  175. public class CassandraConnectionInfo_Environment
  176. {
  177. [JsonProperty("Name")]
  178. public string Name { get; set; }
  179. [JsonProperty("CassandraNodes")]
  180. public string CassandraNodes { get; set; }
  181. [JsonProperty("CassandraKeyspace")]
  182. public string CassandraKeyspace { get; set; }
  183. [JsonProperty("CassandraNodeUsername")]
  184. public string CassandraNodeUsername { get; set; }
  185. [JsonProperty("CassandraNodePassword")]
  186. public string CassandraNodePassword { get; set; }
  187. }
  188. /// <summary>
  189. /// Azure Redis cache connection info.
  190. /// </summary>
  191. public class AzureRedisCacheConnectionInfo
  192. {
  193. [JsonProperty("AzureSubscription")]
  194. public List<AzureRedisCacheConnectionInfo_AzureSubscription> AzureSubscription { get; set; }
  195. }
  196. /// <summary>
  197. /// Azure Redis cache connection info.
  198. /// </summary>
  199. public class AzureRedisCacheConnectionInfo_AzureSubscription
  200. {
  201. [JsonProperty("SubscriptionName")]
  202. public string SubscriptionName { get; set; }
  203. [JsonProperty("Environment")]
  204. public List<AzureRedisCacheConnectionInfo_Environment> Environment { get; set; }
  205. }
  206. /// <summary>
  207. /// Azure Redis cache connection info: Environment.
  208. /// </summary>
  209. public class AzureRedisCacheConnectionInfo_Environment
  210. {
  211. [JsonProperty("Name")]
  212. public string Name { get; set; }
  213. [JsonProperty("RedisCache")]
  214. public List<AzureRedisCacheConnectionInfo_RedisCache> RedisCache { get; set; }
  215. }
  216. /// <summary>
  217. /// Azure Redis cache connection info: Environment.
  218. /// </summary>
  219. public class AzureRedisCacheConnectionInfo_RedisCache
  220. {
  221. [JsonProperty("RedisCacheName")]
  222. public string RedisCacheName { get; set; }
  223. [JsonProperty("Endpoint")]
  224. public string Endpoint { get; set; }
  225. [JsonProperty("Password")]
  226. public string Password { get; set; }
  227. [JsonProperty("SSL")]
  228. public bool SSL { get; set; }
  229. [JsonProperty("ConnectRetry")]
  230. public int ConnectRetry { get; set; }
  231. [JsonProperty("ConnectTimeout")]
  232. public int ConnectTimeout { get; set; }
  233. [JsonProperty("SyncTimeout")]
  234. public int SyncTimeout { get; set; }
  235. }
  236. /// <summary>
  237. /// Azure PowerBI connection info.
  238. /// </summary>
  239. public class AzurePowerBIConnectionInfo
  240. {
  241. [JsonProperty("AzureSubscription")]
  242. public List<AzurePowerBIConnectionInfo_AzureSubscription> AzureSubscription { get; set; }
  243. }
  244. /// <summary>
  245. /// Azure PowerBI connection info.
  246. /// </summary>
  247. public class AzurePowerBIConnectionInfo_AzureSubscription
  248. {
  249. [JsonProperty("SubscriptionName")]
  250. public string SubscriptionName { get; set; }
  251. [JsonProperty("Environment")]
  252. public List<AzurePowerBIConnectionInfo_Environment> Environment { get; set; }
  253. }
  254. /// <summary>
  255. /// Azure PowerBI connection info: Environment.
  256. /// </summary>
  257. public class AzurePowerBIConnectionInfo_Environment
  258. {
  259. [JsonProperty("Name")]
  260. public string Name { get; set; }
  261. [JsonProperty("PowerBI")]
  262. public List<AzurePowerBIConnectionInfo_PowerBI> PowerBI { get; set; }
  263. }
  264. /// <summary>
  265. /// Azure PowewrBI connection info: Environment.
  266. /// </summary>
  267. public class AzurePowerBIConnectionInfo_PowerBI
  268. {
  269. [JsonProperty("PowerBIApiEndpoint")]
  270. public string PowerBIApiEndpoint { get; set; }
  271. [JsonProperty("AzureApiEndpoint")]
  272. public string AzureApiEndpoint { get; set; }
  273. [JsonProperty("WorkspaceCollectionName")]
  274. public string WorkspaceCollectionName { get; set; }
  275. [JsonProperty("WorkspaceCollectionAccessKey")]
  276. public string WorkspaceCollectionAccessKey { get; set; }
  277. }
  278. /// <summary>
  279. /// Azure cloud service info.
  280. /// </summary>
  281. public class AzureCloudServiceInfo
  282. {
  283. [JsonProperty("AzureSubscription")]
  284. public List<AzureCloudServiceInfo_AzureSubscription> AzureSubscription { get; set; }
  285. }
  286. /// <summary>
  287. /// Azure cloud service info: Azure subscription.
  288. /// </summary>
  289. public class AzureCloudServiceInfo_AzureSubscription
  290. {
  291. [JsonProperty("SubscriptionName")]
  292. public string SubscriptionName { get; set; }
  293. [JsonProperty("Environment")]
  294. public List<AzureCloudServiceInfo_Environment> Environment { get; set; }
  295. }
  296. /// <summary>
  297. /// Azure cloud service info: Environment.
  298. /// </summary>
  299. public class AzureCloudServiceInfo_Environment
  300. {
  301. [JsonProperty("Name")]
  302. public string Name { get; set; }
  303. [JsonProperty("CloudService")]
  304. public List<AzureCloudServiceInfo_CloudService> CloudService { get; set; }
  305. }
  306. /// <summary>
  307. /// Azure cloud service info: Cloud service.
  308. /// </summary>
  309. public class AzureCloudServiceInfo_CloudService
  310. {
  311. [JsonProperty("ServiceName")]
  312. public string ServiceName { get; set; }
  313. [JsonProperty("Slot")]
  314. public string Slot { get; set; }
  315. [JsonProperty("InstanceCountScaleUp")]
  316. public int InstanceCountScaleUp { get; set; }
  317. [JsonProperty("InstanceCountScaleDown")]
  318. public int InstanceCountScaleDown { get; set; }
  319. }
  320. /// <summary>
  321. /// Component information.
  322. /// </summary>
  323. public class ComponentInfo
  324. {
  325. [JsonProperty("ClientOSList")]
  326. public ComponentInfo_ClientOSList ClientOSList { get; set; }
  327. }
  328. /// <summary>
  329. /// Client OS.
  330. /// </summary>
  331. public class ComponentInfo_ClientOSList
  332. {
  333. [JsonProperty("ClientOS")]
  334. public List<ComponentInfo_ClientOS> ClientOS { get; set; }
  335. }
  336. /// <summary>
  337. /// Client OS.
  338. /// </summary>
  339. public class ComponentInfo_ClientOS
  340. {
  341. [JsonProperty("Name")]
  342. public string Name { get; set; }
  343. [JsonProperty("VersionMajor")]
  344. public int VersionMajor { get; set; }
  345. [JsonProperty("VersionMinor")]
  346. public int VersionMinor { get; set; }
  347. [JsonProperty("ComponentList")]
  348. public ComponentInfo_ComponentList ComponentList { get; set; }
  349. }
  350. /// <summary>
  351. /// Component list.
  352. /// </summary>
  353. public class ComponentInfo_ComponentList
  354. {
  355. [JsonProperty("Component")]
  356. public List<ComponentInfo_Component> Component { get; set; }
  357. }
  358. /// <summary>
  359. /// Component.
  360. /// </summary>
  361. public class ComponentInfo_Component
  362. {
  363. [JsonProperty("Name")]
  364. public string Name { get; set; }
  365. [JsonProperty("Description")]
  366. public string Description { get; set; }
  367. [JsonProperty("MinimumVersion")]
  368. public string MinimumVersion { get; set; }
  369. [JsonProperty("Provider")]
  370. public string Provider { get; set; }
  371. [JsonProperty("HelpKeyword")]
  372. public string HelpKeyword { get; set; }
  373. [JsonProperty("Required")]
  374. public bool Required { get; set; }
  375. [JsonProperty("LoginRequired")]
  376. public bool LoginRequired { get; set; }
  377. [JsonProperty("InstallerPath")]
  378. public string InstallerPath { get; set; }
  379. [JsonProperty("Installer")]
  380. public string Installer { get; set; }
  381. }
  382. }