예제 #1
0
        public async Task WriteFileAsync(ScaffoldedFile file, CancellationToken cancellationToken = default)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            EnsureDirectoryForFile(file.Path);

            File.WriteAllText(file.Path, file.Code);
        }
예제 #2
0
        private void ProcessClassFile(OpenApiOptions options, List <ScaffoldedFile> list, string name, OpenApiSchema schema)
        {
            var classCode = Generator.WriteClassCode(schema, name, options);
            var classPath = Dependencies.PathHelper.Repository(options.DataProjectDir, name);
            var classFile = new ScaffoldedFile {
                Code = classCode, Path = classPath
            };

            list.Add(classFile);
        }
        private void ProcessInterfaceFile(OpenApiOptions options, List <ScaffoldedFile> list, string name, OpenApiSchema schema)
        {
            var interfaceCode = Generator.WriteInterfaceCode(schema, name, options);
            var interfacePath = Dependencies.PathHelper.RepositoryInterface(options.CoreProjectDir, name);
            var interfaceFile = new ScaffoldedFile {
                Code = interfaceCode, Path = interfacePath
            };

            list.Add(interfaceFile);
        }
        public ContextModel ScaffoldModel(OpenApiOptions options)
        {
            var model         = new ContextModel();
            var classFile     = new ScaffoldedFile();
            var interfaceFile = new ScaffoldedFile();

            classFile.Code = Generator.WriteClassCode(options.Document, options);
            classFile.Path = Dependencies.PathHelper.Context(options.DataProjectDir, options.ContextClassName);

            //interfaceFile.Code = Generator.WriteInterfaceCode(options.Document, options);
            //interfaceFile.Path = Dependencies.PathHelper.Context(options.DataProjectDir, options.ContextInterfaceName);
            model.Class = classFile;

            //model.Interface = interfaceFile;
            return(model);
        }
        public SupervisorModel ScaffoldModel(OpenApiOptions options)
        {
            string supervisorNamespace = Dependencies.Namespace.Supervisor(options.RootNamespace);
            var    model     = new SupervisorModel();
            var    classFile = new ScaffoldedFile
            {
                //var interfaceFile = new ScaffoldedFile();
                Code = Generator.WriteClassCode(options.Document,
                                                options.SupervisorClassName,
                                                options.SupervisorInterfaceName,
                                                supervisorNamespace),
                Path = Dependencies.PathHelper.Supervisor(options.CoreProjectDir, options.SupervisorClassName)
            };

            //interfaceFile.Code = Generator.WriteInterfaceCode(options.Document, options.SupervisorInterfaceName, supervisorNamespace);
            //interfaceFile.Path = Dependencies.PathHelper.Supervisor(options.CoreProjectDir, options.SupervisorInterfaceName);
            model.File = classFile;
            //model.Interface = interfaceFile;
            return(model);
        }
        public ConfigurationModel ScaffoldModel(OpenApiOptions options)
        {
            var model = new ConfigurationModel();
            List <ScaffoldedFile> list = new List <ScaffoldedFile>();

            foreach (var kvp in options.Document.GetSchemas())
            {
                var name   = kvp.Key;
                var schema = kvp.Value;
                var code   = Generator.WriteCode(schema, name, Dependencies.Namespace.Configuration(options.RootNamespace));
                var path   = Dependencies.PathHelper.Configuration(options.DataProjectDir, name);
                var file   = new ScaffoldedFile {
                    Code = code, Path = path
                };
                list.Add(file);
            }

            model.Files = list;
            return(model);
        }
        /// <summary>
        /// Generates code for a model.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="options">The model generatation options <see cref="ModelCodeGenerationOptions"/>.</param>
        /// <returns></returns>
        public ScaffoldedModel GenerateModel(IModel model, ModelCodeGenerationOptions options)
        {
            var files = new ScaffoldedModel();

            var contextCode = this.dbContextGenerator.WriteCode(
                model,
                options.ContextNamespace,
                options.ContextName,
                options.ConnectionString,
                options.UseDataAnnotations,
                options.SuppressConnectionStringWarning
                );

            files.ContextFile = new ScaffoldedFile
            {
                Path = Path.Combine(options.ContextDir, options.ContextName + FileExtension),
                Code = contextCode
            };

            foreach (var entityType in model.GetEntityTypes())
            {
                var entityCode = this.entityTypeGenerator.WriteCode(
                    entityType,
                    options.ContextNamespace,
                    options.UseDataAnnotations
                    );

                var entityFile = new ScaffoldedFile
                {
                    Path = entityType.DisplayName() + FileExtension,
                    Code = entityCode
                };

                files.AdditionalFiles.Add(entityFile);
            }

            return(files);
        }
예제 #8
0
 protected static void AssertFileContents(
     string expectedCode,
     ScaffoldedFile file)
 => Assert.Equal(expectedCode, file.Code, ignoreLineEndingDifferences: true);
예제 #9
0
 public void WriteFile(ScaffoldedFile file)
 {
     ThreadHelper.JoinableTaskFactory.Run(() => WriteFileAsync(file));
 }