PageRenderTime 26ms CodeModel.GetById 20ms app.highlight 4ms RepoModel.GetById 1ms 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
 1// <copyright file="GenericWizardPageViewModel.cs" company="Microsoft Corporation">
 2// Copyright (c) Microsoft Corporation.  All rights reserved.
 3// </copyright>
 4
 5namespace Microsoft.ServiceModel.Interop.ConfigurationWizard.ViewModel
 6{
 7    using System;
 8    using System.Collections.Generic;
 9    using System.Collections.ObjectModel;
10    using System.Linq;
11    using Microsoft.ServiceModel.Interop.ConfigurationWizard.Configuration;
12
13    /// <summary>
14    /// View model for a generic wizard page that gathers input information from the user
15    /// </summary>
16    public class GenericWizardPageViewModel : PageViewModelBase
17    {
18        private ObservableCollection<FieldModel> fields;
19
20        /// <summary>
21        /// Initializes a new instance of the GenericWizardPageViewModel class
22        /// </summary>
23        /// <param name="scenario">Scenario name</param>
24        /// <param name="wizardPage">Wizard page settings</param>
25        public GenericWizardPageViewModel(string scenario, interoperabilityWizardScenarioPage wizardPage)
26        {
27            if (wizardPage == null)
28            {
29                throw new ArgumentNullException("wizardPage");
30            }
31
32            if (string.IsNullOrEmpty(scenario))
33            {
34                throw new ArgumentNullException("scenario");
35            }
36
37            this.WizardPage = wizardPage;
38            this.Subtitle = scenario;
39
40            if (wizardPage.field != null)
41            {
42                this.fields = new ObservableCollection<FieldModel>(wizardPage.field
43                    .Select(f => new FieldModel(f)));
44            }
45            else
46            {
47                this.fields = new ObservableCollection<FieldModel>();
48            }
49
50            this.Description = wizardPage.description;
51        }
52
53        /// <summary>
54        /// Gets the page settings used for initializing the model
55        /// </summary>
56        public interoperabilityWizardScenarioPage WizardPage
57        {
58            get;
59            private set;
60        }
61
62        /// <summary>
63        /// Gets all the available fields for the page
64        /// </summary>
65        public IEnumerable<FieldModel> Fields
66        {
67            get { return this.fields; }
68        }
69
70        /// <summary>
71        /// Gets the page title
72        /// </summary>
73        public override string DisplayName
74        {
75            get { return this.WizardPage.title; }
76        }
77
78        internal override bool IsValid()
79        {
80            return this.fields.All(f => f.CurrentOption != null
81                || (!f.IsRequired || (f.IsRequired && !string.IsNullOrEmpty(f.FieldValue)))
82                || (f.CurrentOption == null && f.HasSingleOption));
83        }
84    }
85}
86