PageRenderTime 35ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
C# | 86 lines | 54 code | 12 blank | 20 comment | 12 complexity | fdf29efdff435d86f192f4d9a01607cb MD5 | raw file
Possible License(s): CC-BY-SA-3.0, Apache-2.0
  1. // <copyright file="GenericWizardPageViewModel.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.Collections.ObjectModel;
  9. using System.Linq;
  10. using Microsoft.ServiceModel.Interop.ConfigurationWizard.Configuration;
  11. /// <summary>
  12. /// View model for a generic wizard page that gathers input information from the user
  13. /// </summary>
  14. public class GenericWizardPageViewModel : PageViewModelBase
  15. {
  16. private ObservableCollection<FieldModel> fields;
  17. /// <summary>
  18. /// Initializes a new instance of the GenericWizardPageViewModel class
  19. /// </summary>
  20. /// <param name="scenario">Scenario name</param>
  21. /// <param name="wizardPage">Wizard page settings</param>
  22. public GenericWizardPageViewModel(string scenario, interoperabilityWizardScenarioPage wizardPage)
  23. {
  24. if (wizardPage == null)
  25. {
  26. throw new ArgumentNullException("wizardPage");
  27. }
  28. if (string.IsNullOrEmpty(scenario))
  29. {
  30. throw new ArgumentNullException("scenario");
  31. }
  32. this.WizardPage = wizardPage;
  33. this.Subtitle = scenario;
  34. if (wizardPage.field != null)
  35. {
  36. this.fields = new ObservableCollection<FieldModel>(wizardPage.field
  37. .Select(f => new FieldModel(f)));
  38. }
  39. else
  40. {
  41. this.fields = new ObservableCollection<FieldModel>();
  42. }
  43. this.Description = wizardPage.description;
  44. }
  45. /// <summary>
  46. /// Gets the page settings used for initializing the model
  47. /// </summary>
  48. public interoperabilityWizardScenarioPage WizardPage
  49. {
  50. get;
  51. private set;
  52. }
  53. /// <summary>
  54. /// Gets all the available fields for the page
  55. /// </summary>
  56. public IEnumerable<FieldModel> Fields
  57. {
  58. get { return this.fields; }
  59. }
  60. /// <summary>
  61. /// Gets the page title
  62. /// </summary>
  63. public override string DisplayName
  64. {
  65. get { return this.WizardPage.title; }
  66. }
  67. internal override bool IsValid()
  68. {
  69. return this.fields.All(f => f.CurrentOption != null
  70. || (!f.IsRequired || (f.IsRequired && !string.IsNullOrEmpty(f.FieldValue)))
  71. || (f.CurrentOption == null && f.HasSingleOption));
  72. }
  73. }
  74. }