Ejemplo n.º 1
0
 public CommandBase(AppCli appCli, string name, string description)
 {
     this.AppCli = appCli;
     this.AppCli.CommandList.Add(this);
     this.Name        = name;
     this.Description = description;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Create default ConfigCli.json file.
        /// </summary>
        public static void Init(AppCli appCli)
        {
            if (!File.Exists(FileName))
            {
                ConfigCli configCli = new ConfigCli();
                configCli.EnvironmentName = configCli.EnvironmentNameGet();
                configCli.EnvironmentList = new List <ConfigCliEnvironment>();
                configCli.WebsiteList     = new List <ConfigCliWebsite>();
                appCli.InitConfigCli(configCli);

                // EnvironmentName defined in WebsiteList
                List <string> environmentNameList = new List <string>();
                foreach (var website in configCli.WebsiteList)
                {
                    foreach (var domainName in website.DomainNameList)
                    {
                        environmentNameList.Add(domainName.EnvironmentName);
                    }
                }
                environmentNameList = environmentNameList.Distinct().ToList();

                // Add missing environments
                foreach (var environmentName in environmentNameList)
                {
                    if (configCli.EnvironmentList.Where(item => item.EnvironmentName == environmentName).FirstOrDefault() == null)
                    {
                        configCli.EnvironmentList.Add(new ConfigCliEnvironment {
                            EnvironmentName = environmentName, IsUseDeveloperExceptionPage = environmentName == "DEV"
                        });
                    }
                }
                UtilFramework.ConfigSave(configCli, FileName);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Script to generate CSharp code. Returns true, if succsesful.
        /// </summary>
        /// <param name="isFrameworkDb">If true, generate CSharp code for Framework library (internal use only) otherwise generate code for Application.</param>
        public static bool Run(bool isFrameworkDb, AppCli appCli)
        {
            bool isSuccessful = true;

            MetaSql    metaSql    = new MetaSql(isFrameworkDb, appCli);
            MetaCSharp metaCSharp = new MetaCSharp(metaSql);

            // Generate CSharp classes from database schema and save (*.cs) files.
            new CSharpGenerate(metaCSharp).Run(isFrameworkDb, out string cSharp);
            if (isFrameworkDb == false)
            {
                UtilFramework.FileSave(UtilFramework.FolderName + "Application.Database/Database/Database.cs", cSharp);
            }
            else
            {
                UtilFramework.FileSave(UtilFramework.FolderName + "Framework/Framework/Database/Database.cs", cSharp);
            }
            UtilCli.ConsoleWriteLineColor("Generate CSharp classes from database schema and write (*.cs) files succsesful!", ConsoleColor.Green);

            // Read Integrate data from database and save (*.cs) files.
            GenerateIntegrateResult generateIntegrateResult = null;

            try
            {
                generateIntegrateResult = appCli.CommandGenerateIntegrateInternal();
            }
            catch (SqlException exception)
            {
                isSuccessful = false;
                string message = string.Format("Read Integrate data from database failed! This can happen after an sql schema change. Try to run generate script again! ({0})", exception.Message);
                UtilCli.ConsoleWriteLineColor(message, ConsoleColor.Red);
            }
            if (generateIntegrateResult != null)
            {
                Run(generateIntegrateResult);
                new GenerateCSharpIntegrate().Run(out string cSharpCli, isFrameworkDb, isApplication: false, integrateList: generateIntegrateResult.Result);
                new GenerateCSharpIntegrate().Run(out string cSharpApplication, isFrameworkDb, isApplication: true, integrateList: generateIntegrateResult.Result);
                if (isFrameworkDb == false)
                {
                    UtilFramework.FileSave(UtilFramework.FolderName + "Application.Cli/Database/DatabaseIntegrate.cs", cSharpCli);
                    UtilFramework.FileSave(UtilFramework.FolderName + "Application.Database/Database/DatabaseIntegrate.cs", cSharpApplication);
                }
                else
                {
                    UtilFramework.FileSave(UtilFramework.FolderName + "Framework/Framework.Cli/Database/DatabaseIntegrate.cs", cSharpCli);
                    UtilFramework.FileSave(UtilFramework.FolderName + "Framework/Framework/Database/DatabaseIntegrate.cs", cSharpApplication);
                }
                UtilCli.ConsoleWriteLineColor("Generate CSharp code for Integrate data and write to (*.cs) files successful!", ConsoleColor.Green);
            }

            return(isSuccessful);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Populate sql Integrate tables.
        /// </summary>
        private void Integrate()
        {
            var             generateIntegrateResult = AppCli.CommandGenerateIntegrateInternal();
            var             deployDbResult          = new DeployDbIntegrateResult(generateIntegrateResult);
            List <Assembly> assemblyList            = AppCli.AssemblyList(isIncludeApp: true, isIncludeFrameworkCli: true);

            // Populate sql tables FrameworkTable, FrameworkField.
            UtilCli.ConsoleWriteLineColor("Update FrameworkTable, FrameworkField tables", ConsoleColor.Green);
            Meta(deployDbResult);
            UtilDalUpsertIntegrate.UpsertAsync(deployDbResult.Result, assemblyList).Wait();

            // Populate sql Integrate tables.
            UtilCli.ConsoleWriteLineColor("Update Integrate tables", ConsoleColor.Green);
            AppCli.CommandDeployDbIntegrateInternal(deployDbResult);
            UtilDalUpsertIntegrate.UpsertAsync(deployDbResult.Result, assemblyList).Wait();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Populate sql tables FrameworkTable, FrameworkField with assembly typeRow.
        /// </summary>
        private void Meta(DeployDbIntegrateResult result)
        {
            var         assemblyList = AppCli.AssemblyList(isIncludeApp: true);
            List <Type> typeRowList  = UtilDalType.TypeRowList(assemblyList);
            // Table
            {
                List <FrameworkTable> rowList = new List <FrameworkTable>();
                foreach (Type typeRow in typeRowList)
                {
                    FrameworkTable table = new FrameworkTable();
                    rowList.Add(table);
                    table.TableNameCSharp = UtilDalType.TypeRowToTableNameCSharp(typeRow);
                    if (UtilDalType.TypeRowIsTableNameSql(typeRow))
                    {
                        table.TableNameSql = UtilDalType.TypeRowToTableNameWithSchemaSql(typeRow);
                    }
                    table.IsDelete = false;
                }
                result.Add(rowList);
            }

            // Field
            {
                List <FrameworkFieldIntegrate> rowList = new List <FrameworkFieldIntegrate>();
                foreach (Type typeRow in typeRowList)
                {
                    string tableNameCSharp = UtilDalType.TypeRowToTableNameCSharp(typeRow);
                    var    fieldList       = UtilDalType.TypeRowToFieldList(typeRow);
                    foreach (var field in fieldList)
                    {
                        FrameworkFieldIntegrate fieldIntegrate = new FrameworkFieldIntegrate();
                        rowList.Add(fieldIntegrate);

                        fieldIntegrate.TableIdName     = tableNameCSharp;
                        fieldIntegrate.FieldNameCSharp = field.PropertyInfo.Name;
                        fieldIntegrate.FieldNameSql    = field.FieldNameSql;
                        fieldIntegrate.Sort            = field.Sort;
                        fieldIntegrate.IsDelete        = false;
                    }
                }

                rowList = rowList.OrderBy(item => item.TableIdName).ThenBy(item => item.FieldNameCSharp).ToList();

                result.Add(rowList);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Populate sql Integrate tables.
        /// </summary>
        private void Integrate(int?reseed)
        {
            var             generateIntegrateResult = AppCli.CommandGenerateIntegrateInternal(isDeployDb: true, null);
            var             deployDbResult          = new DeployDbIntegrateResult(generateIntegrateResult);
            List <Assembly> assemblyList            = AppCli.AssemblyList(isIncludeApp: true, isIncludeFrameworkCli: true);

            // Populate sql tables FrameworkTable, FrameworkField.
            UtilCli.ConsoleWriteLineColor("Update FrameworkTable, FrameworkField tables", ConsoleColor.Green);
            Meta(deployDbResult);
            IntegrateReseed(deployDbResult.Result, reseed, assemblyList);
            UtilDalUpsertIntegrate.UpsertAsync(deployDbResult.Result, assemblyList).Wait();

            // Populate sql Integrate tables.
            UtilCli.ConsoleWriteLineColor("Update Integrate tables ", ConsoleColor.Green, isLine: false);
            AppCli.CommandDeployDbIntegrateInternal(deployDbResult);
            IntegrateReseed(deployDbResult.Result, reseed, assemblyList);
            UtilDalUpsertIntegrate.UpsertAsync(deployDbResult.Result, assemblyList, (typeRow) => UtilCli.ConsoleWriteLineColor(".", ConsoleColor.Green, isLine: false)).Wait(); // See also property IsDeploy
            Console.WriteLine();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Constructor runs Schema.sql.
        /// </summary>
        /// <param name="isFrameworkDb">For internal use only.</param>
        public MetaSql(bool isFrameworkDb, AppCli appCli)
        {
            MetaSqlDbContext dbContext = new MetaSqlDbContext(isFrameworkDb);
            string           sql       = UtilFramework.FileLoad(UtilFramework.FolderName + "Framework/Framework.Cli/Generate/Sql/Schema.sql");

            this.List = dbContext.Schema.FromSqlRaw(sql).ToArray(); // Schema changes can cause timeout. Run sql command "exec sp_updatestats" on master database. If "select * from sys.columns" is slow, free up some memory.
            //
            // For Application filter out "dbo.Framework" tables.
            if (isFrameworkDb == false)
            {
                this.List = this.List.Where(item => !(item.SchemaName.StartsWith("dbo") && item.TableName.StartsWith("Framework"))).ToArray();
                this.List = appCli.CommandGenerateFilter(this.List); // Custom table name filtering for code generation.
            }
            else
            {
                this.List = this.List.Where(item => (item.SchemaName.StartsWith("dbo") && item.TableName.StartsWith("Framework"))).ToArray();
            }
            // Filter out "sysdiagrams" table.
            this.List = this.List.Where(item => item.IsSystemTable == false).ToArray();
        }
Ejemplo n.º 8
0
        private void ExecuteCopy()
        {
            var args = UtilExternal.ExternalArgs();

            // Copy folder App/
            Console.WriteLine("Copy folder App/");
            args.FolderCopy(args.AppSourceFolderName, args.AppDestFolderName);

            // Copy folder Database/
            Console.WriteLine("Copy folder Database/");
            args.FolderCopy(args.DatabaseSourceFolderName, args.DatabaseDestFolderName);

            // Copy folder CliApp/
            args.FolderCopy(args.CliAppSourceFolderName, args.CliAppDestFolderName);
            Console.WriteLine("Copy folder CliApp/");

            // Copy folder CliDatabase/
            args.FolderCopy(args.CliDatabaseSourceFolderName, args.CliDatabaseDestFolderName);
            Console.WriteLine("Copy folder CliDatabase/");

            Console.WriteLine("Update file DatabaseIntegrate.cs");
            args.FileReplaceLine(
                args.CliDatabaseDestFolderName + "DatabaseIntegrate.cs",
                "    public static class FrameworkConfigGridIntegrateAppCli",
                "    public static class FrameworkConfigGridIntegrateAppCli" + "External" + args.ExternalProjectName);

            args.FileReplaceLine(
                args.CliDatabaseDestFolderName + "DatabaseIntegrate.cs",
                "    public static class FrameworkConfigFieldIntegrateAppCli",
                "    public static class FrameworkConfigFieldIntegrateAppCli" + "External" + args.ExternalProjectName);

            // Copy folder CliDeployDb/
            Console.WriteLine("Copy folder CliDeployDb/");
            args.FolderCopy(args.CliDeployDbSourceFolderName, args.CliDeployDbDestFolderName);

            // Copy folder Application.Website/
            Console.WriteLine("Copy folder Application.Website/");
            args.FolderCopy(args.WebsiteSourceFolderName, args.WebsiteDestFolderName);

            AppCli.CommandExternal(args);
        }
Ejemplo n.º 9
0
        protected internal override void Execute()
        {
            string appSourceFolderName          = UtilFramework.FolderName + "Application/App/";
            string appDestFolderName            = UtilFramework.FolderNameExternal + "Application/App/ExternalGit/";
            string databaseSourceFolderName     = UtilFramework.FolderName + "Application.Database/Database/";
            string databaseDestFolderName       = UtilFramework.FolderNameExternal + "Application.Database/Database/ExternalGit/";
            string websiteSourceFolderName      = UtilFramework.FolderName + "Application.Website/";
            string websiteDestFolderName        = UtilFramework.FolderNameExternal + "Application.Website/ExternalGit/";
            string websiteAngularDestFolderName = UtilFramework.FolderNameExternal + "Framework/Framework.Angular/application/src/Application.Website/";
            var    args = new ExternalPrebuildArgs {
                AppSourceFolderName          = appSourceFolderName,
                AppDestFolderName            = appDestFolderName,
                DatabaseSourceFolderName     = databaseSourceFolderName,
                DatabaseDestFolderName       = databaseDestFolderName,
                WebsiteSourceFolderName      = websiteSourceFolderName,
                WebsiteDestFolderName        = websiteDestFolderName,
                WebsiteAngularDestFolderName = websiteAngularDestFolderName
            };

            AppCli.ExternalPrebuild(args);
        }
Ejemplo n.º 10
0
 public CommandEnvironment(AppCli appCli)
     : base(appCli, "env", "Select current environment to use for all cli commands")
 {
 }
Ejemplo n.º 11
0
 public CommandDeploy(AppCli appCli)
     : base(appCli, "deploy", "Deploy app to Azure git")
 {
 }
Ejemplo n.º 12
0
 public CommandExternal(AppCli appCli)
     : base(appCli, "external", "Run external prebuild .NET script.")
 {
 }
Ejemplo n.º 13
0
 public CommandExternal(AppCli appCli)
     : base(appCli, "external", "Copy ExternalGit folders.")
 {
 }
Ejemplo n.º 14
0
 public CommandStart(AppCli appCli)
     : base(appCli, "start", "Start server and open client in browser")
 {
 }
Ejemplo n.º 15
0
 public CommandGenerate(AppCli appCli)
     : base(appCli, "generate", "Generate CSharp code classes from database schema")
 {
 }
Ejemplo n.º 16
0
 public CommandTest(AppCli appCli)
     : base(appCli, "test", "Run unit tests")
 {
 }
Ejemplo n.º 17
0
 public CommandBuild(AppCli appCli)
     : base(appCli, "build", "Build Angular client and ASP.NET Core server")
 {
 }
Ejemplo n.º 18
0
 public CommandDeployDb(AppCli appCli)
     : base(appCli, "deployDb", "Deploy database by running sql scripts")
 {
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Script to generate CSharp code. Returns true, if succsesful.
        /// </summary>
        /// <param name="isFrameworkDb">If true, generate CSharp code for Framework library (internal use only) otherwise generate code for Application.</param>
        public static bool Run(bool isFrameworkDb, AppCli appCli)
        {
            bool    isSuccessful = true;
            MetaSql metaSql      = new MetaSql(isFrameworkDb);

            // Custom sql table and field filtering for code generation.
            var list = metaSql.List;
            var typeRowCalculatedList = new List <Type>(); // Calculated row.

            if (isFrameworkDb == false)
            {
                // Call method CommandGenerateFilter();
                Run(ref list, ref typeRowCalculatedList, appCli);
            }

            MetaCSharp metaCSharp = new MetaCSharp(list);

            // Generate CSharp classes from database schema and save (*.cs) files.
            UtilCli.ConsoleWriteLineColor("Generate CSharp classes from database schema and write (*.cs) files", ConsoleColor.Green);
            new CSharpGenerate(metaCSharp).Run(isFrameworkDb, out string cSharp);
            if (isFrameworkDb == false)
            {
                UtilFramework.FileSave(UtilFramework.FolderName + "Application.Database/Database/Database.cs", cSharp);
            }
            else
            {
                UtilFramework.FileSave(UtilFramework.FolderName + "Framework/Framework/Database/Database.cs", cSharp);
            }
            UtilCli.ConsoleWriteLineColor("Generate CSharp classes from database schema and write (*.cs) files succsesful!", ConsoleColor.Green);

            // Read Integrate data from database and save (*.cs) files.
            UtilCli.ConsoleWriteLineColor("Generate CSharp code for Integrate data and write to (*.cs) files", ConsoleColor.Green);
            GenerateIntegrateResult generateIntegrateResult = null;

            try
            {
                // TableNameCSharp defined in method AppCli.CommandGenerateFilter();
                List <string> tableNameCSharpApplicationFilterList = null;
                if (isFrameworkDb == false)
                {
                    tableNameCSharpApplicationFilterList = metaCSharp.List.GroupBy(item => item.SchemaNameCSharp + "." + item.TableNameCSharp).Select(item => item.Key).ToList();
                    var tableNameCSharpCalculatedList = typeRowCalculatedList.Select(item => UtilDalType.TypeRowToTableNameCSharp(item)).ToList();
                    tableNameCSharpApplicationFilterList.AddRange(tableNameCSharpCalculatedList);
                }

                generateIntegrateResult = appCli.CommandGenerateIntegrateInternal(isDeployDb: false, tableNameCSharpApplicationFilterList);
            }
            catch (SqlException exception)
            {
                isSuccessful = false;
                string message = string.Format("Read Integrate data from database failed! This can happen after an sql schema change. Try to run generate script again! ({0})", exception.Message);
                UtilCli.ConsoleWriteLineColor(message, ConsoleColor.Red);
            }
            if (generateIntegrateResult != null)
            {
                Run(generateIntegrateResult);
                new GenerateCSharpIntegrate().Run(out string cSharpCli, isFrameworkDb, isApplication: false, integrateList: generateIntegrateResult.Result);
                new GenerateCSharpIntegrate().Run(out string cSharpApplication, isFrameworkDb, isApplication: true, integrateList: generateIntegrateResult.Result);
                if (isFrameworkDb == false)
                {
                    UtilFramework.FileSave(UtilFramework.FolderName + "Application.Cli/Database/DatabaseIntegrate.cs", cSharpCli);
                    UtilFramework.FileSave(UtilFramework.FolderName + "Application.Database/Database/DatabaseIntegrate.cs", cSharpApplication);
                }
                else
                {
                    UtilFramework.FileSave(UtilFramework.FolderName + "Framework/Framework.Cli/Database/DatabaseIntegrate.cs", cSharpCli);
                    UtilFramework.FileSave(UtilFramework.FolderName + "Framework/Framework/Database/DatabaseIntegrate.cs", cSharpApplication);
                }
                UtilCli.ConsoleWriteLineColor("Generate CSharp code for Integrate data and write to (*.cs) files successful!", ConsoleColor.Green);
            }

            return(isSuccessful);
        }
Ejemplo n.º 20
0
 public CommandConfig(AppCli appCli)
     : base(appCli, "config", "Read and write configuration")
 {
 }
Ejemplo n.º 21
0
        /// <summary>
        /// Call method CommandGenerateFilter();
        /// </summary>
        private static void Run(ref MetaSqlSchema[] list, ref List <Type> typeRowCalculatedList, AppCli appCli)
        {
            var args   = new GenerateFilterArgs(list);
            var result = new GenerateFilterResult();

            // Args for calculated row
            var         assemblyList = appCli.AssemblyList(isIncludeApp: true);
            List <Type> typeRowList  = UtilDalType.TypeRowList(assemblyList);

            foreach (Type typeRow in typeRowList)
            {
                if (UtilDalType.TypeRowIsTableNameSql(typeRow) == false) // Calculated row
                {
                    args.TypeRowCalculatedList.Add(typeRow);
                }
            }

            // Call method CommandGenerateFilter();
            appCli.CommandGenerateFilter(args, result);

            // Result
            if (result.FieldSqlList != null)
            {
                list = result.List;
            }
            if (result.TypeRowCalculatedList == null)
            {
                typeRowCalculatedList = args.TypeRowCalculatedList;
            }
            else
            {
                typeRowCalculatedList = result.TypeRowCalculatedList;
            }
        }