示例#1
0
        public async Task GenerateCode(ModelGeneratorModel generatorModel)
        {
            if (generatorModel == null)
            {
                throw new ArgumentNullException(nameof(generatorModel));
            }

            if (string.IsNullOrEmpty(generatorModel.ModelName))
            {
                throw new ArgumentException(MessageStrings.ViewNameRequired);
            }

            if (string.IsNullOrEmpty(generatorModel.TemplateName))
            {
                throw new ArgumentException(MessageStrings.TemplateNameRequired);
            }

            var outputPath = ValidateAndGetOutputPath(
                generatorModel,
                outputFileName: generatorModel.ModelName + Constants.CodeFileExtension
                );

            this._logger.LogMessage("ApplicationBasePath: " + this.ApplicationInfo.ApplicationBasePath);
            this._logger.LogMessage("Model Output Path: " + outputPath);


            var layoutDependencyInstaller
                = ActivatorUtilities.CreateInstance <MvcLayoutDependencyInstaller>(this._serviceProvider);

            await layoutDependencyInstaller.Execute();

            await this.GenerateModel(generatorModel, null, outputPath);

            await layoutDependencyInstaller.InstallDependencies();
        }
示例#2
0
        protected async Task AddRequiredFiles(ModelGeneratorModel generatorModel)
        {
            IEnumerable <RequiredFileEntity> requiredFiles = GetRequiredFiles(generatorModel);

            foreach (var file in requiredFiles)
            {
                if (!File.Exists(Path.Combine(ApplicationInfo.ApplicationBasePath, file.OutputPath)))
                {
                    await _codeGeneratorActionsService.AddFileAsync(
                        Path.Combine(ApplicationInfo.ApplicationBasePath, file.OutputPath),
                        Path.Combine(TemplateFolders.First(), file.TemplateName));

                    _logger.LogMessage($"Added additional file :{file.OutputPath}");
                }
            }
        }
示例#3
0
        internal async Task GenerateModel(
            ModelGeneratorModel generatorModel,
            ModelTypeAndContextModel modelTypeAndContextModel,
            string outputPath)
        {
            var templateName = generatorModel.TemplateName + Constants.RazorTemplateExtension;
            await _codeGeneratorActionsService.AddFileFromTemplateAsync(
                outputPath,
                templateName,
                TemplateFolders,
                generatorModel
                );

            this._logger.LogMessage("Added Model : "
                                    + outputPath.Substring(ApplicationInfo.ApplicationBasePath.Length));

            await AddRequiredFiles(generatorModel);
        }
示例#4
0
 protected IEnumerable <RequiredFileEntity> GetRequiredFiles(ModelGeneratorModel viewGeneratorModel)
 {
     return(new List <RequiredFileEntity>());
 }