public static void OutputModel(SQLMetaData config, bool enableProgress = true) { var path = Path.Combine(_basePath, "Model"); Directory.CreateDirectory(path); ConsoleProgressBar progress = null; if (enableProgress) { progress = GetProgressBar(); } var sb = new StringBuilder(); var g = new ModelGenerator(config); // 解析 for (int i = 0; i < config.Tables.Count; i++) { var table = config.Tables[i]; if (config.ExceptTables.Contains(table.Name)) { continue; } sb.Append(config.Model_HeaderNote); sb.Append(string.Join(Environment.NewLine, config.Model_Using)); sb.AppendLine(); sb.AppendLine(); sb.AppendLine(config.Model_Namespace); sb.AppendLine("{"); sb.AppendLine(g.Get_Class(table.Name)); sb.AppendLine("}"); File.AppendAllText(Path.Combine(path, string.Format("{0}.cs", table.Name)), sb.ToString()); sb.Clear(); if (progress != null) { // 打印进度 ProgressPrint(progress, (i + 1), config.Tables.Count); } } // 拷贝公用文件到指定目录 DirHelper.CopyDirectory(Path.Combine("CopyFiles", "Model"), path); }
public static void OutputModel(Dictionary <string, TableMetaData> tables, GlobalConfiguration config, IProgressBar progress = null) { ResetProgress(progress); var path = Path.Combine(config.OutputBasePath, "Model"); Directory.CreateDirectory(path); BaseModelGenerator g = new ModelGenerator(config); // 解析 var i = 0; var sb = new StringBuilder(); foreach (var key in tables.Keys) { var table = tables[key]; if (config.ExcludeTables != null && config.ExcludeTables.Any(p => p.Name == table.Name)) { continue; } sb.AppendLine(g.RenderModelFor(table)); File.AppendAllText(Path.Combine(path, string.Format("{0}.cs", g.FileName)), sb.ToString()); sb.Clear(); PrintProgress(progress, ++i, tables.Count); } // 如果配置文件指定了JoinedTables,那么这里需要为这些关联表生成额外的包装model, // 路径:Model\JoinedViewModel if (config.JoinedTables != null && config.JoinedTables.Count > 0) { //Directory.CreateDirectory(Path.Combine(path, "JoinedViewModel")); //var sb2 = new StringBuilder(); //foreach (var map in config.JoinedTables) //{ // sb2.AppendLine(g.Get_Join_Head(map)); // sb2.AppendLine(g.Get_Joined_Class(map)); // sb2.AppendLine(g.Get_Join_Tail(map)); // File.AppendAllText(Path.Combine(path, "JoinedViewModel", string.Format("{0}.cs", "Joined" + g.FileName)), sb2.ToString()); // sb2.Clear(); //} } // 拷贝公用文件到指定目录 DirHelper.CopyDirectory(Path.Combine("CopyFiles", "Model"), path); }
public static void OutputModel(SQLMetaData config, bool enableProgress = true) { var path = Path.Combine(_outputpath, "Model"); Directory.CreateDirectory(path); ConsoleProgressBar progress = null; if (enableProgress) { progress = GetProgressBar(); } var sb = new StringBuilder(); var g = new ModelGenerator(config); // 解析 for (int i = 0; i < config.Tables.Count; i++) { var table = config.Tables[i]; if (config.ExceptTables.Contains(table.Name)) { continue; } sb.Append(config.Model_HeaderNote); sb.AppendLine(string.Join(Environment.NewLine, config.Model_Using)); sb.AppendLine($"using {config.DAL_Namespace};"); sb.AppendLine($"using {config.DAL_Namespace}.Metadata;"); sb.AppendLine(); sb.AppendLine($"namespace {config.Model_Namespace}"); sb.AppendLine("{"); sb.AppendLine(g.Get_Class(table.Name)); sb.AppendLine("}"); File.AppendAllText(Path.Combine(path, string.Format("{0}.cs", table.Name)), sb.ToString()); sb.Clear(); if (progress != null) { // 打印进度 ProgressPrint(progress, (i + 1), config.Tables.Count); } } // 如果配置文件指定了JoinedTables,那么这里需要为这些关联表生成额外的包装model, // 路径:Model\JoinedViewModel if (config.JoinedTables.Count > 0) { Directory.CreateDirectory(Path.Combine(path, "JoinedViewModel")); var sb2 = new StringBuilder(); foreach (var pair in config.JoinedTables) { var main_table = pair.Key; var sub_table = pair.Value; sb2.Append(config.Model_HeaderNote); sb2.AppendLine(string.Join(Environment.NewLine, config.Model_Using)); sb.AppendLine($"using {config.DAL_Namespace};"); sb2.AppendLine($"using {config.DAL_Namespace}.Metadata;"); sb2.AppendLine(); sb2.AppendLine($"namespace {config.Model_Namespace}.JoinedViewModel"); sb2.AppendLine("{"); sb2.AppendLine(g.Get_Joined_Class(main_table, sub_table)); sb2.AppendLine("}"); File.AppendAllText(Path.Combine(path, "JoinedViewModel", string.Format("{0}.cs", "Joined" + main_table)), sb2.ToString()); sb2.Clear(); } } // 如果配置文件指定了EntityTables,那么这里需要生成实现接口IEntity接口的model // 路径:Model\EntityModel if (config.EntityTables.Count > 0) { Directory.CreateDirectory(Path.Combine(path, "EntityModel")); var sb2 = new StringBuilder(); foreach (var talbe in config.EntityTables) { sb2.Append(config.Model_HeaderNote); sb2.AppendLine(string.Join(Environment.NewLine, config.Model_Using)); sb.AppendLine($"using {config.DAL_Namespace};"); sb2.AppendLine($"using {config.DAL_Namespace}.Metadata;"); sb2.AppendLine(); sb2.AppendLine($"namespace {config.Model_Namespace}.EntityModel"); sb2.AppendLine("{"); sb2.AppendLine(g.Get_Entity_Class(talbe)); sb2.AppendLine("}"); File.AppendAllText(Path.Combine(path, "EntityModel", string.Format("{0}.cs", "Entity" + talbe)), sb2.ToString()); sb2.Clear(); } } // 拷贝公用文件到指定目录 DirHelper.CopyDirectory(Path.Combine("CopyFiles", "Model"), path); }