예제 #1
0
        public MvcViewScaffolderViewModel(MvcViewScaffolderModel model) : base(model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }
            this.Model = model;
            this.ViewTemplatesInternal = model.ViewTemplates;
            ViewTemplate viewTemplate = new ViewTemplate(MvcViewTemplates.Empty, false);

            if (this.ViewTemplatesInternal.Any <ViewTemplate>())
            {
                this.ViewTemplate                  = this.ViewTemplatesInternal.FirstOrDefault <ViewTemplate>((ViewTemplate view) => view.Equals(viewTemplate)) ?? this.ViewTemplatesInternal.First <ViewTemplate>();
                this.ViewTemplateSearchText        = this.ViewTemplate.DisplayName;
                this.IsViewTemplateSelectorVisible = this.ViewTemplatesInternal.Count <ViewTemplate>() > 1;
            }
            this.ViewTemplates = CollectionViewSource.GetDefaultView(this.ViewTemplatesInternal);
            this.ViewTemplates.SortDescriptions.Add(new SortDescription("DisplayName", ListSortDirection.Ascending));
            this.IsPartialViewSelected = model.IsPartialViewSelected;
            this.IsReferenceScriptLibrariesSelected = model.IsReferenceScriptLibrariesSelected;
            this.IsLayoutPageSelected = model.IsLayoutPageSelected;
            this.LayoutPageFile       = model.LayoutPageFile;
            this.ViewName             = model.ViewName;
            base.SetValidationMessage(model.ValidateViewName(this.ViewName), "ViewName");
            this.DataContextTypesInternal = new ObservableCollection <ModelType>();
            this.ModelTypesInternal       = new ObservableCollection <ModelType>();
            foreach (ModelType modelType in this.Model.ModelTypes)
            {
                this.ModelTypesInternal.Add(modelType);
            }
            foreach (ModelType dataContextType in this.Model.DataContextTypes)
            {
                this.DataContextTypesInternal.Add(dataContextType);
            }
            this.DataContextTypes = new ListCollectionView(this.DataContextTypesInternal)
            {
                CustomSort = new DataContextModelTypeComparer()
            };
            this.ModelTypes = CollectionViewSource.GetDefaultView(this.ModelTypesInternal);
            this.ModelTypes.SortDescriptions.Add(new SortDescription("ShortTypeName", ListSortDirection.Ascending));
            this.IsDataContextSelectorVisible = this.DataContextTypesInternal.Any <ModelType>();
            if (this.IsDataContextSelectorVisible && model.DataContextType != null)
            {
                this.DataContextType     = this.Model.DataContextType;
                this.DataContextTypeName = this.DataContextType.DisplayName;
            }
            if (this.ViewTemplate == null)
            {
                base.SetValidationMessage(this.Model.ValidateViewTemplate(null), "ViewTemplate");
            }
            else if (!this.ViewTemplate.IsModelRequired)
            {
                base.SetValidationMessage(null, "ModelType");
            }
            else
            {
                base.SetValidationMessage(this.Model.ValidateModelType(null), "ModelType");
            }
            this.SelectLayoutCommand = new RelayCommand(new Action <object>(this.SelectLayout));
        }