예제 #1
0
        protected RazorPageWithContextTemplateModel GetRazorPageWithContextTemplateModel(RazorPageGeneratorModel razorGeneratorModel, ModelTypeAndContextModel modelTypeAndContextModel)
        {
            bool isLayoutSelected = !razorGeneratorModel.PartialView &&
                                    (razorGeneratorModel.UseDefaultLayout || !String.IsNullOrEmpty(razorGeneratorModel.LayoutPage));

            var namespaceName = string.IsNullOrEmpty(razorGeneratorModel.NamespaceName)
                ? GetDefaultPageModelNamespaceName(razorGeneratorModel.RelativeFolderPath)
                : razorGeneratorModel.NamespaceName;

            RazorPageWithContextTemplateModel templateModel = new RazorPageWithContextTemplateModel(modelTypeAndContextModel.ModelType, modelTypeAndContextModel.DbContextFullName)
            {
                NamespaceName            = namespaceName,
                NoPageModel              = razorGeneratorModel.NoPageModel,
                PageModelClassName       = razorGeneratorModel.RazorPageName + "Model",
                ViewDataTypeName         = modelTypeAndContextModel?.ModelType?.FullName,
                ViewDataTypeShortName    = modelTypeAndContextModel?.ModelType?.Name,
                ContextTypeName          = modelTypeAndContextModel?.DbContextFullName,
                RazorPageName            = razorGeneratorModel.RazorPageName,
                LayoutPageFile           = razorGeneratorModel.LayoutPage,
                IsLayoutPageSelected     = isLayoutSelected,
                IsPartialView            = razorGeneratorModel.PartialView,
                ReferenceScriptLibraries = razorGeneratorModel.ReferenceScriptLibraries,
                ModelMetadata            = modelTypeAndContextModel?.ContextProcessingResult?.ModelMetadata,
                JQueryVersion            = "1.10.2" //Todo
            };

            return(templateModel);
        }
예제 #2
0
        internal async Task BaseGenerateViews(IDictionary <string, string> viewsAndTemplates, RazorPageGeneratorModel razorPageGeneratorModel, ModelTypeAndContextModel modelTypeAndContextModel, string baseOutputPath)
        {
            if (viewsAndTemplates == null)
            {
                throw new ArgumentNullException(nameof(viewsAndTemplates));
            }

            if (razorPageGeneratorModel == null)
            {
                throw new ArgumentNullException(nameof(razorPageGeneratorModel));
            }

            if (modelTypeAndContextModel == null)
            {
                throw new ArgumentNullException(nameof(modelTypeAndContextModel));
            }

            if (string.IsNullOrEmpty(baseOutputPath))
            {
                baseOutputPath = ApplicationInfo.ApplicationBasePath;
            }

            IEnumerable <string> templateFolders = GetTemplateFoldersForContentVersion();

            foreach (KeyValuePair <string, string> entry in viewsAndTemplates)
            {
                string viewName            = entry.Key;
                string templateName        = entry.Value;
                string outputPath          = Path.Combine(baseOutputPath, viewName + Constants.ViewExtension);
                var    pageModelOutputPath = outputPath + ".cs";

                bool isLayoutSelected = !razorPageGeneratorModel.PartialView &&
                                        (razorPageGeneratorModel.UseDefaultLayout || !string.IsNullOrEmpty(razorPageGeneratorModel.LayoutPage));

                RazorPageWithContextTemplateModel templateModel = GetRazorPageWithContextTemplateModel(razorPageGeneratorModel, modelTypeAndContextModel);
                templateModel.RazorPageName      = viewName;
                templateModel.PageModelClassName = viewName + "Model";
                var pageModelTemplateName = templateName + "PageModel" + Constants.RazorTemplateExtension;
                templateName = templateName + Constants.RazorTemplateExtension;

                await _codeGeneratorActionsService.AddFileFromTemplateAsync(outputPath, templateName, templateFolders, templateModel);

                _logger.LogMessage($"Added Razor Page : {outputPath.Substring(ApplicationInfo.ApplicationBasePath.Length)}");
                await _codeGeneratorActionsService.AddFileFromTemplateAsync(pageModelOutputPath, pageModelTemplateName, templateFolders, templateModel);

                _logger.LogMessage($"Added PageModel : {pageModelOutputPath.Substring(ApplicationInfo.ApplicationBasePath.Length)}");
            }

            await AddRequiredFiles(razorPageGeneratorModel);
        }