PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/ExpressInteropBinding/Microsoft.ServiceModel.Interop.ExtensionUtils/ConfigurationWizard/ViewModel/CertificatePageViewModel.cs

#
C# | 143 lines | 93 code | 19 blank | 31 comment | 6 complexity | 1dc46baef8ec2dd88a9841290aef2a3a MD5 | raw file
Possible License(s): CC-BY-SA-3.0, Apache-2.0
  1. // <copyright file="BasicSettingsPageViewModel.cs" company="Microsoft Corporation">
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. // </copyright>
  4. namespace Microsoft.ServiceModel.Interop.ConfigurationWizard.ViewModel
  5. {
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using Microsoft.ServiceModel.Interop.ConfigurationWizard.Services;
  10. /// <summary>
  11. /// View model for the certificate selection view page
  12. /// </summary>
  13. public class CertificatePageViewModel : PageViewModelBase
  14. {
  15. private string storeLocation;
  16. private string store;
  17. private string certificate;
  18. private ICertificateStoreService certificateStore;
  19. private IEnumerable<string> certificates;
  20. /// <summary>
  21. /// Initializes a new instance of the CertificatePageViewModel class
  22. /// </summary>
  23. /// <param name="certificateStore">A valid instance of ICertificateStoreService for selecting an existing certificate</param>
  24. public CertificatePageViewModel(ICertificateStoreService certificateStore)
  25. {
  26. if (certificateStore == null)
  27. {
  28. throw new ArgumentNullException("certificateStore");
  29. }
  30. this.certificateStore = certificateStore;
  31. this.store = this.certificateStore.GetStores().First();
  32. this.storeLocation = this.certificateStore.GetStoreLocations().First();
  33. this.certificates = this.certificateStore.GetCertificates(this.storeLocation, this.store);
  34. }
  35. /// <summary>
  36. /// Gets the view display name
  37. /// </summary>
  38. public override string DisplayName
  39. {
  40. get { return "Certificate Selection"; }
  41. }
  42. /// <summary>
  43. /// Gets the list of certificate store locations
  44. /// </summary>
  45. public IEnumerable<string> StoreLocations
  46. {
  47. get { return this.certificateStore.GetStoreLocations(); }
  48. }
  49. /// <summary>
  50. /// Gets or sets the selected certificate store location
  51. /// </summary>
  52. public string StoreLocation
  53. {
  54. get
  55. {
  56. return this.storeLocation;
  57. }
  58. set
  59. {
  60. if (this.storeLocation != value)
  61. {
  62. this.storeLocation = value;
  63. this.OnStoreLocationChanged();
  64. }
  65. }
  66. }
  67. /// <summary>
  68. /// Gets the list of certificate stores
  69. /// </summary>
  70. public IEnumerable<string> Stores
  71. {
  72. get { return this.certificateStore.GetStores(); }
  73. }
  74. /// <summary>
  75. /// Gets or sets the selected certificate store
  76. /// </summary>
  77. public string Store
  78. {
  79. get
  80. {
  81. return this.store;
  82. }
  83. set
  84. {
  85. if (this.store != value)
  86. {
  87. this.store = value;
  88. this.OnStoreChanged();
  89. }
  90. }
  91. }
  92. /// <summary>
  93. /// Gets the list of certificates
  94. /// </summary>
  95. public IEnumerable<string> Certificates
  96. {
  97. get { return this.certificates; }
  98. }
  99. /// <summary>
  100. /// Gets or sets the selected certificate
  101. /// </summary>
  102. public string Certificate
  103. {
  104. get { return this.certificate; }
  105. set { SetValue(ref this.certificate, value, () => this.Certificate); }
  106. }
  107. internal override bool IsValid()
  108. {
  109. return !string.IsNullOrEmpty(this.Certificate);
  110. }
  111. private void OnStoreChanged()
  112. {
  113. this.certificates = this.certificateStore.GetCertificates(this.StoreLocation, this.Store);
  114. this.OnPropertyChanged(() => this.Store);
  115. this.OnPropertyChanged(() => this.Certificates);
  116. }
  117. private void OnStoreLocationChanged()
  118. {
  119. this.certificates = this.certificateStore.GetCertificates(this.StoreLocation, this.Store);
  120. this.OnPropertyChanged(() => this.StoreLocation);
  121. this.OnPropertyChanged(() => this.Certificates);
  122. }
  123. }
  124. }