示例#1
0
        /// <summary>
        /// 生成代码
        /// </summary>
        /// <param name="project">项目信息</param>
        /// <param name="selectionRelativePath"></param>
        /// <param name="codeGeneratorViewModel"></param>
        private void GenerateCode(Project project, string selectionRelativePath, WebFormsCodeGeneratorViewModel codeGeneratorViewModel)
        {
            // Get Model Type
            var modelType = codeGeneratorViewModel.ModelType.CodeType;

            // Ensure the Data Context
            string dbContextTypeName           = codeGeneratorViewModel.DbContextModelType.TypeName;
            IEntityFrameworkService efService  = Context.ServiceProvider.GetService <IEntityFrameworkService>();
            ModelMetadata           efMetadata = efService.AddRequiredEntity(Context, dbContextTypeName, modelType.FullName);

            // Get the dbContext
            ICodeTypeService codeTypeService = GetService <ICodeTypeService>();
            CodeType         dbContext       = codeTypeService.GetCodeType(project, dbContextTypeName);

            // Get the dbContext namespace
            string dbContextNamespace = dbContext.Namespace != null ? dbContext.Namespace.FullName : String.Empty;

            // Ensure the Dynamic Data Field templates
            EnsureDynamicDataFieldTemplates(project, dbContextNamespace, dbContextTypeName);

            // Add Web Forms Pages from Templates
            AddWebFormsPages(
                project,
                selectionRelativePath,
                dbContextNamespace,
                dbContextTypeName,
                modelType,
                efMetadata,
                codeGeneratorViewModel.UseMasterPage,
                codeGeneratorViewModel.DesktopMasterPage,
                codeGeneratorViewModel.DesktopPlaceholderId,
                codeGeneratorViewModel.OverwriteViews
                );
        }
示例#2
0
        // Shows the Visual Studio dialog that collects scaffolding options
        // from the user.
        // Passing the dialog to this method so that all scaffolder UIs
        // are modal is still an open question and tracked by bug 578173.
        public override bool ShowUIAndValidate()
        {
            _codeGeneratorViewModel = new WebFormsCodeGeneratorViewModel(Context);

            WebFormsScaffolderDialog window = new WebFormsScaffolderDialog(_codeGeneratorViewModel);
            bool?isOk = window.ShowModal();

            if (isOk == true)
            {
                Validate();
            }

            return(isOk == true);
        }
        public WebFormsScaffolderDialog(WebFormsCodeGeneratorViewModel viewModel)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException("viewModel");
            }
            
            InitializeComponent();
            
            viewModel.PromptForNewDataContextTypeName += model =>
            {
                var dialog = new NewDataContextDialog(model);
                var result = dialog.ShowModal();
                model.Canceled = !result.HasValue || !result.Value;
            };

            viewModel.Close += result => DialogResult = result;

            DataContext = viewModel;
        }
示例#4
0
        // Collects the common data needed by all of the scaffolded output and generates:
        // 1) Dynamic Data Field Templates
        // 2) Web Forms Pages
        private void GenerateCode(Project project, string selectionRelativePath, WebFormsCodeGeneratorViewModel codeGeneratorViewModel)
        {
            // Get Model Type
            var modelType = codeGeneratorViewModel.ModelType.CodeType;

            // Ensure the Data Context
            string dbContextTypeName           = codeGeneratorViewModel.DbContextModelType.TypeName;
            IEntityFrameworkService efService  = Context.ServiceProvider.GetService <IEntityFrameworkService>();
            ModelMetadata           efMetadata = efService.AddRequiredEntity(Context, dbContextTypeName, modelType.FullName);
            var oneToManyModels = GetOneToManyModelDictionary(efMetadata, efService, dbContextTypeName);

            // Get the dbContext
            ICodeTypeService codeTypeService = GetService <ICodeTypeService>();
            CodeType         dbContext       = codeTypeService.GetCodeType(project, dbContextTypeName);

            // Get the dbContext namespace
            string dbContextNamespace = dbContext.Namespace != null ? dbContext.Namespace.FullName : String.Empty;

            // Ensure the Dynamic Data Field templates
            EnsureDynamicDataFieldTemplates(project, dbContextNamespace, dbContextTypeName);

            EnsurePepositoriesTemplates(project, dbContextNamespace, dbContextTypeName);
            EnsureExtensionsTemplates(project, dbContextNamespace, dbContextTypeName);


            AddEntityRepositoryTemplates(
                project,
                selectionRelativePath,
                dbContextNamespace,
                dbContextTypeName,
                modelType,
                efMetadata,
                codeGeneratorViewModel.OverwriteViews
                );


            // Add Web Forms Pages from Templates
            AddWebFormsPages(
                project,
                selectionRelativePath,
                dbContextNamespace,
                dbContextTypeName,
                modelType,
                efMetadata,
                codeGeneratorViewModel.UseMasterPage,
                codeGeneratorViewModel.DesktopMasterPage,
                codeGeneratorViewModel.DesktopPlaceholderId,
                codeGeneratorViewModel.OverwriteViews,
                oneToManyModels
                );

            foreach (var dicitem in oneToManyModels)
            {
                var metadata  = dicitem.Value;
                var modelName = this.GetModelName(efMetadata, metadata.EntitySetName);
                AddEntityRepositoryTemplates(
                    project,
                    selectionRelativePath,
                    dbContextNamespace,
                    dbContextTypeName,
                    modelType,
                    metadata,
                    codeGeneratorViewModel.OverwriteViews,
                    modelName
                    );
            }

            // Add Web Forms Pages from Templates
        }
        // Collects the common data needed by all of the scaffolded output and generates:
        // 1) Dynamic Data Field Templates
        // 2) Web Forms Pages
        private void GenerateCode(Project project, string selectionRelativePath, WebFormsCodeGeneratorViewModel codeGeneratorViewModel)
        {
            foreach (var codeType in codeGeneratorViewModel.ModelTypeCollection.Where(m => m.Selected))
            {
                // Get Model Type
                var modelType = codeType.CodeType;

                // Get the dbContext
                string dbContextTypeName = codeGeneratorViewModel.DbContextModelType.TypeName;
                ICodeTypeService codeTypeService = GetService<ICodeTypeService>();
                CodeType dbContext = codeTypeService.GetCodeType(project, dbContextTypeName);

                // Get the dbContext namespace
                string dbContextNamespace = dbContext.Namespace != null ? dbContext.Namespace.FullName : String.Empty;

                if (codeGeneratorViewModel.GenerateViews)
                    // Add Web Forms Pages from Templates
                    AddWebFormsPages(
                        project,
                        selectionRelativePath,
                        dbContextNamespace,
                        dbContextTypeName,
                        modelType,
                        codeGeneratorViewModel.Overwrite
                   );

                if (codeGeneratorViewModel.GenerateController)
                    // Add Controllers from Templates
                    AddControllers(
                        project,
                        selectionRelativePath,
                        dbContextNamespace,
                        dbContextTypeName,
                        modelType,
                        codeGeneratorViewModel.Overwrite
                   );

                if (codeGeneratorViewModel.GenerateApiController)
                    // Add Controllers from Templates
                    AddApiControllers(
                        project,
                        selectionRelativePath,
                        dbContextNamespace,
                        dbContextTypeName,
                        modelType,
                        codeGeneratorViewModel.Overwrite
                   );

                if (codeGeneratorViewModel.GenerateStorageContext)
                    // Add Storage Contexts from Templates
                    AddStorageContexts(
                        project,
                        selectionRelativePath,
                        dbContextNamespace,
                        dbContextTypeName,
                        modelType,
                        codeGeneratorViewModel.Overwrite
                   );

                if (codeGeneratorViewModel.GenerateScripts)
                    // Add Storage Contexts from Templates
                    AddScripts(
                        project,
                        selectionRelativePath,
                        dbContextNamespace,
                        dbContextTypeName,
                        modelType,
                        codeGeneratorViewModel.Overwrite
                   );
            }
        }
        // Collects the common data needed by all of the scaffolded output and generates:
        // 1) Dynamic Data Field Templates
        // 2) Web Forms Pages
        private void GenerateCode(Project project, string selectionRelativePath, WebFormsCodeGeneratorViewModel codeGeneratorViewModel)
        {
            foreach (var codeType in codeGeneratorViewModel.ModelTypeCollection.Where(m => m.Selected))
            {
                // Get Model Type
                var modelType = codeType.CodeType;

                // Get the dbContext
                string           dbContextTypeName = codeGeneratorViewModel.DbContextModelType.TypeName;
                ICodeTypeService codeTypeService   = GetService <ICodeTypeService>();
                CodeType         dbContext         = codeTypeService.GetCodeType(project, dbContextTypeName);

                // Get the dbContext namespace
                string dbContextNamespace = dbContext.Namespace != null ? dbContext.Namespace.FullName : String.Empty;

                if (codeGeneratorViewModel.GenerateViews)
                {
                    // Add Web Forms Pages from Templates
                    AddWebFormsPages(
                        project,
                        selectionRelativePath,
                        dbContextNamespace,
                        dbContextTypeName,
                        modelType,
                        codeGeneratorViewModel.Overwrite
                        );
                }

                if (codeGeneratorViewModel.GenerateController)
                {
                    // Add Controllers from Templates
                    AddControllers(
                        project,
                        selectionRelativePath,
                        dbContextNamespace,
                        dbContextTypeName,
                        modelType,
                        codeGeneratorViewModel.Overwrite
                        );
                }

                if (codeGeneratorViewModel.GenerateApiController)
                {
                    // Add Controllers from Templates
                    AddApiControllers(
                        project,
                        selectionRelativePath,
                        dbContextNamespace,
                        dbContextTypeName,
                        modelType,
                        codeGeneratorViewModel.Overwrite
                        );
                }

                if (codeGeneratorViewModel.GenerateStorageContext)
                {
                    // Add Storage Contexts from Templates
                    AddStorageContexts(
                        project,
                        selectionRelativePath,
                        dbContextNamespace,
                        dbContextTypeName,
                        modelType,
                        codeGeneratorViewModel.Overwrite
                        );
                }

                if (codeGeneratorViewModel.GenerateScripts)
                {
                    // Add Storage Contexts from Templates
                    AddScripts(
                        project,
                        selectionRelativePath,
                        dbContextNamespace,
                        dbContextTypeName,
                        modelType,
                        codeGeneratorViewModel.Overwrite
                        );
                }
            }
        }