示例#1
0
        public static void AspNetCoreAPIWithServiceAndControllers(string directory, string @namespace, string connectionString, Action <string> log = null)
        {
            log?.Invoke("Begin template generate");
            log?.Invoke("Generating dotnet project and installing required packages...");
            Directory.SetCurrentDirectory(directory);
            RunCommand($"dotnet new webapi");
            RunCommand($"del WeatherForecast.cs");
            RunCommand($"del Controllers\\WeatherForecastController.cs");
            AlterLaunchSettings();
            AlterStartup();
            RunCommand($"dotnet add package Deszolate.Utilities.Lite --version 0.2.2.1");
            RunCommand($"dotnet add package Microsoft.Data.SqlClient");
            log?.Invoke("Gathering database structures...");
            var dbDef             = ModelGenerator.Core.Helper.SqlDefinition.GetDatabaseDefinition <SqlConnection, SqlParameter>(connectionString, x => $"[{x}]");
            var svBuilder         = new ServiceBuilder(directory, @namespace, dbDef);
            var controllerBuilder = new ControllerBuilder(directory, @namespace, dbDef);

            log?.Invoke("Scaffolding database connector service...");
            svBuilder.Generate(ModelGenerator.Core.Provider.ServiceProvider.CSharpServiceProvider.Context);
            log?.Invoke("Scaffolding required controllers...");
            controllerBuilder.Generate(ModelGenerator.Core.Provider.ControllerProvider.CSharpControllerProvider.Context);
            log?.Invoke("Done!");
示例#2
0
        private void Button1_Click(object sender, EventArgs e)
        {
            if (!System.IO.Directory.Exists(Directory))
            {
                MessageBox.Show("You must select an output directory before trying to generate!");
                return;
            }
            var connectionString = this.txt_ConnectionString.Text;

            if (string.IsNullOrWhiteSpace(connectionString))
            {
                Log("Connection string is not provide, process aborted.");
            }
            Log($"Start generate with settings : mode : {mode} | language : {language}");
            Task.Run(() =>
            {
                DatabaseDefinition databaseDefinition = GetDatabaseDefinition(connectionString);
                try
                {
                    switch (mode)
                    {
                    case SupportMode.Model:
                        var provider = language switch
                        {
                            SupportLanguage.CSharp => CSharpModelProvider.Context,
                            SupportLanguage.TypeScript => TypeScriptModelProvider.Context,
                            SupportLanguage.VisualBasic => VisualBasicModelProvider.Context,
                            _ => throw new NotSupportedException()
                        };
                        var modelGenerator              = new ModelBuilder(Directory + "\\Models", Namespace, databaseDefinition);
                        modelGenerator.OnFileGenerated += (f) => Log($"Generated {f}");
                        modelGenerator.Generate(provider);
                        break;

                    case SupportMode.BackendService:
                        var serviceProvider = language switch
                        {
                            SupportLanguage.CSharp => CSharpServiceProvider.Context,
                            SupportLanguage.TypeScript => TypescriptServiceProvider.Context,
                            _ => throw new NotSupportedException()
                        };
                        var serviceGenerator              = new ServiceBuilder(Directory, Namespace, databaseDefinition);
                        serviceGenerator.OnFileGenerated += (f) => Log($"Generated {f}");
                        serviceGenerator.Generate(serviceProvider);
                        //GeneratorFactory.PerformRepositoryGenerate(targetLanguage, targetDatabaseConnector, txt_connectionString.Text, outputDir, txt_namespace.Text);
                        break;

                    case SupportMode.FrontendService:
                        var consumerServiceProvider = language switch
                        {
                            SupportLanguage.CSharp => CSharpConsumerServiceProvider.Context,
                            _ => throw new NotSupportedException()
                        };
                        var consumerGenerator              = new ServiceBuilder(Directory, Namespace, databaseDefinition);
                        consumerGenerator.OnFileGenerated += (f) => Log($"Geenrated {f}");
                        consumerGenerator.Generate(consumerServiceProvider);
                        break;
                    }
                    Log($"All tasks are done.");
                    this.Close();
                }
                catch (Exception ex)
                {
                    Log($"Error with message : {ex.Message}");
                }
            });
        }
示例#3
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var outputDir = txt_outputDir.Content.ToString();

            if (!Directory.Exists(outputDir))
            {
                MessageBox.Show("You must select an output directory before trying to generate!");
                return;
            }
            btn_Generate.IsEnabled = false;
            var connectionString = txt_connectionString.Text;
            var @namespace       = txt_namespace.Text;

            if (string.IsNullOrWhiteSpace(connectionString))
            {
                Log("Connection string is not provide, process aborted.");
            }
            Log($"Start generate with settings : mode : {mode} | language : {language}");
            Task.Run(async() =>
            {
                try
                {
                    DatabaseDefinition databaseDefinition = GetDatabaseDefinition(connectionString);
                    switch (mode)
                    {
                    case SupportMode.Model:
                        var provider = language switch
                        {
                            SupportLanguage.CSharp => CSharpModelProvider.Context,
                            SupportLanguage.TypeScript => TypeScriptModelProvider.Context,
                            SupportLanguage.VisualBasic => VisualBasicModelProvider.Context,
                            _ => throw new NotSupportedException()
                        };
                        var modelGenerator              = new ModelBuilder(outputDir, @namespace, databaseDefinition);
                        modelGenerator.OnFileGenerated += (f) => Log($"Generated {f}");
                        modelGenerator.Generate(provider);

                        break;

                    case SupportMode.FrontendService:
                        var consumerServiceProvider = language switch
                        {
                            SupportLanguage.CSharp => CSharpConsumerServiceProvider.Context,
                            SupportLanguage.TypeScript => TypescriptServiceProvider.Context,
                            _ => throw new NotSupportedException()
                        };
                        var consumerGenerator              = new ServiceBuilder(outputDir, @namespace, databaseDefinition);
                        consumerGenerator.OnFileGenerated += (f) => Log($"Geenrated {f}");
                        consumerGenerator.Generate(consumerServiceProvider);
                        break;

                    case SupportMode.BackendService:
                        IServiceBuilderProvider serviceProvider = language switch
                        {
                            SupportLanguage.CSharp => CSharpServiceProvider.Context,
                            _ => throw new NotSupportedException()
                        };
                        var serviceGenerator              = new ServiceBuilder(outputDir, @namespace, databaseDefinition);
                        serviceGenerator.OnFileGenerated += (f) => Log($"Generated {f}");
                        serviceGenerator.Generate(serviceProvider);
                        //GeneratorFactory.PerformRepositoryGenerate(targetLanguage, targetDatabaseConnector, txt_connectionString.Text, outputDir, txt_namespace.Text);
                        break;

                    case SupportMode.Controller:
                        IControllerProvider controllerProvider = language switch
                        {
                            SupportLanguage.CSharp => CSharpControllerProvider.Context,
                            _ => throw new NotSupportedException()
                        };
                        var controllerGenerator              = new ControllerBuilder(outputDir, @namespace, databaseDefinition);
                        controllerGenerator.OnFileGenerated += (f) => Log($"Generated {f}");
                        controllerGenerator.Generate(controllerProvider);
                        break;
                    }
                    Log($"All tasks are done.");
                    Process.Start("explorer.exe", outputDir);
                }
                catch (Exception ex)
                {
                    Log($"Error with message : {ex.Message}");
                }
            });
            btn_Generate.IsEnabled = true;
        }