private void WriteDataSource(DataBaseTable item) { var path = Path.Combine(Config.CSharp.UnitTest.Path, "DataSource", item.Schema); var file = $"{item.Name}DataSource.cs"; var nameSpace = new List <string> { "System", "System.Collections.Generic", "XCommon.Extensions.Converters", "XCommon.Util" }; nameSpace.Add($"{Config.CSharp.Entity.NameSpace}.{item.Schema}"); nameSpace.Add($"{Config.CSharp.Entity.NameSpace}.{item.Schema}.Filter"); var builder = new StringBuilderIndented(); builder .ClassInit($"{item.Name}DataSource", string.Empty, $"{Config.CSharp.UnitTest.NameSpace}.{item.Schema}", ClassVisibility.PublicStatic, nameSpace.ToArray()); builder .AppendLine($"public static IEnumerable<object[]> {item.Name}EntityDataSource") .AppendLine("{") .IncrementIndent() .AppendLine("get") .AppendLine("{") .IncrementIndent() .AppendLine($"var result = new PairList<Pair<{item.Name}Entity>, bool, string>();"); builder .ClassEnd(); Writer.WriteFile(path, file, builder, false); }
public void WriteFactory() { var path = Path.Combine(Config.CSharp.Factory.Path); var file = $"Register.Auto.cs"; var nameSpace = new List <string> { "XCommon.Patterns.Ioc", "XCommon.Patterns.Specification.Validation", "XCommon.Patterns.Specification.Query" }; foreach (var schema in Config.DataBaseItems) { if (Config.CSharp.Repository.Contract != null && Config.CSharp.Repository.Contract.Execute) { nameSpace.Add($"{Config.CSharp.Repository.Contract.NameSpace}.{schema.Name}"); } nameSpace.Add($"{Config.CSharp.Repository.Concrecte.NameSpace}.{schema.Name}"); nameSpace.Add($"{Config.CSharp.Repository.Concrecte.NameSpace}.{schema.Name}.Query"); nameSpace.Add($"{Config.CSharp.Repository.Concrecte.NameSpace}.{schema.Name}.Validate"); nameSpace.Add($"{Config.CSharp.Entity.NameSpace}.{schema.Name}"); nameSpace.Add($"{Config.CSharp.Entity.NameSpace}.{schema.Name}.Filter"); nameSpace.Add($"{Config.CSharp.EntityFramework.NameSpace}.{schema.Name}"); } ; var builder = new StringBuilderIndented(); builder .ClassInit("Register", null, $"{Config.CSharp.Factory.NameSpace}", ClassVisility.Public, true, nameSpace.ToArray()) .AppendLine("public static void Do(bool unitTest = false)") .AppendLine("{") .IncrementIndent(); if (Config.CSharp.Repository.Contract != null && Config.CSharp.Repository.Contract.Execute) { builder .AppendLine("RegisterRepository();"); } builder .AppendLine("RegisterValidate();") .AppendLine("RegisterQuery();") .AppendLine("RegisterCustom(unitTest);") .DecrementIndent() .AppendLine("}") .AppendLine(); if (Config.CSharp.Repository.Contract != null && Config.CSharp.Repository.Contract.Execute) { GenerateFactoryRepository(builder); } GenerateFactoryQuery(builder); GenerateFactoryValidate(builder); builder .ClassEnd(); Writer.WriteFile(path, file, builder, true); }
public void WriteEntity(DataBaseTable item) { var path = Path.Combine(Config.CSharp.EntityFramework.Path, item.Schema); var file = $"{item.Name}.cs"; var nameSpace = new List <string> { "System", "System.Collections.Generic" }; nameSpace.AddRange(item.RelationShips.Where(c => c.TableFK != item.Schema).Select(c => $"{Config.CSharp.EntityFramework.NameSpace}.{c.SchemaFK}").Distinct()); nameSpace.AddRange(item.RelationShips.Where(c => c.TablePK != item.Schema).Select(c => $"{Config.CSharp.EntityFramework.NameSpace}.{c.SchemaPK}").Distinct()); nameSpace.AddRange(item.Columns.Where(c => c.Schema != item.Schema).Select(c => c.Schema)); nameSpace.AddRange(item.ProcessRemapSchema(Config)); var itemNameSpace = $"{Config.CSharp.EntityFramework.NameSpace}.{item.Schema}"; nameSpace.RemoveAll(c => c == itemNameSpace); var builder = new StringBuilderIndented(); builder .GenerateFileMessage() .ClassInit(item.Name, null, itemNameSpace, ClassVisility.Public, nameSpace.ToArray()); foreach (var property in item.Columns) { var propertyType = property.ProcessRemapProperty(Config); builder .AppendLine($"public {propertyType} {property.Name} {{ get; set; }}") .AppendLine(); } foreach (var relationShip in item.RelationShips.Where(c => c.Type == DataBaseRelationShipType.Single)) { var relationShipName = ProcessRelationShipName(relationShip, relationShip.TablePK); builder .AppendLine($"public virtual {relationShip.TablePK} {relationShipName} {{ get; set; }}") .AppendLine(); } foreach (var relationShip in item.RelationShips.Where(c => c.Type == DataBaseRelationShipType.Many)) { var relationShipName = ProcessRelationShipName(relationShip, relationShip.TableFK); builder .AppendLine($"public virtual ICollection<{relationShip.TableFK}> {relationShipName} {{ get; set; }}") .AppendLine(); } builder .ClassEnd(); Writer.WriteFile(path, file, builder, true); }