Beispiel #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);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Tag version build.
        /// </summary>
        internal static void VersionBuild(Action build)
        {
            // Read UtilFramework.cs
            string fileNameServer = UtilFramework.FolderName + "Framework/Framework/UtilFramework.cs";
            string textServer     = UtilFramework.FileLoad(fileNameServer);
            string fileNameClient = UtilFramework.FolderName + "Framework/Framework.Angular/application/src/app/data.service.ts";
            string textClient     = UtilFramework.FileLoad(fileNameClient);

            string versionBuild = string.Format("Build (WorkplaceX={3}; Commit={0}; Pc={1}; Time={2} (UTC);)", UtilCli.GitCommit(), System.Environment.MachineName, UtilFramework.DateTimeToString(DateTime.Now.ToUniversalTime()), UtilFramework.Version);

            string findServer    = "/* VersionBuild */"; // See also: method CommandBuild.BuildServer();
            string replaceServer = string.Format("                return \"{0}\"; /* VersionBuild */", versionBuild);
            string findClient    = "/* VersionBuild */"; // See also: file data.service.ts
            string replaceClient = string.Format("  public VersionBuild: string = \"{0}\"; /* VersionBuild */", versionBuild);

            // Write UtilFramework.cs
            string textNewServer = UtilFramework.ReplaceLine(textServer, findServer, replaceServer);

            File.WriteAllText(fileNameServer, textNewServer);
            string textNewClient = UtilFramework.ReplaceLine(textClient, findClient, replaceClient);

            File.WriteAllText(fileNameClient, textNewClient);

            try
            {
                build();
            }
            finally
            {
                File.WriteAllText(fileNameServer, textServer); // Back to original text.
                File.WriteAllText(fileNameClient, textClient); // Back to original text.
            }
        }
Beispiel #3
0
        /// <summary>
        /// Execute (*.sql) scripts.
        /// </summary>
        private void DeployDbExecute(string folderName, bool isFrameworkDb)
        {
            // SELECT FrameworkDeployDb
            var rowList = Data.Query <FrameworkDeployDb>().QueryExecute();

            // 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.OrderBy(item => item).ToList();
            foreach (string fileName in fileNameList)
            {
                if (rowList.Select(item => item.FileName.ToLower()).Contains(fileName.ToLower()) == false)
                {
                    string fileNameFull = UtilFramework.FolderName + fileName;
                    Console.WriteLine(string.Format("Execute {0}", fileNameFull));
                    string sql = UtilFramework.FileLoad(fileNameFull);
                    Data.ExecuteNonQueryAsync(sql, null, isFrameworkDb, commandTimeout: 0).Wait();
                    FrameworkDeployDb row = new FrameworkDeployDb()
                    {
                        FileName = fileName, Date = DateTime.UtcNow
                    };
                    Data.InsertAsync(row).Wait();
                }
            }
        }
Beispiel #4
0
            /// <summary>
            /// Find and replace a line in a text file.
            /// </summary>
            internal void FileReplaceLine(string fileName, string find, string replace)
            {
                string text = UtilFramework.FileLoad(fileName);

                text = UtilFramework.ReplaceLine(text, find, replace);
                UtilFramework.FileSave(fileName, text);
            }
Beispiel #5
0
        /// <summary>
        /// Render first html GET request.
        /// </summary>
        private static async Task <string> WebsiteServerSideRenderingAsync(HttpContext context, AppSelector appSelector, AppJson appJson)
        {
            string url;

            if (UtilServer.IsIssServer)
            {
                // Running on IIS Server.
                url  = context.Request.IsHttps ? "https://" : "http://";
                url += context.Request.Host.ToUriComponent() + "/Framework/Framework.Angular/server/main.js"; // Url of server side rendering when running on IIS Server
            }
            else
            {
                // Running in Visual Studio.
                url = "http://localhost:4000/"; // Url of server side rendering when running in Visual Studio
            }

            // Process AppJson
            string jsonClient = await appSelector.ProcessAsync(context, appJson); // Process (For first server side rendering)

            // Server side rendering POST.
            string folderNameServer = appSelector.Website.FolderNameServerGet(appSelector.ConfigServer, "Application.Server/Framework/");

            string serverSideRenderView = UtilFramework.FolderNameParse(folderNameServer, "/index.html");

            serverSideRenderView = HttpUtility.UrlEncode(serverSideRenderView);
            url += "?view=" + serverSideRenderView;

            bool   isServerSideRendering = ConfigServer.Load().IsServerSideRendering;
            string indexHtml;

            if (isServerSideRendering)
            {
                // index.html server side rendering
                indexHtml = await UtilServer.WebPost(url, jsonClient); // Server side rendering POST. http://localhost:50919/Framework/Framework.Angular/server.js?view=Application.Website%2fDefault%2findex.html
            }
            else
            {
                // index.html serve directly
                string fileName = UtilServer.FolderNameContentRoot() + UtilFramework.FolderNameParse(appSelector.Website.FolderNameServerGet(appSelector.ConfigServer, "Application.Server/"), "/index.html");
                indexHtml = UtilFramework.FileLoad(fileName);
            }

            // Set jsonBrowser in index.html.
            string scriptFind    = "</app-root>"; //" <script>var jsonBrowser={}</script>"; // For example Html5Boilerplate build process renames var jsonBrowser to a.
            string scriptReplace = "</app-root><script>var jsonBrowser = " + jsonClient + "</script>";

            if (isServerSideRendering)
            {
                indexHtml = UtilFramework.Replace(indexHtml, scriptFind, scriptReplace);
            }

            // Add Angular scripts
            scriptFind    = "</body></html>";
            scriptReplace = "<script src=\"runtime.js\" defer></script><script src=\"polyfills.js\" defer></script><script src=\"main.js\" defer></script>" +
                            "</body></html>";
            indexHtml = UtilFramework.Replace(indexHtml, scriptFind, scriptReplace);

            return(indexHtml);
        }
Beispiel #6
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);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Constructor runs Schema.sql.
        /// </summary>
        /// <param name="isFrameworkDb">For internal use only.</param>
        public MetaSql(bool isFrameworkDb)
        {
            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 == "dbo" && item.TableName.StartsWith("Framework"))).ToArray();
            }
            else
            {
                this.List = this.List.Where(item => (item.SchemaName == "dbo" && item.TableName.StartsWith("Framework"))).ToArray();
            }
            // Filter out "sysdiagrams" table.
            this.List = this.List.Where(item => item.IsSystemTable == false).ToArray();
        }