示例#1
0
        /// <summary>
        /// Execute (*Drop.sql) scripts.
        /// </summary>
        private void DeployDbDropExecute(string folderName, bool isFrameworkDb)
        {
            // FileNameList. For example "Framework/Framework.Cli/DeployDb/Config.sql"
            List <string> fileNameList = new List <string>();

            foreach (string fileName in UtilFramework.FileNameList(folderName, "*.sql"))
            {
                UtilFramework.Assert(fileName.ToLower().StartsWith(UtilFramework.FolderName.ToLower()));
                if (IsFileNameDrop(fileName))
                {
                    fileNameList.Add(fileName.Substring(UtilFramework.FolderName.Length));
                }
            }

            fileNameList = fileNameList.OrderByDescending(item => item).ToList(); // Reverse
            foreach (string fileName in fileNameList)
            {
                string fileNameFull = UtilFramework.FolderName + fileName;
                Console.WriteLine(string.Format("Execute {0}", fileNameFull));
                string sql = UtilFramework.FileLoad(fileNameFull);
                try
                {
                    Data.ExecuteNonQueryAsync(sql, null, isFrameworkDb, commandTimeout: 0).Wait();
                }
                catch
                {
                    UtilCli.ConsoleWriteLineColor("Already dropped or drop failed!", ConsoleColor.DarkYellow);
                }
            }
        }
示例#2
0
        protected internal override void Execute()
        {
            CommandBuild.ConfigServerPublish();

            ConfigCli configCli         = ConfigCli.Load();
            string    deployAzureGitUrl = UtilFramework.StringNull(configCli.EnvironmentGet().DeployAzureGitUrl); // For example: "https://*****:*****@my22.scm.azurewebsites.net:443/my22.git"

            if (deployAzureGitUrl == null)
            {
                UtilCli.ConsoleWriteLineColor(nameof(ConfigCliEnvironment.DeployAzureGitUrl) + " not set!", System.ConsoleColor.Green);
            }
            else
            {
                string folderName           = UtilFramework.FolderName + "Application.Server/";
                string folderNamePublish    = UtilFramework.FolderName + "Application.Server/bin/Debug/net5.0/publish/";
                string folderNamePublishGit = folderNamePublish + ".git";

                UtilCli.FolderDelete(folderNamePublishGit);                                            // Undo git init.
                UtilCli.Start(folderNamePublish, "git", "init -b master");                             // External system to push to.
                UtilCli.Start(folderNamePublish, "git", "config user.email \"[email protected]\""); // Prevent: Error "Please tell me who you are". See also: http://www.thecreativedev.com/solution-github-please-tell-me-who-you-are-error/
                UtilCli.Start(folderNamePublish, "git", "config user.name \"Deploy\"");
                UtilCli.Start(folderNamePublish, "git", "config core.autocrlf false");                 // Prevent "LF will be replaced by CRLF" error in stderr.
                UtilCli.Start(folderNamePublish, "git", "add .");                                      // Can throw "LF will be replaced by CRLF".
                UtilCli.Start(folderNamePublish, "git", "commit -m Deploy");
                UtilCli.Start(folderNamePublish, "git", "remote add azure " + deployAzureGitUrl);
                UtilCli.Start(folderNamePublish, "git", "push azure master -f", isRedirectStdErr: true); // Do not write to stderr. Can be tested with "dotnet run -- deploy [DeployAzureGitUrl] 2>Error.txt"
            }
        }
示例#3
0
 private void Changed(object sender, FileSystemEventArgs e)
 {
     if (isFileSync == false)
     {
         isFileSync = true;                         // Lock
         Task.Delay(100).ContinueWith((Task t) => { // Wait for further possible changes (debounce)
             try
             {
                 do
                 {
                     isChange = false;
                     UtilCli.ConsoleWriteLineColor("FileSync...", System.ConsoleColor.Green);
                     foreach (var item in folderNameList)
                     {
                         string folderNameSource = item.Key;
                         string folderNameDest   = item.Value;
                         // UtilCli.FolderDelete(folderNameDest);
                         UtilCli.FolderCopy(folderNameSource, folderNameDest, "*.*", true);
                     }
                 } while (isChange); // Change happened while syncing
             }
             finally
             {
                 isFileSync = false;
             }
         });
     }
     else
     {
         isChange = true;
     }
 }
示例#4
0
 public static int Command(CommandLineApplication command, Action action)
 {
     UtilCli.ConsoleWriteLineColor($"Command run ({ command.Name })", ConsoleColor.Green);
     action();
     UtilCli.ConsoleWriteLineColor($"Command success! ({ command.Name })", ConsoleColor.Green);
     return(0);
 }
示例#5
0
        /// <summary>
        /// Generate CSharp property for every database field.
        /// </summary>
        private static void FieldNameProperty(MetaCSharp metaCSharp, string schemaName, string tableName, StringBuilder result)
        {
            var  fieldNameList = metaCSharp.List.Where(item => item.Schema.SchemaName == schemaName && item.Schema.TableName == tableName).ToArray();
            bool isFirst       = true;

            foreach (var item in fieldNameList)
            {
                if (isFirst)
                {
                    isFirst = false;
                }
                else
                {
                    result.AppendLine();
                }
                if (item.FrameworkTypeEnum == FrameworkTypeEnum.None)
                {
                    UtilCli.ConsoleWriteLineColor(string.Format("Warning! Type not supported by framework. ({0}.{1}.{2})", item.Schema.SchemaName, item.Schema.TableName, item.Schema.FieldName), ConsoleColor.Yellow);
                }
                else
                {
                    string typeCSharp = UtilGenerate.SqlTypeToCSharpType(item.Schema.SqlType, item.Schema.IsNullable);
                    if (item.IsPrimaryKey == false)
                    {
                        result.AppendLine(string.Format("        [SqlField(\"{0}\", {2})]", item.Schema.FieldName, item.TableNameCSharp + "_" + item.FieldNameCSharp, nameof(FrameworkTypeEnum) + "." + item.FrameworkTypeEnum.ToString()));
                    }
                    else
                    {
                        result.AppendLine(string.Format("        [SqlField(\"{0}\", {2}, {3})]", item.Schema.FieldName, item.TableNameCSharp + "_" + item.FieldNameCSharp, item.IsPrimaryKey.ToString().ToLower(), nameof(FrameworkTypeEnum) + "." + item.FrameworkTypeEnum.ToString()));
                    }
                    result.AppendLine(string.Format("        public " + typeCSharp + " {0} {{ get; set; }}", item.FieldNameCSharp));
                }
            }
        }
示例#6
0
        protected internal override void Execute()
        {
            // Build angular client
            if (!UtilCli.FolderNameExist(UtilFramework.FolderName + "Application.Server/Framework/Framework.Angular/"))
            {
                var commandBuild = new CommandBuild(AppCli);
                UtilCli.OptionSet(ref commandBuild.OptionClientOnly, true);
                commandBuild.Execute();
            }

            if (optionWatch.OptionGet())
            {
                ConfigCli configCli = ConfigCli.Load();

                var website = configCli.WebsiteList.First(item => item.FolderNameDist != null); // TODO choose if multiple

                string folderNameNpmBuilt = UtilFramework.FolderName + website.FolderNameNpmBuild;
                string folderNameDist     = UtilFramework.FolderName + website.FolderNameDist;

                string folderNameAngular         = UtilFramework.FolderName + "Framework/Framework.Angular/application/";
                string folderNameCustomComponent = UtilFramework.FolderName + "Application.Website/Shared/CustomComponent/";

                UtilCli.ConsoleWriteLineColor("Port: http://localhost:4200/", System.ConsoleColor.Green);
                UtilCli.ConsoleWriteLineColor("Website: " + folderNameNpmBuilt, System.ConsoleColor.Green);
                UtilCli.ConsoleWriteLineColor("CustomComponent: " + folderNameCustomComponent, System.ConsoleColor.Green);
                UtilCli.ConsoleWriteLineColor("Framework: " + folderNameAngular, System.ConsoleColor.Green);

                FileSync fileSync = new FileSync();
                fileSync.AddFolder(folderNameDist, folderNameAngular + "src/Application.Website/Default/"); // TODO
                fileSync.AddFolder(folderNameCustomComponent, folderNameAngular + "src/Application.Website/Shared/CustomComponent/");

                UtilCli.Npm(folderNameNpmBuilt, "run build -- --watch", isWait: false);
                UtilCli.Npm(folderNameAngular, "start", isWait: true);
            }
            else
            {
                string folderName = UtilFramework.FolderName + @"Application.Server/";
                UtilCli.VersionBuild(() =>
                {
                    UtilCli.DotNet(folderName, "build");
                });
                UtilCli.DotNet(folderName, "run --no-build", false);
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    UtilCli.OpenWebBrowser("http://localhost:50919/"); // For port setting see also: Application.Server\Properties\launchSettings.json (applicationUrl, sslPort)
                }
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    // Ubuntu list all running processes: 'ps'
                    // To reboot Ubuntu type on Windows command prompt: 'wsl -t Ubuntu-18.04'
                    // Ubuntu show processes tool: 'htop'
                    UtilCli.ConsoleWriteLineColor("Stop server with command: 'killall -SIGKILL Application.Server node dotnet'", System.ConsoleColor.Yellow);
                }
            }
        }
示例#7
0
        protected internal override void Execute()
        {
            ConfigCli configCli = ConfigCli.Load();

            if (optionSilent.OptionGet() == false && configCli.EnvironmentNameGet() != "DEV")
            {
                if (UtilCli.ConsoleReadYesNo(string.Format("Deploy to {0} database?", configCli.EnvironmentName)) == false)
                {
                    return;
                }
            }

            if (optionDrop.OptionGet())
            {
                // FolderNameDeployDb
                string folderNameDeployDbFramework   = UtilFramework.FolderName + "Framework/Framework.Cli/DeployDb/";
                string folderNameDeployDbApplication = UtilFramework.FolderName + "Application.Cli/DeployDb/";

                Console.WriteLine("DeployDbDrop");
                DeployDbDropExecute(folderNameDeployDbApplication, isFrameworkDb: false);
                DeployDbDropExecute(folderNameDeployDbFramework, isFrameworkDb: true); // Uses ConnectionString in ConfigServer.json

                UtilCli.ConsoleWriteLineColor("DeployDb drop successful!", ConsoleColor.Green);
            }
            else
            {
                // FolderNameDeployDb
                string folderNameDeployDbFramework   = UtilFramework.FolderName + "Framework/Framework.Cli/DeployDb/";
                string folderNameDeployDbApplication = UtilFramework.FolderName + "Application.Cli/DeployDb/";

                // SqlInit
                string fileNameInit = UtilFramework.FolderName + "Framework/Framework.Cli/DeployDbInit/Init.sql";
                string sqlInit      = UtilFramework.FileLoad(fileNameInit);
                Data.ExecuteNonQueryAsync(sqlInit, null, isFrameworkDb: true).Wait();

                // (*.sql)
                UtilCli.ConsoleWriteLineColor("DeployDb run (*.sql) scripts", ConsoleColor.Green);
                DeployDbExecute(folderNameDeployDbFramework, isFrameworkDb: true); // Uses ConnectionString in ConfigServer.json
                DeployDbExecute(folderNameDeployDbApplication, isFrameworkDb: false);
                UtilCli.ConsoleWriteLineColor("DeployDb run (*.sql) scripts successful!", ConsoleColor.Green);

                // Integrate
                UtilCli.ConsoleWriteLineColor("DeployDb run Integrate", ConsoleColor.Green);
                int?reseed = null;
                if (optionReseed.OptionGet())
                {
                    reseed = 1000;
                }
                Integrate(reseed);
                UtilCli.ConsoleWriteLineColor("DeployDb run Integrate successful!", ConsoleColor.Green);
            }
        }
示例#8
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);
        }
示例#9
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();
        }
示例#10
0
        protected internal override void Execute()
        {
            ConfigCli configCli = ConfigCli.Load();

            if (optionSilent.OptionGet() == false && configCli.EnvironmentNameGet() != "DEV")
            {
                if (UtilCli.ConsoleReadYesNo(string.Format("Generate CSharp code from {0} database?", configCli.EnvironmentName)) == false)
                {
                    return;
                }
            }

            bool isFrameworkDb = optionFramework.OptionGet();

            if (Script.Run(isFrameworkDb, AppCli))
            {
                UtilCli.ConsoleWriteLineColor("Generate successful!", ConsoleColor.Green);
            }
        }
示例#11
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();
        }
示例#12
0
 public static void ConsoleWriteLineCurrentEnvironment(ConfigCli configCli)
 {
     UtilCli.ConsoleWriteLineColor(string.Format("Current Environment (Name={0})", configCli.EnvironmentNameGet()), ConsoleColor.Green);
 }
示例#13
0
        protected internal override void Execute()
        {
            // Build angular client
            if (!UtilCli.FolderNameExist(UtilFramework.FolderName + "Application.Server/Framework/Framework.Angular/"))
            {
                var commandBuild = new CommandBuild(AppCli);
                UtilCli.OptionSet(ref commandBuild.OptionClientOnly, true);
                commandBuild.Execute();
            }

            if (optionWatch.OptionGet())
            {
                {
                    ConfigCli configCli = ConfigCli.Load();

                    Console.WriteLine("Select Website:");

                    for (int i = 0; i < configCli.WebsiteList.Count; i++)
                    {
                        Console.WriteLine(string.Format("{0}={1}", i + 1, configCli.WebsiteList[i].FolderNameNpmBuild));
                    }

                    Console.Write("Website: ");

                    var websiteIndex = int.Parse(Console.ReadLine()) - 1;

                    var website = configCli.WebsiteList[websiteIndex];

                    string folderNameNpmBuilt = UtilFramework.FolderName + website.FolderNameNpmBuild;
                    string folderNameDist     = UtilFramework.FolderName + website.FolderNameDist;

                    string folderNameAngular         = UtilFramework.FolderName + "Framework/Framework.Angular/application/";
                    string folderNameCustomComponent = UtilFramework.FolderName + "Application.Website/Shared/CustomComponent/";

                    Console.WriteLine("Copy folder dist/");
                    UtilCli.FolderCopy(folderNameDist, folderNameAngular + "src/Application.Website/dist/", "*.*", true);

                    Console.WriteLine("Copy folder CustomComponent/");
                    UtilCli.FolderCopy(folderNameCustomComponent, folderNameAngular + "src/Application.Website/Shared/CustomComponent/", "*.*", true);

                    bool isWebsiteWatch = UtilCli.ConsoleReadYesNo("Start Website npm watch?");
                    bool isFileSync     = UtilCli.ConsoleReadYesNo("Start Website FileSync (dist/ to Angular)?");
                    bool isAngular      = UtilCli.ConsoleReadYesNo("Start Angular?");
                    bool isServer       = UtilCli.ConsoleReadYesNo("Start Server?");

                    // FileSync
                    if (isFileSync)
                    {
                        FileSync fileSync = new FileSync();
                        fileSync.AddFolder(folderNameDist, folderNameAngular + "src/Application.Website/dist/");
                        fileSync.AddFolder(folderNameAngular + "src/Application.Website/Shared/CustomComponent/", folderNameCustomComponent);
                    }

                    // Website --watch
                    if (isWebsiteWatch)
                    {
                        UtilCli.Npm(folderNameNpmBuilt, "run build -- --watch", isWait: false);
                    }

                    // Angular client
                    if (isAngular)
                    {
                        UtilCli.Npm(folderNameAngular, "start -- --disable-host-check", isWait: false); // disable-host-check to allow for example http://localhost2:4200/
                    }

                    // .NET Server
                    if (isServer)
                    {
                        string folderName = UtilFramework.FolderName + @"Application.Server/";
                        UtilCli.DotNet(folderName, "run", isWait: false);
                    }

                    void heartBeat()
                    {
                        Console.WriteLine();
                        Console.WriteLine(UtilFramework.DateTimeToString(DateTime.Now));
                        if (isAngular)
                        {
                            UtilCli.ConsoleWriteLineColor("Angular: http://" + website.DomainNameList.First().DomainName + ":4200/", System.ConsoleColor.Green);
                        }
                        if (isServer)
                        {
                            UtilCli.ConsoleWriteLineColor("Server: http://" + website.DomainNameList.First().DomainName + ":50919/", System.ConsoleColor.Green);
                        }
                        if (isFileSync)
                        {
                            UtilCli.ConsoleWriteLineColor("Modify Website: " + folderNameNpmBuilt, System.ConsoleColor.Green);
                            UtilCli.ConsoleWriteLineColor("Modify CustomComponent: " + folderNameCustomComponent, System.ConsoleColor.Green);
                        }
                        if (isAngular)
                        {
                            UtilCli.ConsoleWriteLineColor("Modify Angular: " + folderNameAngular, System.ConsoleColor.Green);
                        }
                        Task.Delay(5000).ContinueWith((Task task) => heartBeat());
                    }

                    if (isFileSync || isWebsiteWatch || isAngular || isServer)
                    {
                        heartBeat();
                        while (true)
                        {
                            Console.ReadLine(); // Program would end and with it FileSync
                        }
                    }
                }
            }
            else
            {
                string folderName = UtilFramework.FolderName + @"Application.Server/";
                UtilCli.VersionBuild(() =>
                {
                    UtilCli.DotNet(folderName, "build");
                });
                UtilCli.DotNet(folderName, "run --no-build", false);
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    UtilCli.OpenWebBrowser("http://localhost:50919/"); // For port setting see also: Application.Server\Properties\launchSettings.json (applicationUrl, sslPort)
                }
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    // Ubuntu list all running processes: 'ps'
                    // To reboot Ubuntu type on Windows command prompt: 'wsl -t Ubuntu-18.04'
                    // Ubuntu show processes tool: 'htop'
                    UtilCli.ConsoleWriteLineColor("Stop server with command 'killall -SIGKILL Application.Server node dotnet'", System.ConsoleColor.Yellow);
                }
            }
        }
示例#14
0
        private void ArgumentWebsite()
        {
            ConfigCli configCli = ConfigCli.Load();

            // Input DomainName
            Console.WriteLine("Enter domain name. For example: 'example.com' or empty for default website:");
            Console.Write(">");
            string domainName = Console.ReadLine();

            // Input AppTypeName
            Console.WriteLine("Enter AppTypeName. For example: 'Application.AppMain, Application':");
            Console.Write(">");
            string appTypeName = Console.ReadLine();

            if (Type.GetType(appTypeName) == null)
            {
                UtilCli.ConsoleWriteLineColor(string.Format("Type not found! ({0})", appTypeName), ConsoleColor.Yellow);
            }

            // Input FolderName
            Console.WriteLine("Enter npm build folder name. Or empty if no build. For example: 'Application.Website/LayoutDefault/'. In this folder ci calls npm install; npm build;");
            Console.Write(">");
            string folderNameNpmBuild = Console.ReadLine();

            folderNameNpmBuild = UtilFramework.FolderNameParse(folderNameNpmBuild);

            string folderNameNpmBuildCheck = UtilFramework.FolderName + folderNameNpmBuild;

            if (!Directory.Exists(folderNameNpmBuildCheck))
            {
                UtilCli.ConsoleWriteLineColor(string.Format("Folder does not exist! ({0})", folderNameNpmBuild), ConsoleColor.Yellow);
            }

            // Input FolderNameDist
            Console.WriteLine("Enter dist folder name. For example 'Application.Website/LayoutDefault/dist/'. Content of this folder is copied to FolderNameServer");
            Console.Write(">");
            string folderNameDist = Console.ReadLine();

            folderNameDist = UtilFramework.FolderNameParse(folderNameDist);
            string folderNameDistCheck = UtilFramework.FolderName + folderNameDist;

            if (!Directory.Exists(folderNameDistCheck))
            {
                UtilCli.ConsoleWriteLineColor(string.Format("Folder does not exist! ({0})", folderNameDist), ConsoleColor.Yellow);
            }

            // Add Website
            ConfigCliWebsite website = new ConfigCliWebsite();

            website.DomainNameList = new List <ConfigCliWebsiteDomain>();
            website.DomainNameList.Add(new ConfigCliWebsiteDomain()
            {
                EnvironmentName = configCli.EnvironmentNameGet(), DomainName = domainName, AppTypeName = appTypeName
            });
            website.FolderNameNpmBuild = folderNameNpmBuild;
            website.FolderNameDist     = folderNameDist;

            configCli.WebsiteList.Add(website);

            ConfigCli.Save(configCli);
        }
示例#15
0
        protected internal override void Execute()
        {
            ConfigCli configCli = ConfigCli.Load();

            // Command "json"
            if (UtilCli.ArgumentValueIsExist(this, argumentJson))
            {
                if (UtilCli.ArgumentValue(this, argumentJson, out string json))
                {
                    // Set ConfigCli.json with command: ".\cli.cmd config json='{}'"
                    json = json.Trim('\"');         // Remove quotation marks at the begin and end.
                    json = json.Replace("'", "\""); // To use it in command prompt.
                    // Write
                    try
                    {
                        configCli = UtilFramework.ConfigFromJson <ConfigCli>(json);
                    }
                    catch (Exception exception)
                    {
                        throw new Exception("ConfigCli invalid!", exception);
                    }
                    ConfigCli.Save(configCli);
                }
            }

            // Command "deployAzureGitUrl"
            if (UtilCli.ArgumentValueIsExist(this, argumentDeployAzureGitUrl))
            {
                if (UtilCli.ArgumentValue(this, argumentDeployAzureGitUrl, out string value))
                {
                    // Write
                    configCli.EnvironmentGet().DeployAzureGitUrl = value;
                    ConfigCli.Save(configCli);
                }
                else
                {
                    // Read
                    Console.WriteLine(argumentDeployAzureGitUrl.Name + "=" + configCli.EnvironmentGet().DeployAzureGitUrl);
                }
                return;
            }

            // Command "connectionString"
            if (UtilCli.ArgumentValueIsExist(this, argumentConnectionString))
            {
                ArgumentConnectionString();
                return;
            }

            // Command "connectionStringFramework"
            if (UtilCli.ArgumentValueIsExist(this, argumentConnectionStringFramework))
            {
                ArgumentConnectionStringFramework();
                return;
            }

            // Command "connectionStringApplication"
            if (UtilCli.ArgumentValueIsExist(this, argumentConnectionStringApplication))
            {
                ArgumentConnectionStringApplication();
                return;
            }

            // Command "website"
            if (UtilCli.ArgumentValueIsExist(this, argumentWebsite))
            {
                ArgumentWebsite();
                return;
            }

            // Print ConfigCli.json to screen
            {
                configCli = ConfigCli.Load();
                Console.WriteLine();
                UtilCli.ConsoleWriteLineColor("Add the following environment variable to ci build server: (Value including double quotation marks!)", ConsoleColor.Green);
                string json = UtilFramework.ConfigToJson(configCli, isIndented: false);
                json = json.Replace("\"", "'"); // To use it in command prompt.
                UtilCli.ConsoleWriteLineColor("ConfigCli=", ConsoleColor.DarkGreen);
                UtilCli.ConsoleWriteLineColor(string.Format("\"{0}\"", json), ConsoleColor.DarkGreen);
                Console.WriteLine();
            }
        }
示例#16
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);
        }