コード例 #1
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);
 }
コード例 #2
0
        /// <summary>
        /// Set default values if file ConfigCli.json does not exist.
        /// </summary>
        protected override void InitConfigCli(ConfigCli configCli)
        {
            string appTypeName = UtilCli.AppTypeName(typeof(AppMain));

            configCli.WebsiteList.Add(new ConfigCliWebsite()
            {
                DomainNameList = new List <ConfigCliWebsiteDomain>(new ConfigCliWebsiteDomain[] { new ConfigCliWebsiteDomain {
                                                                                                      EnvironmentName = "DEV", DomainName = "localhost", AppTypeName = appTypeName, PasswordSalt = UtilFramework.PasswordSaltConfigCreate()
                                                                                                  } }),
                FolderNameAngular = "Application.Website/",
            });

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                // Default ConnectionString (Windows)
                configCli.EnvironmentGet().ConnectionStringApplication = "Data Source=localhost\\SQLEXPRESS; Initial Catalog=ApplicationDoc; Integrated Security=True;";
                configCli.EnvironmentGet().ConnectionStringFramework   = "Data Source=localhost\\SQLEXPRESS; Initial Catalog=ApplicationDoc; Integrated Security=True;";
            }

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                // Default ConnectionString (Linux)
                configCli.EnvironmentGet().ConnectionStringApplication = "Data Source=localhost; Initial Catalog=ApplicationDoc; User Id=SA; Password=MyPassword;";
                configCli.EnvironmentGet().ConnectionStringFramework   = "Data Source=localhost; Initial Catalog=ApplicationDoc; User Id=SA; Password=MyPassword;";
            }
        }
コード例 #3
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));
                }
            }
        }
コード例 #4
0
ファイル: CommandStart.cs プロジェクト: smfichadiya/Framework
 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;
     }
 }
コード例 #5
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);
                }
            }
        }
コード例 #6
0
        private void ExecuteDelete()
        {
            var args = UtilExternal.ExternalArgs();

            // Delete folder App/
            Console.WriteLine("Delete dest folder App/");
            UtilCli.FolderDelete(args.AppDestFolderName);

            // Copy folder Database/
            Console.WriteLine("Delete dest folder App/");
            UtilCli.FolderDelete(args.DatabaseDestFolderName);

            // Copy folder CliApp/
            Console.WriteLine("Delete dest folder CliApp/");
            UtilCli.FolderDelete(args.CliAppDestFolderName);


            // Copy folder CliDatabase/
            Console.WriteLine("Delete dest folder CliDatabase/");
            UtilCli.FolderDelete(args.CliDatabaseDestFolderName);


            // Copy folder CliDeployDb/
            Console.WriteLine("Delete dest folder CliDeployDb/");
            UtilCli.FolderDelete(args.CliDeployDbDestFolderName);

            // Copy folder Application.Website/
            Console.WriteLine("Delete dest folder Application.Website/");
            UtilCli.FolderDelete(args.WebsiteDestFolderName);
        }
コード例 #7
0
        /// <summary>
        /// Zip folder Framework.Template/ before running dotnet pack.
        /// </summary>
        public static void CommandTemplateZip()
        {
            Console.WriteLine("Create Framework.Template.zip");

            var folderNameTemplate = new Uri(new Uri(UtilCli.FolderNameFrameworkSln !), "Framework.Template/").AbsolutePath;
            var fileNameList       = UtilCli.FileNameList(folderNameTemplate);

            // Filter folder node_modules, bin, obj, vs
            fileNameList = fileNameList.Where(item => !item.Contains("/node_modules/") && !item.Contains("/bin/") && !item.Contains("/obj/") && !item.Contains("/.vs/")).ToList();

            // Temp FolderName
            var folderNameTemp = Path.GetTempPath().Replace("\\", "/") + Guid.NewGuid() + "/" + "Framework.Template/";

            Directory.CreateDirectory(folderNameTemp);

            // Copy FileName
            foreach (var fileName in fileNameList)
            {
                Debug.Assert(fileName.StartsWith(folderNameTemplate));
                var fileNameDest = folderNameTemp + fileName.Substring(folderNameTemplate.Length);
                UtilCli.FileNameCopy(fileName, fileNameDest);
            }

            // Zip
            var fileNameZip = UtilCli.FolderNameFrameworkSln + "WorkplaceX.Cli/Framework.Template.zip";

            if (File.Exists(fileNameZip))
            {
                File.Delete(fileNameZip);
            }
            ZipFile.CreateFromDirectory(folderNameTemp, fileNameZip);
            Directory.Delete(folderNameTemp, recursive: true);
        }
コード例 #8
0
        protected internal override void Execute()
        {
            // Clone external repo
            ExternalGit();

            // Copy folder Application.Website/Shared/CustomComponent/
            BuildAngularInit();

            // Run cli external command. Override for example custom components.
            CommandExternal();

            // Build layout Website(s) (npm) includes for example Bootstrap
            BuildWebsite(); // Has to be before dotnet publish! It will copy site to publish/Framework/Application.Website/

            UtilCli.VersionBuild(() => {
                // Build Angular client (npm)
                BuildAngular();

                if (OptionClientOnly.OptionGet() == false)
                {
                    // Build .NET Core server (dotnet)
                    BuildServer();
                }
            });
        }
コード例 #9
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"
            }
        }
コード例 #10
0
        /// <summary>
        /// Build all layout Websites. For example: "Application.Website/LayoutDefault"
        /// </summary>
        private void BuildWebsite()
        {
            var configCli = ConfigCli.Load();

            // Ensure FolderNameNpmBuild is defined once only in ConfigCli.json.
            ConfigCliWebsite configCliWebsite = configCli.WebsiteList.GroupBy(item => item.FolderNameNpmBuild.ToLower()).Where(group => group.Count() > 1).FirstOrDefault()?.FirstOrDefault();

            UtilFramework.Assert(configCliWebsite == null, string.Format("ConfigCli.json Website defined more than once. Use DomainNameList instead! (FolderNameNpmBuild={0})", configCliWebsite?.FolderNameNpmBuild));

            // Delete folder Application.Server/Framework/Application.Website/
            string folderNameApplicationWebsite = UtilFramework.FolderName + "Application.Server/Framework/Application.Website/";

            UtilCli.FolderDelete(folderNameApplicationWebsite);

            foreach (var website in configCli.WebsiteList)
            {
                Console.WriteLine(string.Format("### Build Website (Begin) - {0}", website.DomainNameListToString()));

                // Delete dist folder
                string folderNameDist = UtilFramework.FolderNameParse(website.FolderNameDist);
                UtilFramework.Assert(folderNameDist != null);
                UtilCli.FolderDelete(folderNameDist);

                // npm run build
                BuildWebsiteNpm(website);
                string folderNameServer = UtilFramework.FolderNameParse("Application.Server/Framework/" + website.FolderNameDist);
                UtilFramework.Assert(folderNameServer != null, "FolderNameServer can not be null!");
                UtilFramework.Assert(folderNameServer.StartsWith("Application.Server/Framework/Application.Website/"), "FolderNameServer has to start with 'Application.Server/Framework/Application.Website/'!");

                // Copy dist folder
                string folderNameSource = UtilFramework.FolderName + folderNameDist;
                string folderNameDest   = UtilFramework.FolderName + folderNameServer;
                if (!UtilCli.FolderNameExist(folderNameSource))
                {
                    throw new Exception(string.Format("Folder does not exist! ({0})", folderNameDest));
                }

                // Layout file main.js and Angular file main.js
                // Prevent for example two main.js. Angular js can not be overridden by layout Website
                // Application.Website/LayoutDefault/dist/main.js
                // Application.Server/Framework/Framework.Angular/browser/main.js
                var fileNameList = new string[] { "runtime.js", "polyfills.js", "main.js" };
                foreach (var fileName in fileNameList)
                {
                    var fileNameFull = folderNameSource + fileName;
                    if (File.Exists(fileNameFull))
                    {
                        throw new Exception(string.Format("File conflicts with Angular! See also: https://webpack.js.org/configuration/output/ ({0})", fileNameFull));
                    }
                }

                UtilCli.FolderDelete(folderNameDest);
                UtilFramework.Assert(!UtilCli.FolderNameExist(folderNameDest));
                UtilCli.FolderCopy(folderNameSource, folderNameDest, "*.*", true);
                UtilFramework.Assert(UtilCli.FolderNameExist(folderNameDest));

                Console.WriteLine(string.Format("### Build Website (End) - {0}", website.DomainNameListToString()));
            }
        }
コード例 #11
0
        /// <summary>
        /// Copy ConfigServer.json to publish folder.
        /// </summary>
        internal static void ConfigServerPublish()
        {
            string folderNamePublish = UtilFramework.FolderName + "Application.Server/bin/Debug/net5.0/publish/";

            string fileNameSource = UtilFramework.FolderName + "ConfigServer.json";
            string fileNameDest   = folderNamePublish + "ConfigServer.json";

            UtilCli.FileCopy(fileNameSource, fileNameDest);
        }
コード例 #12
0
ファイル: CommandStart.cs プロジェクト: smfichadiya/Framework
        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);
                }
            }
        }
コード例 #13
0
        /// <summary>
        /// Execute "npm run build" command.
        /// </summary>
        private static void BuildWebsiteNpm(ConfigCliWebsite website)
        {
            string folderNameNpmBuild = UtilFramework.FolderNameParse(website.FolderNameNpmBuild);

            if (UtilFramework.StringNull(folderNameNpmBuild) != null)
            {
                string folderName = UtilFramework.FolderName + folderNameNpmBuild;
                UtilCli.Npm(folderName, "install --loglevel error"); // --loglevel error prevent writing to STDERR "npm WARN optional SKIPPING OPTIONAL DEPENDENCY"
                UtilCli.Npm(folderName, "run build");
            }
        }
コード例 #14
0
        /// <summary>
        /// Write config ConnectionStringFramework and ConnectionStringApplication to ConfigCli.json and ConfigServer.json.
        /// </summary>
        private void ArgumentConnectionString()
        {
            ConfigCli configCli = ConfigCli.Load();

            if (UtilCli.ArgumentValue(this, argumentConnectionString, out string connectionString))
            {
                // Write
                configCli.EnvironmentGet().ConnectionStringFramework   = connectionString;
                configCli.EnvironmentGet().ConnectionStringApplication = connectionString;
                ConfigCli.Save(configCli);
            }
        }
コード例 #15
0
        private static void BuildServer()
        {
            string folderName        = UtilFramework.FolderName + "Application.Server/";
            string folderNamePublish = UtilFramework.FolderName + "Application.Server/bin/Debug/net5.0/publish/";

            UtilCli.FolderNameDelete(folderNamePublish);
            UtilFramework.Assert(!Directory.Exists(folderNamePublish), "Delete folder failed!");
            UtilCli.DotNet(folderName, "publish"); // Use publish instead to build.
            UtilFramework.Assert(Directory.Exists(folderNamePublish), "Deploy failed!");

            ConfigServerPublish();
        }
コード例 #16
0
ファイル: Script.cs プロジェクト: smfichadiya/Framework
        /// <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);
        }
コード例 #17
0
        public void Run(string[] args)
        {
            // Title
            commandLineApplication.FullName = "WorkplaceX.Cli";
            commandLineApplication.HelpOption("-h | --help"); // Command line interface help (to show commands)
            commandLineApplication.VersionOption("-v | --version", UtilCli.Version);

            // Register command new project
            commandLineApplication.Command("new", (configuration) =>
            {
                configuration.Description = "Create new project";
                configuration.OnExecute(() => Command(configuration, CommandNewProject));
            });

            // Register command templateZip
            if (UtilCli.FolderNameFrameworkSln != null)
            {
                var folderNameTemplate = new Uri(new Uri(UtilCli.FolderNameFrameworkSln), "Framework.Template/").AbsolutePath;
                if (Directory.Exists(folderNameTemplate))
                {
                    commandLineApplication.Command("templateZip", (configuration) =>
                    {
                        configuration.Description = "Zip folder Framework.Template/ before pack.";
                        configuration.OnExecute(() => Command(configuration, CommandTemplateZip));
                    });
                }
            }

            // Show list of available commands
            if (args.Length > 0)
            {
                commandLineApplication.Execute("-h"); // Show list of available commands.
            }

            // Debug
            Console.WriteLine("FolderNameAssembly=" + UtilCli.FolderNameAssembly);
            Console.WriteLine("FolderNameCurrent=" + UtilCli.FolderNameCurrent);
            Console.WriteLine("FolderNameFrameworkSln=" + UtilCli.FolderNameFrameworkSln);
            Console.WriteLine("FolderNameContent=" + UtilCli.FolderNameContent);
            Console.WriteLine("FolderNameAppCliExe=" + UtilCli.FolderNameAppCliExe);
            Console.WriteLine("FolderNameAppCliCsproj=" + UtilCli.FolderNameAppCliCsproj);

            // Execute command
            try
            {
                commandLineApplication.Execute(args);
            }
            catch (Exception exception) // For example unrecognized option
            {
                UtilCli.ConsoleWriteLineError(exception);
            }
        }
コード例 #18
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);
            }
        }
コード例 #19
0
        /// <summary>
        /// Read or write config ConnectionStringApplication.
        /// </summary>
        private void ArgumentConnectionStringApplication()
        {
            ConfigCli configCli = ConfigCli.Load();

            if (UtilCli.ArgumentValue(this, argumentConnectionStringApplication, out string connectionString))
            {
                // Write
                configCli.EnvironmentGet().ConnectionStringApplication = connectionString;
                ConfigCli.Save(configCli);
            }
            else
            {
                // Read
                UtilCli.ConsoleWriteLinePassword(argumentConnectionStringApplication.Name + "=" + configCli.EnvironmentGet().ConnectionStringApplication);
            }
        }
コード例 #20
0
        /// <summary>
        /// Run method AppCli.CommandExternal(); on ExternalGit/ProjectName/
        /// </summary>
        private static void CommandExternal()
        {
            var configCli = ConfigCli.Load();

            // External git url
            var externalGit = UtilFramework.StringNull(configCli.ExternalGit);

            // Call command cli external (prebuild script)
            var externalProjectName = UtilFramework.StringNull(configCli.ExternalProjectName);

            if (externalGit != null && externalProjectName != null)
            {
                string folderName = UtilFramework.FolderName + "ExternalGit/" + externalProjectName + "/" + "Application.Cli";
                UtilCli.DotNet(folderName, "run -- external");
            }
        }
コード例 #21
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();
        }
コード例 #22
0
        /// <summary>
        /// Generate CSharp property with value.
        /// </summary>
        private static void GenerateCSharpRowIntegrateField(UtilDalType.Field field, object value, StringBuilder result)
        {
            string        fieldNameCSharp = field.FieldNameCSharp;
            FrameworkType frameworkType   = UtilDalType.FrameworkTypeFromEnum(field.FrameworkTypeEnum);
            string        valueCSharp;

            if (value is string)
            {
                valueCSharp = UtilCli.EscapeCSharpString(value.ToString());
            }
            else
            {
                valueCSharp = frameworkType.ValueToCSharp(value);
            }
            result.Append(string.Format("{0} = {1}", fieldNameCSharp, valueCSharp));
        }
コード例 #23
0
        /// <summary>
        /// Clone external git repo and call prebuild script.
        /// </summary>
        private static void ExternalGit()
        {
            var configCli = ConfigCli.Load();

            // Clone repo
            var externalGit = UtilFramework.StringNull(configCli.ExternalGit);

            if (externalGit != null)
            {
                string externalFolderName = UtilFramework.FolderName + "ExternalGit/";
                if (!UtilCli.FolderNameExist(externalFolderName))
                {
                    Console.WriteLine("Git Clone ExternalGit");
                    UtilCli.FolderCreate(externalFolderName);
                    UtilCli.Start(externalFolderName, "git", "clone --recursive -q" + " " + externalGit); // --recursive clone also submodule Framework -q do not write to stderr on linux
                }
            }
        }
コード例 #24
0
ファイル: CommandBuild.cs プロジェクト: smfichadiya/Framework
        /// <summary>
        /// Build all layout Websites. For example: "Application.Website/LayoutDefault"
        /// </summary>
        private void BuildWebsite()
        {
            var configCli = ConfigCli.Load();

            // Ensure FolderNameNpmBuild is defined once only in ConfigCli.json.
            ConfigCliWebsite configCliWebsite = configCli.WebsiteList.GroupBy(item => item.FolderNameNpmBuild.ToLower()).Where(group => group.Count() > 1).FirstOrDefault()?.FirstOrDefault();

            UtilFramework.Assert(configCliWebsite == null, string.Format("ConfigCli.json Website defined more than once. Use DomainNameList instead! (FolderNameNpmBuild={0})", configCliWebsite?.FolderNameNpmBuild));

            // Delete folder Application.Server/Framework/Application.Website/
            string folderNameApplicationWebsite = UtilFramework.FolderName + "Application.Server/Framework/Application.Website/";

            UtilCli.FolderDelete(folderNameApplicationWebsite);

            foreach (var website in configCli.WebsiteList)
            {
                Console.WriteLine(string.Format("### Build Website (Begin) - {0}", website.DomainNameListToString()));

                // Delete dist folder
                string folderNameDist = UtilFramework.FolderNameParse(website.FolderNameDist);
                UtilFramework.Assert(folderNameDist != null);
                UtilCli.FolderDelete(folderNameDist);

                // npm run build
                BuildWebsiteNpm(website);
                string folderNameServer = UtilFramework.FolderNameParse(website.FolderNameServerGet(configCli));
                UtilFramework.Assert(folderNameServer != null, "FolderNameServer can not be null!");
                UtilFramework.Assert(folderNameServer.StartsWith("Application.Server/Framework/Application.Website/"), "FolderNameServer has to start with 'Application.Server/Framework/Application.Website/'!");

                // Copy dist folder
                string folderNameSource = UtilFramework.FolderName + folderNameDist;
                string folderNameDest   = UtilFramework.FolderName + folderNameServer;
                if (!UtilCli.FolderNameExist(folderNameSource))
                {
                    throw new Exception(string.Format("Folder does not exist! ({0})", folderNameDest));
                }
                UtilCli.FolderDelete(folderNameDest);
                UtilFramework.Assert(!UtilCli.FolderNameExist(folderNameDest));
                UtilCli.FolderCopy(folderNameSource, folderNameDest, "*.*", true);
                UtilFramework.Assert(UtilCli.FolderNameExist(folderNameDest));

                Console.WriteLine(string.Format("### Build Website (End) - {0}", website.DomainNameListToString()));
            }
        }
コード例 #25
0
        /// <summary>
        /// Copy folder Application.Website/Shared/CustomComponent/
        /// </summary>
        private static void BuildAngularInit()
        {
            // Delete folder Application.Website/
            string folderNameApplicationWebSite = UtilFramework.FolderName + "Framework/Framework.Angular/application/src/Application.Website/";

            UtilCli.FolderDelete(folderNameApplicationWebSite);

            // Copy folder CustomComponent/
            string folderNameSource = UtilFramework.FolderName + "Application.Website/Shared/CustomComponent/";
            string folderNameDest   = UtilFramework.FolderName + "Framework/Framework.Angular/application/src/Application.Website/Shared/CustomComponent/";

            UtilCli.FolderCopy(folderNameSource, folderNameDest, "*.*", true);

            // Copy empty index.html file
            UtilCli.FileCopy(UtilFramework.FolderName + "Framework/Framework.Angular/application/src/index.html", UtilFramework.FolderName + "Framework/Framework.Angular/application/src/Application.Website/dist/index.html");

            // Ensure folder exists now
            UtilFramework.Assert(Directory.Exists(folderNameApplicationWebSite));
        }
コード例 #26
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);
            }
        }
コード例 #27
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();
        }
コード例 #28
0
        /// <summary>
        /// Build Framework/Framework.Angular/application/.
        /// </summary>
        private static void BuildAngular()
        {
            // Build SSR
            {
                string folderName = UtilFramework.FolderName + "Framework/Framework.Angular/application/";
                UtilCli.Npm(folderName, "install --loglevel error");              // Angular install. --loglevel error prevent writing to STDERR "npm WARN optional SKIPPING OPTIONAL DEPENDENCY"
                UtilCli.Npm(folderName, "run build:ssr", isRedirectStdErr: true); // Build Server-side Rendering (SSR) to folder Framework/Framework.Angular/application/server/dist/ // TODO Bug report Angular build writes to stderr. Repo steps: Delete node_modules and run npm install and then run build:ssr.
            }

            // Copy output dist folder
            {
                string folderNameSource = UtilFramework.FolderName + "Framework/Framework.Angular/application/dist/application/";
                string folderNameDest   = UtilFramework.FolderName + "Application.Server/Framework/Framework.Angular/";

                // Copy folder
                UtilCli.FolderDelete(folderNameDest);
                UtilFramework.Assert(!Directory.Exists(folderNameDest));
                UtilCli.FolderCopy(folderNameSource, folderNameDest, "*.*", true);
                UtilFramework.Assert(Directory.Exists(folderNameDest));
            }
        }
コード例 #29
0
        protected internal override void Execute()
        {
            ConfigCli configCli          = ConfigCli.Load();
            string    environmentNameOld = configCli.EnvironmentName;

            if (UtilCli.ArgumentValueIsExist(this, argumentName))
            {
                if (UtilCli.ArgumentValue(this, argumentName, out string name))
                {
                    configCli.EnvironmentName = name?.ToUpper();
                }
            }

            configCli.EnvironmentGet(); // Get or init

            if (configCli.EnvironmentName != environmentNameOld)
            {
                ConsoleWriteLineCurrentEnvironment(configCli);
            }

            ConfigCli.Save(configCli);
        }
コード例 #30
0
 public static void ConsoleWriteLineCurrentEnvironment(ConfigCli configCli)
 {
     UtilCli.ConsoleWriteLineColor(string.Format("Current Environment (Name={0})", configCli.EnvironmentNameGet()), ConsoleColor.Green);
 }