public EntityTypeCodeGeneratorHelper([NotNull] EntityTypeGeneratorModel generatorModel, [NotNull] IRelationalMetadataExtensionProvider extensionsProvider) { Check.NotNull(generatorModel, nameof(generatorModel)); Check.NotNull(extensionsProvider, nameof(extensionsProvider)); GeneratorModel = generatorModel; ExtensionsProvider = extensionsProvider; }
public virtual async Task <List <string> > GenerateAsync( [NotNull] ReverseEngineeringConfiguration configuration, CancellationToken cancellationToken = default(CancellationToken)) { Check.NotNull(configuration, nameof(configuration)); CheckConfiguration(configuration); var resultingFiles = new List <string>(); var providerAssembly = configuration.ProviderAssembly; var provider = GetProvider(providerAssembly); var metadataModel = GetMetadataModel(provider, configuration); var dbContextGeneratorModel = new DbContextGeneratorModel { ClassName = configuration.ContextClassName, Namespace = configuration.Namespace, ProviderAssembly = configuration.ProviderAssembly.FullName, ConnectionString = configuration.ConnectionString, Generator = this, MetadataModel = metadataModel }; var dbContextCodeGeneratorHelper = provider.DbContextCodeGeneratorHelper(dbContextGeneratorModel); dbContextGeneratorModel.Helper = dbContextCodeGeneratorHelper; var dbContextClassName = configuration.ContextClassName ?? dbContextCodeGeneratorHelper.ClassName(configuration.ConnectionString); CheckOutputFiles(configuration.OutputPath, dbContextClassName, metadataModel); var templating = _serviceProvider.GetRequiredService <ITemplating>(); var dbContextTemplate = provider.DbContextTemplate; var templateResult = await templating.RunTemplateAsync(dbContextTemplate, dbContextGeneratorModel, provider); if (templateResult.ProcessingException != null) { throw new InvalidOperationException( Strings.ErrorRunningDbContextTemplate(templateResult.ProcessingException.Message)); } // output DbContext .cs file var dbContextFileName = dbContextClassName + FileExtension; var dbContextFileFullPath = FileService.OutputFile( configuration.OutputPath, dbContextFileName, templateResult.GeneratedText); resultingFiles.Add(dbContextFileFullPath); var entityTypeTemplate = provider.EntityTypeTemplate; foreach (var entityType in metadataModel.EntityTypes) { var entityTypeGeneratorModel = new EntityTypeGeneratorModel() { EntityType = entityType, Namespace = configuration.Namespace, ProviderAssembly = configuration.ProviderAssembly.FullName, ConnectionString = configuration.ConnectionString, Generator = this }; var entityTypeCodeGeneratorHelper = provider.EntityTypeCodeGeneratorHelper(entityTypeGeneratorModel); entityTypeGeneratorModel.Helper = entityTypeCodeGeneratorHelper; templateResult = await templating.RunTemplateAsync(entityTypeTemplate, entityTypeGeneratorModel, provider); if (templateResult.ProcessingException != null) { throw new InvalidOperationException( Strings.ErrorRunningEntityTypeTemplate(templateResult.ProcessingException.Message)); } // output EntityType poco .cs file var entityTypeFileName = entityType.DisplayName() + FileExtension; var entityTypeFileFullPath = FileService.OutputFile( configuration.OutputPath, entityTypeFileName, templateResult.GeneratedText); resultingFiles.Add(entityTypeFileFullPath); } return(resultingFiles); }
public EntityTypeCodeGeneratorHelper([NotNull] EntityTypeGeneratorModel generatorModel) { Check.NotNull(generatorModel, nameof(generatorModel)); GeneratorModel = generatorModel; }
public virtual async Task<List<string>> GenerateAsync( [NotNull] ReverseEngineeringConfiguration configuration, CancellationToken cancellationToken = default(CancellationToken)) { Check.NotNull(configuration, nameof(configuration)); CheckConfiguration(configuration); var resultingFiles = new List<string>(); var providerAssembly = configuration.ProviderAssembly; var provider = GetProvider(providerAssembly); var metadataModel = GetMetadataModel(provider, configuration); var dbContextGeneratorModel = new DbContextGeneratorModel { ClassName = configuration.ContextClassName, Namespace = configuration.Namespace, ProviderAssembly = configuration.ProviderAssembly.FullName, ConnectionString = configuration.ConnectionString, MetadataModel = metadataModel }; //TODO - check to see whether user has an override class for this in the current project first var dbContextCodeGenerator = provider.GetContextModelCodeGenerator(this, dbContextGeneratorModel); if (dbContextCodeGenerator == null) { throw new InvalidOperationException( Strings.NoContextModelCodeGenerator(provider.GetType().FullName)); } CheckOutputFiles(configuration.OutputPath, dbContextCodeGenerator.ClassName, metadataModel); var contextStringBuilder = new IndentedStringBuilder(); dbContextCodeGenerator.Generate(contextStringBuilder); // output DbContext .cs file var dbContextFileName = dbContextCodeGenerator.ClassName + FileExtension; using (var sourceStream = new MemoryStream(Encoding.UTF8.GetBytes(contextStringBuilder.ToString()))) { await OutputFile(configuration.OutputPath, dbContextFileName, sourceStream); } resultingFiles.Add(Path.Combine(configuration.OutputPath, dbContextFileName)); foreach (var entityType in metadataModel.EntityTypes) { var entityTypeGeneratorModel = new EntityTypeGeneratorModel() { EntityType = entityType, Namespace = configuration.Namespace, ProviderAssembly = configuration.ProviderAssembly.FullName, ConnectionString = configuration.ConnectionString, }; //TODO - check to see whether user has an override class for this in the current project first var entityTypeCodeGenerator = provider.GetEntityTypeModelCodeGenerator( this, entityTypeGeneratorModel); if (entityTypeCodeGenerator == null) { throw new InvalidOperationException( Strings.NoEntityTypeModelCodeGenerator(provider.GetType().FullName)); } var entityTypeStringBuilder = new IndentedStringBuilder(); entityTypeCodeGenerator.Generate(entityTypeStringBuilder); // output EntityType poco .cs file using (var sourceStream = new MemoryStream(Encoding.UTF8.GetBytes(entityTypeStringBuilder.ToString()))) { var entityTypeFileName = entityType.Name + FileExtension; await OutputFile(configuration.OutputPath, entityTypeFileName, sourceStream); resultingFiles.Add(Path.Combine(configuration.OutputPath, entityTypeFileName)); } } return resultingFiles; }
public virtual async Task <List <string> > GenerateAsync( [NotNull] ReverseEngineeringConfiguration configuration, CancellationToken cancellationToken = default(CancellationToken)) { Check.NotNull(configuration, nameof(configuration)); CheckConfiguration(configuration); var resultingFiles = new List <string>(); var providerAssembly = configuration.ProviderAssembly; var provider = GetProvider(providerAssembly); var metadataModel = GetMetadataModel(provider, configuration); var dbContextGeneratorModel = new DbContextGeneratorModel { ClassName = configuration.ContextClassName, Namespace = configuration.Namespace, ProviderAssembly = configuration.ProviderAssembly.FullName, ConnectionString = configuration.ConnectionString, MetadataModel = metadataModel }; //TODO - check to see whether user has an override class for this in the current project first var dbContextCodeGenerator = provider.GetContextModelCodeGenerator(this, dbContextGeneratorModel); if (dbContextCodeGenerator == null) { throw new InvalidOperationException( Strings.NoContextModelCodeGenerator(provider.GetType().FullName)); } CheckOutputFiles(configuration.OutputPath, dbContextCodeGenerator.ClassName, metadataModel); var contextStringBuilder = new IndentedStringBuilder(); dbContextCodeGenerator.Generate(contextStringBuilder); // output DbContext .cs file var dbContextFileName = dbContextCodeGenerator.ClassName + FileExtension; using (var sourceStream = new MemoryStream(Encoding.UTF8.GetBytes(contextStringBuilder.ToString()))) { await OutputFile(configuration.OutputPath, dbContextFileName, sourceStream); } resultingFiles.Add(Path.Combine(configuration.OutputPath, dbContextFileName)); foreach (var entityType in metadataModel.EntityTypes) { var entityTypeGeneratorModel = new EntityTypeGeneratorModel() { EntityType = entityType, Namespace = configuration.Namespace, ProviderAssembly = configuration.ProviderAssembly.FullName, ConnectionString = configuration.ConnectionString, }; //TODO - check to see whether user has an override class for this in the current project first var entityTypeCodeGenerator = provider.GetEntityTypeModelCodeGenerator( this, entityTypeGeneratorModel); if (entityTypeCodeGenerator == null) { throw new InvalidOperationException( Strings.NoEntityTypeModelCodeGenerator(provider.GetType().FullName)); } var entityTypeStringBuilder = new IndentedStringBuilder(); entityTypeCodeGenerator.Generate(entityTypeStringBuilder); // output EntityType poco .cs file using (var sourceStream = new MemoryStream(Encoding.UTF8.GetBytes(entityTypeStringBuilder.ToString()))) { var entityTypeFileName = entityType.Name + FileExtension; await OutputFile(configuration.OutputPath, entityTypeFileName, sourceStream); resultingFiles.Add(Path.Combine(configuration.OutputPath, entityTypeFileName)); } } return(resultingFiles); }
public virtual EntityTypeCodeGeneratorHelper EntityTypeCodeGeneratorHelper(EntityTypeGeneratorModel model) { return(new EntityTypeCodeGeneratorHelper(model, ExtensionsProvider)); }
public virtual async Task<List<string>> GenerateAsync( [NotNull] ReverseEngineeringConfiguration configuration, CancellationToken cancellationToken = default(CancellationToken)) { Check.NotNull(configuration, nameof(configuration)); CheckConfiguration(configuration); var resultingFiles = new List<string>(); var providerAssembly = configuration.ProviderAssembly; var provider = GetProvider(providerAssembly); var metadataModel = GetMetadataModel(provider, configuration); var dbContextGeneratorModel = new DbContextGeneratorModel { ClassName = configuration.ContextClassName, Namespace = configuration.Namespace, ProviderAssembly = configuration.ProviderAssembly.FullName, ConnectionString = configuration.ConnectionString, Generator = this, MetadataModel = metadataModel }; var dbContextCodeGeneratorHelper = provider.DbContextCodeGeneratorHelper(dbContextGeneratorModel); dbContextGeneratorModel.Helper = dbContextCodeGeneratorHelper; var dbContextClassName = configuration.ContextClassName ?? dbContextCodeGeneratorHelper.ClassName(configuration.ConnectionString); CheckOutputFiles(configuration.OutputPath, dbContextClassName, metadataModel); var templating = _serviceProvider.GetRequiredService<ITemplating>(); var dbContextTemplate = provider.DbContextTemplate; var templateResult = await templating.RunTemplateAsync(dbContextTemplate, dbContextGeneratorModel, provider); if (templateResult.ProcessingException != null) { throw new InvalidOperationException( Strings.ErrorRunningDbContextTemplate(templateResult.ProcessingException.Message)); } // output DbContext .cs file var dbContextFileName = dbContextClassName + FileExtension; var dbContextFileFullPath = FileService.OutputFile( configuration.OutputPath, dbContextFileName, templateResult.GeneratedText); resultingFiles.Add(dbContextFileFullPath); var entityTypeTemplate = provider.EntityTypeTemplate; foreach (var entityType in metadataModel.EntityTypes) { var entityTypeGeneratorModel = new EntityTypeGeneratorModel() { EntityType = entityType, Namespace = configuration.Namespace, ProviderAssembly = configuration.ProviderAssembly.FullName, ConnectionString = configuration.ConnectionString, Generator = this }; var entityTypeCodeGeneratorHelper = provider.EntityTypeCodeGeneratorHelper(entityTypeGeneratorModel); entityTypeGeneratorModel.Helper = entityTypeCodeGeneratorHelper; templateResult = await templating.RunTemplateAsync(entityTypeTemplate, entityTypeGeneratorModel, provider); if (templateResult.ProcessingException != null) { throw new InvalidOperationException( Strings.ErrorRunningEntityTypeTemplate(templateResult.ProcessingException.Message)); } // output EntityType poco .cs file var entityTypeFileName = entityType.DisplayName() + FileExtension; var entityTypeFileFullPath = FileService.OutputFile( configuration.OutputPath, entityTypeFileName, templateResult.GeneratedText); resultingFiles.Add(entityTypeFileFullPath); } return resultingFiles; }
public virtual EntityTypeCodeGeneratorHelper EntityTypeCodeGeneratorHelper(EntityTypeGeneratorModel model) { return new EntityTypeCodeGeneratorHelper(model, ExtensionsProvider); }