/// <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); } }
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> /// 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); } } }
/// <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); }
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> /// 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); }
/// <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> /// 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> /// 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); }
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(); }
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); } } } } }
/// <summary> /// Sets CommandOption flag. /// </summary> public static void OptionSet(ref CommandOption option, bool value) { if (option == null) { option = new CommandOption("--null", CommandOptionType.NoValue); // For example if command calls command and options is not registered. } option.Values.Clear(); if (value) { option.Values.Add("on"); } UtilFramework.Assert(OptionGet(option) == value); }
/// <summary> /// Start script. /// </summary> /// <param name="isRedirectStdErr">If true, do not write to stderr. Use this flag if shell command is known to write info (mistakenly) to stderr.</param> internal static void Start(string workingDirectory, string fileName, string arguments, bool isWait = true, bool isRedirectStdErr = false) { string time = UtilFramework.DateTimeToString(DateTime.Now); UtilCli.ConsoleWriteLinePassword(string.Format("### {4} Process Begin (FileName={1}; Arguments={2}; IsWait={3}; WorkingDirectory={0};)", workingDirectory, fileName, arguments, isWait, time), ConsoleColor.Green); ProcessStartInfo info = new ProcessStartInfo { WorkingDirectory = workingDirectory, FileName = fileName, Arguments = arguments }; if (isRedirectStdErr) { info.RedirectStandardError = true; // Do not write to stderr. } // info.UseShellExecute = true; using (var process = Process.Start(info)) { if (isWait) { if (isRedirectStdErr) { // process.WaitForExit(); // Can hang. For example Angular 9.1.1 build:ssr (May be when std buffer is full) string errorText = process.StandardError.ReadToEnd(); // Waits for process to exit. process.WaitForExit(); // Used for Ubuntu. Otherwise HasExited is not (yet) true. UtilFramework.Assert(process.HasExited); if (!string.IsNullOrEmpty(errorText)) { UtilCli.ConsoleWriteLinePassword(string.Format("### {4} Process StdErr (FileName={1}; Arguments={2}; IsWait={3}; WorkingDirectory={0};)", workingDirectory, fileName, arguments, isWait, time), ConsoleColor.DarkGreen); // Write stderr to stdout. UtilCli.ConsoleWriteLinePassword(errorText, ConsoleColor.DarkGreen); // Log DarkGreen because it is not treated like an stderr output. } } else { process.WaitForExit(); UtilFramework.Assert(process.HasExited); } if (process.ExitCode != 0) { throw new Exception("Script failed!"); } } } UtilCli.ConsoleWriteLinePassword(string.Format("### {4} Process End (FileName={1}; Arguments={2}; IsWait={3}; WorkingDirectory={0};)", workingDirectory, fileName, arguments, isWait, time), ConsoleColor.DarkGreen); }
/// <summary> /// Browser GET request to download file. /// </summary> private static async Task <bool> FileDownloadAsync(HttpContext context, string path, byte[] data) { bool result = false; if (data != null) { UtilFramework.Assert(data != null); string fileName = UtilFramework.FolderNameParse(null, path); context.Response.ContentType = UtilServer.ContentType(fileName); await context.Response.Body.WriteAsync(data, 0, data.Length); result = true; } return(result); }
/// <summary> /// Add unique key. /// </summary> public void AddKey <TRow>(params string[] fieldNameKeyList) where TRow : Row { Type typeRow = typeof(TRow); string tableNameCSharp = UtilDalType.TypeRowToTableNameCSharp(typeRow); UtilFramework.Assert(!tableNameCSharp.EndsWith("Integrate"), string.Format("Do not add Integrate. Use underlying sql table! ({0})", tableNameCSharp)); 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> /// Returns text escaped as CSharp code. Handles special characters. /// </summary> public static string EscapeCSharpString(string text) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("\""); var textList = UtilFramework.SplitChunk(text); // Because of line break after 80 characters! using (var writer = new StringWriter(CultureInfo.InvariantCulture)) { using var provider = CodeDomProvider.CreateProvider("CSharp"); foreach (var item in textList) { provider.GenerateCodeFromExpression(new CodePrimitiveExpression(item), writer, null); // Does a line break after 80 characters by default! string textCSharp = writer.ToString(); UtilFramework.Assert(textCSharp.StartsWith("\"")); UtilFramework.Assert(textCSharp.EndsWith("\"")); textCSharp = textCSharp[1..^ 1]; // Remove quotation marks.
/// <summary> /// Returns ExternalProjectName without reading file ConfigCli. json. External file Config.Cli.json does not contain this value. See also file ConfigCli.json of host cli. /// </summary> public static string ExternalProjectName() { UtilFramework.Assert(IsExternal); UtilFramework.Assert(UtilFramework.FolderName.StartsWith(UtilExternal.FolderNameExternal)); // ExternalGit/ProjectName/ string externalGitProjectNamePath = UtilFramework.FolderName.Substring(UtilExternal.FolderNameExternal.Length); UtilFramework.Assert(externalGitProjectNamePath.StartsWith("ExternalGit/")); UtilFramework.Assert(externalGitProjectNamePath.EndsWith("/")); string result = externalGitProjectNamePath.Substring("ExternalGit/".Length); result = result.Substring(0, result.Length - 1); return(result); }
/// <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())); } }
/// <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)); }
public void Add <TRow>(List <TRow> rowList) where TRow : Row { Type typeRow = typeof(TRow); // Reference from GenerateIntegrate to DeployDbIntegrate var referenceFilterList = GenerateIntegrateResult.ResultReference.Where(item => item.TypeRowIntegrate == typeof(TRow)).ToList(); // Make sure reference tables are deployed. foreach (var item in referenceFilterList) { if (item.TypeRowReferenceIntegrate != typeRow) // Exclude hierarchical reference { int referenceCount = Result.Count(itemLocal => itemLocal.TypeRow == item.TypeRowReferenceIntegrate || itemLocal.TypeRow == item.TypeRowReference); UtilFramework.Assert(referenceCount > 0, string.Format("Reference table not yet deployed! ({0})", UtilDalType.TypeRowToTableNameCSharp(item.TypeRowReferenceIntegrate))); } } // Key from GenerateIntegrate var typeRowUnderlying = typeRow; string tableNameCSharp = UtilDalType.TypeRowToTableNameCSharp(typeRow); if (tableNameCSharp.EndsWith("Integrate")) { string tableNameCSharpUnderlying = tableNameCSharp.Substring(0, tableNameCSharp.Length - "Integrate".Length); typeRowUnderlying = GenerateIntegrateResult.TableNameCSharpList.SingleOrDefault(item => item.Value == tableNameCSharpUnderlying).Key; UtilFramework.Assert(typeRowUnderlying != null, string.Format("Use underlying sql table! ({0})", tableNameCSharp)); } UtilFramework.Assert(GenerateIntegrateResult.ResultKey.ContainsKey(typeRowUnderlying), string.Format("TypRow not unique key defined! See also method GenerateIntegrateResult.AddKey(); ({0})", tableNameCSharp)); var fieldNameCSharpKeyList = GenerateIntegrateResult.ResultKey[typeRowUnderlying]; // Result var result = UtilDalUpsertIntegrate.UpsertItem.Create(rowList, fieldNameCSharpKeyList, referenceFilterList); // Make sure table is not already added. if (Result.Count > 0 && Result[^ 1].TypeRow != result.TypeRow) // Do not test ist previous is identical (because of hierarchical reference calling this method multiple times). { UtilFramework.Assert(Result.Count(item => item.TypeRow == result.TypeRow) == 0, string.Format("Table already added! ({0})", UtilDalType.TypeRowToTableNameCSharp(result.TypeRow))); } Result.Add(result); }
/// <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)); } }
private static void RunComponentJson() { // Reference to self { MyComponent source = new MyComponent(null); source.Component = source; UtilJson.Serialize(source, out string json, out string jsonClient); MyComponent dest = (MyComponent)UtilJson.Deserialize(json); UtilFramework.Assert(dest.Component == dest); } // ComponentJson reference to ComponentJson do not send to client { MyComponent source = new MyComponent(null); source.HtmlAbc = new Html(source) { TextHtml = "JK" }; source.MyTextSession = "SessionValueX"; source.MyTextClient = "ClientValueX"; source.MyIgnore = "IgnoreX"; UtilJson.Serialize(source, out string jsonSession, out string jsonClient); MyComponent dest = (MyComponent)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(!jsonClient.Contains("HtmlAbc")); // Do not send property name of ComponentJson reference to client UtilFramework.Assert(jsonSession.Contains("SessionValueX")); UtilFramework.Assert(!jsonClient.Contains("SessionValueX")); UtilFramework.Assert(!jsonSession.Contains("ClientValueX")); UtilFramework.Assert(jsonClient.Contains("ClientValueX")); UtilFramework.Assert(!jsonSession.Contains("IgnoreX")); UtilFramework.Assert(!jsonClient.Contains("IgnoreX")); UtilFramework.Assert(!jsonSession.Contains("Owner")); UtilFramework.Assert(!jsonClient.Contains("Owner")); } // ComponentJson.IsHide { MyComponent source = new MyComponent(null); new Html(source) { TextHtml = "X11" }; new Html(source) { TextHtml = "X12", IsHide = true }; new Html(source) { TextHtml = "X13" }; UtilJson.Serialize(source, out string jsonSession, out string jsonClient); MyComponent dest = (MyComponent)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(dest.List.Count == 3); UtilFramework.Assert(jsonClient.Contains("X11")); UtilFramework.Assert(!jsonClient.Contains("X12")); UtilFramework.Assert(jsonClient.Contains("X13")); } // ComponentJson.IsHide (Dto to ComponentJson { My source = new My(); source.MyComponent = new MyComponent(null) { Id = 789, IsHide = true }; UtilJson.Serialize(source, out string jsonSession, out string jsonClient); My dest = (My)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(!jsonClient.Contains("789")); } // ComponentJson.IsHide { MyComponent source = new MyComponent(null); source.Html = new Html(source) { TextHtml = "My123", IsHide = true }; UtilJson.Serialize(source, out string jsonSession, out string jsonClient); MyComponent dest = (MyComponent)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(jsonSession.Contains("My123")); UtilFramework.Assert(!jsonClient.Contains("My123")); } // ComponentJson.IsHide (Root) { MyComponent source = new MyComponent(null); source.IsHide = true; source.Html = new Html(source) { TextHtml = "My123", IsHide = true }; UtilJson.Serialize(source, out string jsonSession, out string jsonClient); MyComponent dest = (MyComponent)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(jsonSession.Contains("My123")); UtilFramework.Assert(jsonClient == ""); } // Reference to Row { MyComponent source = new MyComponent(null); source.MyRow = new MyRow { Text = "My123", DateTime = DateTime.Now }; source.MyRowList = new List <Row>(); source.MyRowList.Add(new MyRow { Text = "My1234", DateTime = DateTime.Now }); source.MyRowList.Add(new MyRow { Text = "My12356", DateTime = DateTime.Now }); UtilJson.Serialize(source, out string jsonSession, out string jsonClient); MyComponent dest = (MyComponent)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(!jsonClient.Contains("My123")); } // Reference to Row { MyComponent source = new MyComponent(null); source.MyRowList = new List <Row>(); source.MyRowList.Add(new MyRow { Text = "My1234", DateTime = DateTime.Now }); source.MyRowList.Add(new MyRow { Text = "My12356", DateTime = DateTime.Now }); UtilJson.Serialize(source, out string jsonSession, out string jsonClient); MyComponent dest = (MyComponent)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(!jsonClient.Contains("My123")); } // Field of object type with Row value { MyComponent source = new MyComponent(null); source.V = new MyRow() { Text = "Hello" }; try { UtilJson.Serialize(source, out string jsonSession, out string jsonClient); } catch (Exception exception) { UtilFramework.Assert(exception.Message == "Can not send data row to client!"); // V is object declaration therefore no Row detection. } } // Reference to removed ComponentJson { MyComponent source = new MyComponent(null); var html = new Html(source) { TextHtml = "My" }; source.Html = html; html.ComponentRemove(); UtilJson.Serialize(source, out string jsonSession, out string jsonClient); MyComponent dest = (MyComponent)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(dest.Html == null); } // ComponentJson reference in list { MyComponent source = new MyComponent(null); var html = new Html(source) { TextHtml = "My" }; source.HtmlList = new List <Html>(); source.HtmlList.Add(html); // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); try { var dest = (MyComponent)UtilJson.Deserialize(jsonSession); } catch (Exception exception) { UtilFramework.Assert(exception.Message == "Reference to ComponentJson in List not supported!"); } } { MyComponent source = new MyComponent(null); new MyComponent(source); UtilJson.Serialize(source, out string jsonSession, out string jsonClient); var dest = (MyComponent)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(dest.List.Count == 1); } { MyComponent source = new MyComponent(null); UtilJson.Serialize(source, out string jsonSession, out string jsonClient); var dest = (MyComponent)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(dest.Index == null); } { MyComponent source = new MyComponent(null); source.Index = 0; UtilJson.Serialize(source, out string jsonSession, out string jsonClient); var dest = (MyComponent)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(dest.Index == 0); } { MyComponent source = new MyComponent(null); source.Index = -1; UtilJson.Serialize(source, out string jsonSession, out string jsonClient); var dest = (MyComponent)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(dest.Index == -1); } { My source = new My(); var myComponent1 = new MyComponent(null); Html html1 = new Html(myComponent1) { TextHtml = "A" }; myComponent1.Dto = new Dto { Css = "A", Html = html1 }; var myComponent2 = new MyComponent(null); Html html2 = new Html(myComponent2) { TextHtml = "B" }; myComponent2.Dto = new Dto { Css = "B", Html = html2 }; source.List.Add(myComponent1); UtilJson.Serialize(source, out string jsonSession, out string jsonClient); var dest = (My)UtilJson.Deserialize(jsonSession); dest.List[0].Dto.Html.TextHtml = "abc"; UtilFramework.Assert(((Html)dest.List[0].List[0]).TextHtml == "abc"); source.List.Add(myComponent2); try { UtilJson.Serialize(source, out jsonSession, out jsonClient); } catch (Exception exception) { UtilFramework.Assert(exception.Message == "JsonClient can only have one ComponentJson graph!"); } } { My source = new My(); var myComponent1 = new MyComponent(null); Html html1 = new Html(myComponent1) { TextHtml = "A" }; myComponent1.Dto = new Dto { Css = "A", Html = html1 }; var myComponent2 = new MyComponent(null); Html html2 = new Html(myComponent2) { TextHtml = "B" }; myComponent2.Dto = new Dto { Css = "B", Html = html2 }; var myComponent3 = new MyComponent(myComponent1); source.List.Add(myComponent3); // Reference not to root! try { UtilJson.Serialize(source, out string jsonSession, out string jsonClient); } catch (Exception exception) { UtilFramework.Assert(exception.Message == "Referenced ComponentJson not root!"); } source.List.Remove(myComponent3); source.List.Add(myComponent1); source.List.Add(myComponent2); try { UtilJson.Serialize(source, out string jsonSession, out string jsonClient); } catch (Exception exception) { UtilFramework.Assert(exception.Message == "JsonClient can only have one ComponentJson graph!"); } } { My source = new My(); var myComponent1 = new MyComponent(null); Html html1 = new Html(myComponent1) { TextHtml = "A" }; myComponent1.Dto = new Dto { Css = "A", Html = html1 }; var myComponent2 = new MyComponent(null); Html html2 = new Html(myComponent2) { TextHtml = "B" }; myComponent2.Dto = new Dto { Css = "B", Html = html1 }; // Reference to object in different graph source.List.Add(myComponent2); source.List.Add(myComponent1); try { UtilJson.Serialize(source, out string jsonSession, out string jsonClient); } catch (Exception exception) { UtilFramework.Assert(exception.Message == "Referenced ComponentJson not in same object graph!"); } } { var source = new MyComponent(null); source.Html = new Html(source) { TextHtml = "Hello" }; UtilJson.Serialize(source, out string jsonSession, out string jsonClient); UtilFramework.Assert(!jsonSession.Contains("Owner")); var dest = (MyComponent)UtilJson.Deserialize(jsonSession); var htmlOne = dest.Html; var htmlTwo = dest.List.OfType <Html>().First(); htmlOne.TextHtml = "K"; UtilFramework.Assert(htmlOne.TextHtml == htmlTwo.TextHtml); } // Referenced ComponentJson not in same graph { var source = new MyComponent(null); source.Html = new Html(null); try { UtilJson.Serialize(source, out string jsonSession, out string jsonClient); } catch (Exception exception) { UtilFramework.Assert(exception.Message == "Referenced ComponentJson not in same object graph!"); } } }
public static void Run() { { UtilFramework.CamelCase camelCase = new UtilFramework.CamelCase("AbcDef"); UtilFramework.Assert(camelCase.TextList[0] == "Abc"); UtilFramework.Assert(camelCase.TextList[1] == "Def"); } { UtilFramework.CamelCase camelCase = new UtilFramework.CamelCase("abcDef"); UtilFramework.Assert(camelCase.TextList[0] == "abc"); UtilFramework.Assert(camelCase.TextList[1] == "Def"); } { UtilFramework.CamelCase camelCase = new UtilFramework.CamelCase("AbcDefCSharp"); UtilFramework.Assert(camelCase.TextList[0] == "Abc"); UtilFramework.Assert(camelCase.TextList[1] == "Def"); UtilFramework.Assert(camelCase.TextList[2] == "CSharp"); UtilFramework.Assert(camelCase.EndsWith("DefCSharp")); UtilFramework.Assert(camelCase.EndsWith("cDefCSharp") == false); UtilFramework.Assert(camelCase.EndsWith("AbcDefCSharp")); UtilFramework.Assert(camelCase.EndsWith("AbcDefCSharpCar") == false); UtilFramework.Assert(camelCase.EndsWith("CarAbcDefCSharp") == false); UtilFramework.Assert(camelCase.EndsWith("") == true); } { UtilFramework.CamelCase camelCase = new UtilFramework.CamelCase("AbcDefCSharp"); UtilFramework.Assert(camelCase.StartsWith("Abc")); UtilFramework.Assert(camelCase.StartsWith("AbcDef")); UtilFramework.Assert(camelCase.StartsWith("AbcDefCSharp")); UtilFramework.Assert(camelCase.StartsWith("AbcDefCShar") == false); UtilFramework.Assert(camelCase.StartsWith("AbcDefCSharpLk") == false); UtilFramework.Assert(camelCase.StartsWith("LkAbcDefCSharp") == false); UtilFramework.Assert(camelCase.StartsWith("")); } { UtilFramework.CamelCase camelCase = new UtilFramework.CamelCase("ImageFileId"); UtilFramework.Assert(camelCase.EndsWith("FileId")); } { UtilFramework.CamelCase camelCase = new UtilFramework.CamelCase("ImagEFileId"); UtilFramework.Assert(camelCase.EndsWith("FileId") == false); } { var source = new AppMain(); // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); var dest = (AppMain)UtilJson.Deserialize(jsonSession); } { var source = new MyApp(); source.Div = new Div(source); source.Div.ComponentRemove(); // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); var dest = (MyApp)UtilJson.Deserialize(jsonSession); } { var source = new MyApp(); source.Row = new BootstrapRow(source); source.Col = new BootstrapCol((BootstrapRow)source.Row); // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); var dest = (MyApp)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(!jsonSession.Contains("PropertyReadOnly")); } { var source = new MyApp(); // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); var dest = (MyApp)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(!jsonSession.Contains("PropertyReadOnly")); } { var source = new MyApp(); // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); var dest = (MyApp)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(!jsonSession.Contains("PropertyReadOnly")); } { var source = new MyApp(); var myGrid = new MyGrid(source) { Text = "K7", IsHide = true }; source.MyCell = new MyCell { MyGridBoth = myGrid, MyText = "7755" }; // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); var dest = (MyApp)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(UtilFramework.FindCount(jsonClient, "K7") == 1); UtilFramework.Assert(UtilFramework.FindCount(jsonSession, "K7") == 1); // Ensure session stores reference UtilFramework.Assert(dest.List[0] == dest.MyCell.MyGridBoth); } { var source = new MyApp(); var myGrid = new MyGrid(source) { Text = "K7", IsHide = true }; var myGrid2 = new MyGrid(source) { Text = "K8", IsHide = true }; source.MyCell = new MyCell { MyGrid = myGrid, MyGrid2 = myGrid2, MyText = "7755" }; // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); var dest = (MyApp)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(jsonClient.Contains("K7")); UtilFramework.Assert(!jsonClient.Contains("K8")); UtilFramework.Assert(dest.List[1] == dest.MyCell.MyGrid2); } RunComponentJson(); { A source = new A(); source.MyEnum = MyEnum.Left; // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); A dest = (A)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(dest.MyEnum == MyEnum.Left); UtilFramework.Assert(dest.MyEnumNullable == null); } { A source = new A(); source.MyEnumNullable = MyEnum.None; // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); A dest = (A)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(dest.MyEnumNullable == MyEnum.None); } { A source = new A(); // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); A dest = (A)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(!jsonSession.Contains(nameof(A.MyEnumList))); UtilFramework.Assert(source.MyEnumList == null); UtilFramework.Assert(dest.MyEnumList != null); UtilFramework.Assert(dest.MyEnumList.Count == 0); } { A source = new A(); source.MyEnumList = new List <MyEnum>(); source.MyEnumList.Add(MyEnum.None); source.MyEnumList.Add(MyEnum.Left); source.MyEnumList.Add(MyEnum.Right); // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); A dest = (A)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(jsonSession.Contains(nameof(A.MyEnumList))); UtilFramework.Assert(dest.MyEnumList[0] == MyEnum.None); UtilFramework.Assert(dest.MyEnumList[1] == MyEnum.Left); UtilFramework.Assert(dest.MyEnumList[2] == MyEnum.Right); } { A source = new A(); source.MyEnumNullableList = new List <MyEnum?>(); source.MyEnumNullableList.Add(MyEnum.None); source.MyEnumNullableList.Add(MyEnum.Left); source.MyEnumNullableList.Add(null); source.MyEnumNullableList.Add(MyEnum.Right); // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); A dest = (A)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(jsonSession.Contains(nameof(A.MyEnumNullableList))); UtilFramework.Assert(dest.MyEnumNullableList[0] == MyEnum.None); UtilFramework.Assert(dest.MyEnumNullableList[1] == MyEnum.Left); UtilFramework.Assert(dest.MyEnumNullableList[2] == null); UtilFramework.Assert(dest.MyEnumNullableList[3] == MyEnum.Right); } { A source = new A(); source.IntNullableList = new List <int?>(); source.IntNullableList.Add(0); source.IntNullableList.Add(1); source.IntNullableList.Add(null); source.IntNullableList.Add(2); // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); A dest = (A)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(jsonSession.Contains(nameof(A.IntNullableList))); UtilFramework.Assert(dest.IntNullableList[0] == 0); UtilFramework.Assert(dest.IntNullableList[1] == 1); UtilFramework.Assert(dest.IntNullableList[2] == null); UtilFramework.Assert(dest.IntNullableList[3] == 2); } { A source = new A(); source.IntList = new List <int>(); source.IntList.Add(0); source.IntList.Add(1); source.IntList.Add(2); // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); A dest = (A)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(jsonSession.Contains(nameof(A.IntList))); UtilFramework.Assert(dest.IntList[0] == 0); UtilFramework.Assert(dest.IntList[1] == 1); UtilFramework.Assert(dest.IntList[2] == 2); } { A source = new A(); source.V = 33; // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); A dest = (A)UtilJson.Deserialize(jsonSession); UtilFramework.Assert((int)dest.V == 33); } { A source = new A(); source.V = "Hello"; // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); A dest = (A)UtilJson.Deserialize(jsonSession); UtilFramework.Assert((string)dest.V == "Hello"); } { var date = DateTime.Now; A source = new A(); source.Row = new FrameworkDeployDb { Id = 22, FileName = @"C:\Temp\Readme.txt", Date = date }; // Serialize, deserialize UtilJson.Serialize(source, out string jsonSession, out string jsonClient); A dest = (A)UtilJson.Deserialize(jsonSession); UtilFramework.Assert(dest.Row.Id == 22); UtilFramework.Assert(dest.Row.FileName == @"C:\Temp\Readme.txt"); UtilFramework.Assert(dest.Row.Date == date); } { A source = new A(); source.V = MyEnum.None; // TODO Serialize enum on property of type object. // Serialize, deserialize // string json = UtilJson.Serialize(source); // A dest = (A)UtilJson.Deserialize(json); } }
/// <summary> /// Add reference table. Parameter fieldNameId references a table. For example: "UserId". It also needs a corresponding "UserIdName". Command cli generate will produce "UserId = 0" CSharp code. /// </summary> /// <typeparam name="TRow">For example: "LoginUserRole".</typeparam> /// <typeparam name="TRowReference">For example: "LoginUser".</typeparam> /// <param name="fieldNameId">For example: "UserId". Needs a corresponding "UserIdName".</param> public void AddReference <TRow, TRowReference>(string fieldNameId) where TRow : Row where TRowReference : Row { string fieldNameIdCSharp = fieldNameId; Type typeRowResult; string fieldNameIdCSharpResult; string fieldNameIdSqlResult; Type typeRowIntegrateResult; string fieldNameIdNameCSharpResult; string fieldNameIdNameSqlResult; Type typeRowReferenceResult; Type typeRowReferenceIntegrateResult; // Row { Type typeRow = typeof(TRow); string tableNameCSharp = UtilDalType.TypeRowToTableNameCSharp(typeRow); UtilFramework.Assert(!tableNameCSharp.EndsWith("Integrate"), string.Format("Do not add Integrate. Use underlying sql table! ({0})", tableNameCSharp)); var fieldId = UtilDalType.TypeRowToFieldList(typeRow).Where(item => item.FieldNameCSharp == fieldNameIdCSharp).FirstOrDefault(); UtilFramework.Assert(fieldId != null, string.Format("Field not found! ({0}.{1})", tableNameCSharp, fieldNameIdCSharp)); typeRowResult = typeRow; fieldNameIdCSharpResult = fieldId.FieldNameCSharp; fieldNameIdSqlResult = fieldId.FieldNameSql; } // Row Integrate { Type typeRow = typeof(TRow); string tableNameCSharp = UtilDalType.TypeRowToTableNameCSharp(typeRow); var tableIntegrate = TableNameCSharpList.Where(item => item.Value == tableNameCSharp + "Integrate").SingleOrDefault(); Type typeRowIntegrate = tableIntegrate.Key; string tableNameIntegrate = tableIntegrate.Value; UtilFramework.Assert(tableNameIntegrate != null, string.Format("CSharp Integrate row not found! Run command cli generate? ({0})", tableNameCSharp)); var fieldIntegrateId = UtilDalType.TypeRowToFieldList(typeRowIntegrate).Where(item => item.FieldNameCSharp == fieldNameIdCSharp).FirstOrDefault(); UtilFramework.Assert(fieldIntegrateId != null, string.Format("Field not found! ({0}.{1})", tableNameIntegrate, fieldNameIdCSharp)); var fieldIntegrateIdName = UtilDalType.TypeRowToFieldList(typeRowIntegrate).Where(item => item.FieldNameCSharp == fieldNameIdCSharp + "Name").FirstOrDefault(); UtilFramework.Assert(fieldIntegrateIdName != null, string.Format("CSharp field not found! Run command cli generate? ({0}.{1})", tableNameIntegrate, fieldNameIdCSharp + "Name")); typeRowIntegrateResult = typeRowIntegrate; fieldNameIdNameCSharpResult = fieldIntegrateIdName.FieldNameCSharp; fieldNameIdNameSqlResult = fieldIntegrateIdName.FieldNameCSharp; } // Row Reference { Type typeRow = typeof(TRowReference); string tableNameCSharp = UtilDalType.TypeRowToTableNameCSharp(typeRow); UtilFramework.Assert(!tableNameCSharp.EndsWith("Integrate"), string.Format("Do not add Integrate. Use underlying sql table! ({0})", tableNameCSharp)); var fieldId = UtilDalType.TypeRowToFieldList(typeRow).Where(item => item.FieldNameCSharp == "Id").FirstOrDefault(); UtilFramework.Assert(fieldId != null, string.Format("Field not found! ({0}.{1})", tableNameCSharp, "Id")); typeRowReferenceResult = typeRow; } // Row Reference Integrate { Type typeRow = typeof(TRowReference); string tableNameCSharp = UtilDalType.TypeRowToTableNameCSharp(typeRow); var tableIntegrate = TableNameCSharpList.Where(item => item.Value == tableNameCSharp + "Integrate").SingleOrDefault(); Type typeRowIntegrate = tableIntegrate.Key; string tableNameIntegrate = tableIntegrate.Value; UtilFramework.Assert(tableNameIntegrate != null, string.Format("Integrate not found! ({0})", tableNameIntegrate)); var fieldIntegrateId = UtilDalType.TypeRowToFieldList(typeRowIntegrate).Where(item => item.FieldNameCSharp == "Id").FirstOrDefault(); UtilFramework.Assert(fieldIntegrateId != null, string.Format("Field not found! ({0}.{1})", tableNameIntegrate, "Id")); var fieldIntegrateIdName = UtilDalType.TypeRowToFieldList(typeRowIntegrate).Where(item => item.FieldNameCSharp == "IdName").FirstOrDefault(); UtilFramework.Assert(fieldIntegrateIdName != null, string.Format("Field not found! ({0}.{1})", tableNameIntegrate, "IdName")); typeRowReferenceIntegrateResult = typeRowIntegrate; } // Result var reference = new UtilDalUpsertIntegrate.Reference(typeRowResult, fieldNameIdCSharpResult, fieldNameIdSqlResult, typeRowIntegrateResult, fieldNameIdNameCSharpResult, fieldNameIdNameSqlResult, typeRowReferenceResult, typeRowReferenceIntegrateResult); UtilFramework.Assert(ResultReference.Count(item => item.TypeRow == reference.TypeRow && item.FieldNameIdCSharp == reference.FieldNameIdCSharp) == 0, "Reference already defined!"); ResultReference.Add(reference); }