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(); }
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}"); } } }
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); }
protected IEnumerable <RequiredFileEntity> GetRequiredFiles(ModelGeneratorModel viewGeneratorModel) { return(new List <RequiredFileEntity>()); }