/// <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); }
/// <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. } }
/// <summary> /// Add unique key. /// </summary> public void AddKey <TRow>(params string[] fieldNameKeyList) where TRow : Row { Type typeRow = typeof(TRow); // Asser table name ends with Integrate string tableNameCSharp = UtilDalType.TypeRowToTableNameCSharp(typeRow); UtilFramework.Assert(!tableNameCSharp.EndsWith("Integrate"), string.Format("Do not add Integrate. Use underlying sql table! ({0})", tableNameCSharp)); // Asser field exists var fieldNameCSharpList = UtilDalType.TypeRowToFieldList(typeRow).Select(item => item.FieldNameCSharp).ToList(); foreach (var fieldNameCSharp in fieldNameKeyList) { UtilFramework.Assert(fieldNameCSharpList.Contains(fieldNameCSharp), string.Format("Field not found! ({0})", fieldNameCSharp)); } if (ResultKey.ContainsKey(typeof(TRow))) { UtilFramework.Assert(ResultKey[typeRow].SequenceEqual(fieldNameKeyList), string.Format("TypeRow added with different FieldNameKeyList! ({0})", UtilDalType.TypeRowToTableNameCSharp(typeRow))); } else { ResultKey.Add(typeRow, fieldNameKeyList); } }
/// <summary> /// Create default ConfigCli.json file. /// </summary> public static void Init(AppCli appCli) { if (!File.Exists(FileName)) { ConfigCli configCli = new ConfigCli(); configCli.EnvironmentName = configCli.EnvironmentNameGet(); configCli.EnvironmentList = new List <ConfigCliEnvironment>(); configCli.WebsiteList = new List <ConfigCliWebsite>(); appCli.InitConfigCli(configCli); // EnvironmentName defined in WebsiteList List <string> environmentNameList = new List <string>(); foreach (var website in configCli.WebsiteList) { foreach (var domainName in website.DomainNameList) { environmentNameList.Add(domainName.EnvironmentName); } } environmentNameList = environmentNameList.Distinct().ToList(); // Add missing environments foreach (var environmentName in environmentNameList) { if (configCli.EnvironmentList.Where(item => item.EnvironmentName == environmentName).FirstOrDefault() == null) { configCli.EnvironmentList.Add(new ConfigCliEnvironment { EnvironmentName = environmentName, IsUseDeveloperExceptionPage = environmentName == "DEV" }); } } UtilFramework.ConfigSave(configCli, FileName); } }
internal static ConfigServer Load() { ConfigServer result; if (File.Exists(FileName)) { result = UtilFramework.ConfigLoad <ConfigServer>(FileName); } else { result = Init(); } if (result.WebsiteList == null) { result.WebsiteList = new List <ConfigServerWebsite>(); } foreach (var website in result.WebsiteList) { if (website.DomainNameList == null) { website.DomainNameList = new List <ConfigServerWebsiteDomain>(); } } return(result); }
/// <summary> /// Returns Framework, Application.Database, Application and Framework.Cli assembly when running in cli mode. /// </summary> /// <param name="isIncludeApp">If true, Application assembly (with App class and derived custom logic) is included.</param> /// <param name="isIncludeFrameworkCli">If true, Framework.Cli assembly is included</param> /// <returns>List of assemblies.</returns> internal List <Assembly> AssemblyList(bool isIncludeApp = false, bool isIncludeFrameworkCli = false) { List <Assembly> result = new List <Assembly> { AssemblyFramework, AssemblyApplicationDatabase }; if (isIncludeApp) { result.Add(AssemblyApplication); } if (isIncludeFrameworkCli) { result.Add(AssemblyFrameworkCli); } // No assembly double in result! int count = result.Count(); result = result.Distinct().ToList(); UtilFramework.Assert(count == result.Count); return(result); }
/// <summary> /// Returns html content type. /// </summary> public static string ContentType(string fileName) { // ContentType string fileNameExtension = UtilFramework.FileNameExtension(fileName); string result; // https://www.sitepoint.com/web-foundations/mime-types-complete-list/ switch (fileNameExtension) { case ".html": result = "text/html"; break; case ".css": result = "text/css"; break; case ".js": result = "text/javascript"; break; case ".map": result = "text/plain"; break; case ".png": result = "image/png"; break; case ".ico": result = "image/x-icon"; break; case ".jpg": result = "image/jpeg"; break; case ".pdf": result = "application/pdf"; break; case ".json": result = "application/json"; break; case ".xlsx": result = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break; default: result = "text/plain"; break; // Type not found! } return(result); }
/// <summary> /// Returns JsonClient. Create AppJson and process request. /// </summary> internal async Task <string> ProcessAsync(HttpContext context, AppJson appJson) { if (appJson == null) { // Create AppJson with session data. appJson = await CreateAppJsonSession(context); } // Process try { await appJson.ProcessInternalAsync(appJson); } catch (Exception exception) { appJson.BootstrapAlert(UtilFramework.ExceptionToString(exception), BootstrapAlertEnum.Error); appJson.IsReload = true; } // Version tag RenderVersion(appJson); // RequestCount appJson.RequestCount = appJson.RequestJson.RequestCount; // ResponseCount appJson.ResponseCount += 1; // SerializeSession, SerializeClient UtilSession.Serialize(appJson, out string jsonClientResponse); return(jsonClientResponse); }
private static void GenerateCSharpRowIntegrate(GenerateIntegrateItem integrateItem, StringBuilder result) { var fieldNameIdCSharpReferenceList = integrateItem.Owner.ResultReference.Where(item => item.TypeRowIntegrate == integrateItem.TypeRow).Select(item => item.FieldNameIdCSharp).ToList(); var fieldList = UtilDalType.TypeRowToFieldList(integrateItem.TypeRow); foreach (Row row in integrateItem.RowList) { result.Append(string.Format(" new {0} {{", integrateItem.TableNameCSharp)); bool isFirst = true; foreach (var field in fieldList) { if (isFirst) { isFirst = false; } else { result.Append(", "); } object value = field.PropertyInfo.GetValue(row); if (fieldNameIdCSharpReferenceList.Contains(field.FieldNameCSharp) || (fieldNameIdCSharpReferenceList.Count() > 0 && field.FieldNameCSharp == "Id")) { UtilFramework.Assert(value == null || value.GetType() == typeof(int)); // Unlike IdName, Id can change from database to database. value = 0; } GenerateCSharpRowIntegrateField(field, value, result); } result.Append(" },"); result.AppendLine(); } }
/// <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(); } } }
/// <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); } } }
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" } }
/// <summary> /// Return (null, 4, true, "Text"). /// </summary> private static string CSharpParam <T>(T value) { Type type = UtilFramework.TypeUnderlying(typeof(T)); string result; if (value == null) { if (type == typeof(string)) { result = "null"; } else { result = Activator.CreateInstance(type).ToString(); } } else { result = value.ToString(); } if (type == typeof(bool)) { result = result.ToLower(); } if (type == typeof(string) && value != null) { string valueString = (string)(object)value; valueString = valueString.Replace("\"", @"\"""); result = string.Format("\"{0}\"", valueString); } return(result); }
/// <summary> /// Returns true, if value has been set. (Use Argument=null to set a value to null). /// </summary> /// <param name="value">Returns value.</param> internal static bool ArgumentValue(CommandBase command, CommandArgument commandArgument, out string value) { string name = commandArgument.Name; commandArgument = ArgumentValue(command, commandArgument); // Sequence of passed arguments might be wrong. bool isValue = false; string result = commandArgument.Value; UtilFramework.Assert(name.ToLower() == result.Substring(0, name.Length).ToLower()); if (result.ToUpper().StartsWith(name.ToUpper())) { result = result.Substring(name.Length); } if (result.StartsWith("=")) { result = result.Substring(1); } result = UtilFramework.StringNull(result); if (result != null) { isValue = true; } if (result?.ToLower() == "null") // User sets value to null. { result = null; } value = result; return(isValue); }
/// <summary> /// Returns Integrate rows to deploy to sql database. /// </summary> internal void CommandDeployDbIntegrateInternal(DeployDbIntegrateResult result) { // FrameworkConfigGridIntegrate { var rowList = FrameworkConfigGridIntegrateFrameworkCli.RowList; // Read FrameworkConfigGridIntegrate.RowListList from Application.Cli project. string nameCli = "DatabaseIntegrate.dbo.FrameworkConfigGridIntegrateApplicationCli"; // See also method GenerateCSharpTableNameClass(); var typeCli = AssemblyApplicationCli.GetType(nameCli); UtilFramework.Assert(typeCli != null, string.Format("Type not found! See also method GenerateCSharpTableNameClass(); ({0})", nameCli)); PropertyInfo propertyInfo = typeCli.GetProperty(nameof(FrameworkConfigGridIntegrateFrameworkCli.RowList)); var rowApplicationCliList = (List <FrameworkConfigGridIntegrate>)propertyInfo.GetValue(null); rowList.AddRange(rowApplicationCliList); result.Add(rowList); } // FrameworkConfigFieldIntegrate { var rowList = FrameworkConfigFieldIntegrateFrameworkCli.RowList; // Read FrameworkConfigFieldIntegrateCli.List from Application.Cli project. string nameCli = "DatabaseIntegrate.dbo.FrameworkConfigFieldIntegrateApplicationCli"; // See also method GenerateCSharpTableNameClass(); var typeCli = AssemblyApplicationCli.GetType(nameCli); UtilFramework.Assert(typeCli != null, string.Format("Type not found! See also method GenerateCSharpTableNameClass(); ({0})", nameCli)); PropertyInfo propertyInfo = typeCli.GetProperty(nameof(FrameworkConfigFieldIntegrateFrameworkCli.RowList)); var rowApplicationCliList = (List <FrameworkConfigFieldIntegrate>)propertyInfo.GetValue(null); rowList.AddRange(rowApplicationCliList); result.Add(rowList); } // Add application (custom) Integrate data rows to deploy to database CommandDeployDbIntegrate(result); }
internal static void FolderDelete(string folderName) { var count = 0; do { if (count > 0) { Task.Delay(1000).Wait(); // Wait for next attempt. } if (UtilCli.FolderNameExist(folderName)) { foreach (FileInfo fileInfo in new DirectoryInfo(folderName).GetFiles("*.*", SearchOption.AllDirectories)) { fileInfo.Attributes = FileAttributes.Normal; // See also: https://stackoverflow.com/questions/1701457/directory-delete-doesnt-work-access-denied-error-but-under-windows-explorer-it/30673648 } try { Directory.Delete(folderName, true); } catch (IOException) { // Silent exception. Console.WriteLine(string.Format("Can not delete folder! ({0})", folderName)); } } count += 1; } while (UtilCli.FolderNameExist(folderName) && count <= 3); UtilFramework.Assert(!UtilCli.FolderNameExist(folderName), string.Format("Can not delete folder! Make sure server.ts and node.exe is not running. ({0}", folderName)); }
/// <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); }
/// <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())); } }
/// <summary> /// Returns FolderNameServer. For example: "Application.Server/Framework/Application.Website/Layout01/". /// </summary> public string FolderNameServerGet(ConfigServer configServer, string prefixRemove) { string result = string.Format("Application.Server/Framework/Application.Website/Layout{0:00}/", configServer.WebsiteList.IndexOf(this) + 1); UtilFramework.Assert(result.StartsWith(prefixRemove)); result = result.Substring(prefixRemove.Length); return(result); }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { string connectionString = ConfigCli.ConnectionString(IsFrameworkDb); UtilFramework.Assert(string.IsNullOrEmpty(connectionString) == false, "ConnectionString is null!"); optionsBuilder.UseSqlServer(connectionString); optionsBuilder.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking); }
/// <summary> /// Returns FolderNameServer. For example: "Application.Server/Framework/Application.Website/LayoutDefault/dist/". /// </summary> public string FolderNameServerGet(ConfigServer configServer, string prefixRemove) { string result = "Application.Server/Framework/" + FolderNameDist; UtilFramework.Assert(result.StartsWith(prefixRemove)); result = result.Substring(prefixRemove.Length); return(result); }
/// <summary> /// Returns EnvironmentName. This is the currently selected environment. Default is DEV. /// </summary> public string EnvironmentNameGet() { string result = EnvironmentName?.ToUpper(); if (UtilFramework.StringNull(result) == null) { result = "DEV"; } return(result); }
protected override async Task UpdateAsync(UpdateArgs args, UpdateResult result) { result.Row.TextHtml = UtilFramework.TextMdToHtml(args.Row.TextMd, this.ComponentOwner <AppMain>().CssFrameworkEnum); result.Row.SitemapDate = DateTime.UtcNow; await Data.UpdateAsync(result.Row); Data.RowCopy(result.Row, PageAdminContent.GridContent.RowSelect); PageAdminContent.Html.TextHtml = result.Row.TextHtml; result.IsHandled = true; }
/// <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"); } }
/// <summary> /// Copy ConfigCli.json to ConfigServer.json and validate ConnectionString exists. /// </summary> private void CopyConfigCliToConfigServer() { ConfigCli.CopyConfigCliToConfigServer(); var configCli = ConfigCli.Load(); var environment = configCli.EnvironmentGet(); if (UtilFramework.StringNull(environment.ConnectionStringFramework) == null || UtilFramework.StringNull(environment.ConnectionStringFramework) == null) { UtilCli.ConsoleWriteLineColor(string.Format("No ConnectionString for {0}! Set it with command cli config connectionString.", environment.EnvironmentName), ConsoleColor.Yellow); } }
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(); }
/// <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); }
public static void BootstrapNavbarRender(AppJson appJson) { int buttonId = 0; // BootstrapNavbarButton.Id foreach (BootstrapNavbar bootstrapNavbar in appJson.ComponentListAll().OfType <BootstrapNavbar>()) { bootstrapNavbar.ButtonList = new List <BootstrapNavbarButton>(); // Clear foreach (var item in bootstrapNavbar.GridList) { if (item.Grid?.TypeRow != null) { var propertyInfoList = UtilDalType.TypeRowToPropertyInfoList(item.Grid.TypeRow); PropertyInfo propertyInfoId = propertyInfoList.Where(item => item.Name == "Id" && item.PropertyType == typeof(int)).SingleOrDefault(); PropertyInfo propertyInfoParentId = propertyInfoList.Where(item => item.Name == "ParentId" && item.PropertyType == typeof(int?)).SingleOrDefault(); PropertyInfo propertyInfoTextHtml = propertyInfoList.Where(item => item.Name == "TextHtml" && item.PropertyType == typeof(string)).SingleOrDefault(); if (propertyInfoParentId != null) { UtilFramework.Assert(propertyInfoId != null, "Row needs a column 'Id'!"); } UtilFramework.Assert(propertyInfoTextHtml != null, string.Format("Row needs a column 'TextHtml' ({0})!", UtilDalType.TypeRowToTableNameCSharp(item.Grid.TypeRow))); // Add for example language switch if (item.IsSelectMode) { if (item.Grid.RowSelect != null) { string textHtml = (string)propertyInfoTextHtml.GetValue(item.Grid.RowSelect); var args = new BootstrapNavbarButtonArgs { BootstrapNavbar = bootstrapNavbar, Grid = item.Grid, Row = item.Grid.RowSelect }; var result = new BootstrapNavbarButtonResult { TextHtml = textHtml }; bootstrapNavbar.ButtonTextHtml(args, result); buttonId += 1; var button = new BootstrapNavbarButton { Id = buttonId, Grid = item.Grid, RowStateId = item.Grid.RowSelectRowStateId.Value, TextHtml = result.TextHtml }; bootstrapNavbar.ButtonList.Add(button); BootstrapNavbarRender(bootstrapNavbar, item, button, ref button.ButtonList, findParentId: null, propertyInfoId, propertyInfoParentId, propertyInfoTextHtml, ref buttonId); } } else { BootstrapNavbarRender(bootstrapNavbar, item, null, ref bootstrapNavbar.ButtonList, findParentId: null, propertyInfoId, propertyInfoParentId, propertyInfoTextHtml, ref buttonId); } } } } }
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); } }
protected override async Task ProcessAsync() { AlertError.ComponentRemove(); if (Button.IsClick) { var loginUserSession = Grid.RowSelect; var loginUserRoleAppList = (await Data.Query <LoginUserRoleApp>().Where(item => item.LoginUserName == loginUserSession.Name && item.LoginUserRoleIsActive == true).QueryExecuteAsync()); if (!loginUserRoleAppList.Any()) { // Username does not exist this.AlertError = new Alert(this.ComponentOwner <AppJson>(), "Username or password wrong!", AlertEnum.Error); } else { var pageMain = this.ComponentOwner <PageMain>(); string password = loginUserSession.PasswordHash; // User entered password string passwordHash = loginUserRoleAppList.First().LoginUserPasswordHash; // In db stored hash string passwordSalt = loginUserRoleAppList.First().LoginUserPasswordSalt; // In db stored salt if (passwordHash != null && !UtilFramework.PasswordIsValid(password, passwordHash, passwordSalt)) { // Password wrong this.AlertError = new Alert(this.ComponentOwner <AppJson>(), "Username or password wrong!", AlertEnum.Error); } else { if (!loginUserRoleAppList.First().LoginUserIsActive) { // User not active this.AlertError = new Alert(this.ComponentOwner <AppJson>(), "User not (yet) active.", AlertEnum.Warning); } else { // Login successful pageMain.LoginUserRoleAppList = loginUserRoleAppList; foreach (var item in pageMain.LoginUserRoleAppList) { item.LoginUserPasswordHash = null; // Remoe from session item.LoginUserPasswordSalt = null; // Remove from session } var loginUserId = pageMain.LoginUserRoleAppList.First().LoginUserId; await pageMain.GridNavigate.LoadAsync(); this.ComponentOwner <AppJson>().Navigate("/"); // Navigate to home after login } } } // Render grid ConfigDeveloper (coffee icon) if user is a developer. await Grid.LoadAsync(); } }