Ejemplo n.º 1
0
		public void Run(CSharpConfig config)
		{
			foreach (var group in config.DataBaseItems)
			{
				foreach (var item in group.Items)
				{
					string path = Path.Combine(config.ContractPath, group.Name);
					string file = $"I{item.Name}Business.cs";

					if (File.Exists(Path.Combine(path, file)))
						continue;

					var nameSpace = new List<string> { "System", "XCommon.Patterns.Repository" };
					nameSpace.Add($"{config.EntrityNameSpace}.{group.Name}");
					nameSpace.Add($"{config.EntrityNameSpace}.{group.Name}.Filter");

					StringBuilderIndented builder = new StringBuilderIndented();

					builder
						.InterfaceInit($"I{item.Name}Business", $"IRepository<{item.Name}Entity, {item.Name}Filter>", $"{config.ContractNameSpace}.{group.Name}", ClassVisility.Public, nameSpace.ToArray())
						.InterfaceEnd();

					WriteFile(path, file, builder);
				}
			}

			Console.WriteLine("Generate contract code - OK");
		}
Ejemplo n.º 2
0
		public void Run(CSharpConfig config)
		{
			GenerateFactoryCuston(config);
			GenerateFactory(config);

			Console.WriteLine("Generate factory code - OK");
		}
Ejemplo n.º 3
0
		private void GenerateValidateTest(CSharpConfig config, ItemGroup group, Item item)
		{
			string path = Path.Combine(config.UnitTestPath, group.Name);
			string file = $"{item.Name}Test.cs";

			if (File.Exists(Path.Combine(path, file)))
				return;

			var className = $"{item.Name}Test";
			var nameSpace = new List<string> { "System.Linq", "System.Collections.Generic", "FluentAssertions", "Xunit", "XCommon.Patterns.Ioc", "XCommon.Application.Executes", "XCommon.Patterns.Specification.Validation", "XCommon.Patterns.Specification.Query" };
			nameSpace.Add($"{config.EntrityNameSpace}.{group.Name}");
			nameSpace.Add($"{config.EntrityNameSpace}.{group.Name}.Filter");
            nameSpace.Add($"{config.DataBase.NameSpace}.{group.Name}");
            nameSpace.Add($"{config.UnitTestNameSpace}.{group.Name}.DataSource");

			StringBuilderIndented builder = new StringBuilderIndented();

			builder
				.ClassInit(className, "BaseTest", $"{config.UnitTestNameSpace}.{group.Name}", ClassVisility.Public, false, nameSpace.ToArray());

			builder
				.AppendLine("[Inject]")
				.AppendLine($"protected ISpecificationValidation<{item.Name}Entity> SpecificationValidation {{ get; set; }}")
                .AppendLine()
                .AppendLine("[Inject]")
                .AppendLine($"protected ISpecificationQuery<{item.Name}, {item.Name}Filter> SpecificationQuery {{ get; set; }}")
                .AppendLine()
				.AppendLine($"[Theory(DisplayName = \"{item.Name} (Validate)\")]")
				.AppendLine($"[MemberData(nameof({item.Name}DataSource.EntityValidation), MemberType = typeof({item.Name}DataSource))]")
				.AppendLine($"public void Validate{item.Name}({item.Name}Entity data, bool expected, string message)")
				.AppendLine("{")
				.IncrementIndent()
				.AppendLine("Execute execute = new Execute();")
				.AppendLine("bool result = SpecificationValidation.IsSatisfiedBy(data, execute);")
				.AppendLine()
				.AppendLine("result.Should().Be(expected, message);")
				.AppendLine("expected.Should().Be(!execute.HasErro, message);")
				.DecrementIndent()
				.AppendLine("}")
                .AppendLine()

                .AppendLine($"[Theory(DisplayName = \"{item.Name} (Load) \")]")
                .AppendLine($"[MemberData(nameof({item.Name}DataSource.EntityFilter), MemberType = typeof({item.Name}DataSource))]")
                .AppendLine($"public void ValidateLoad(List<{item.Name}> source, {item.Name}Filter filter, int expected, string message)")
                .AppendLine("{")
                .IncrementIndent()
                .AppendLine("var result = SpecificationQuery.Build(source, filter);")
                .AppendLine()
                .AppendLine("result.Count().Should().Be(expected, message);")
                .DecrementIndent()
                .AppendLine("}")

				.ClassEnd();

			WriteFile(path, file, builder);
		}
Ejemplo n.º 4
0
		internal void Run(CSharpConfig config)
		{
			GenerateConcrete(config);
			GenerateValidation(config);
			GenerateQuery(config);

			Console.WriteLine("Generate concrect code - OK");
			Console.WriteLine("Generate concrect code [validation] - OK");
			Console.WriteLine("Generate concrect code [query] - OK");
		}
Ejemplo n.º 5
0
		public void Run(CSharpConfig config)
		{
			ClearFolder(config);
			GenerateContext(config);
			GenerateEntity(config);
			GenerateEntityMap(config);

			Console.WriteLine("Generate data code - OK");
			Console.WriteLine("Generate data code [entity] - OK");
			Console.WriteLine("Generate data code [entity-map] - OK");
		}
Ejemplo n.º 6
0
		public void Run(CSharpConfig config)
		{
			foreach (var group in config.DataBaseItems)
			{
				foreach (var item in group.Items)
				{
					GenerateValidateDataSource(config, group, item);
					GenerateValidateTest(config, group, item);
				}
			}

			Console.WriteLine("Generate unit test code - OK");
		}
Ejemplo n.º 7
0
		public void Run(CSharpConfig config)
		{
			foreach (var group in config.DataBaseItems)
			{
				foreach (var item in group.Items)
				{
					GenerateEntity(config, group, item);
					GenerateFilter(config, group, item);
				}
			}

			Console.WriteLine("Generate entity code - OK");
			Console.WriteLine("Generate entity code [filter] - OK");
		}
Ejemplo n.º 8
0
		private void GenerateQuery(CSharpConfig config)
		{
			foreach (var group in config.DataBaseItems)
			{
				foreach (var table in group.Items)
				{
					string path = Path.Combine(config.ConcretePath, group.Name, "Query");
					string file = Path.Combine(path, $"{table.Name}Query.cs");

					if (File.Exists(file))
						continue;

					var nameSpace = new List<string> { "System", "System.Linq", "System.Collections.Generic", "XCommon.Patterns.Specification.Query", "XCommon.Patterns.Specification.Query.Extensions", "XCommon.Extensions.String", "XCommon.Extensions.Checks" };
					nameSpace.Add($"{config.DataBase.NameSpace}.{group.Name}");
					nameSpace.Add($"{config.EntrityNameSpace}.{group.Name}.Filter");

					StringBuilderIndented builder = new StringBuilderIndented();

					var columnOrder = table.Properties.Any(c => c.Name == "Name")
						? "Name"
						: table.NameKey;

					builder
						.ClassInit($"{table.Name}Query", $"SpecificationQuery<{table.Name}, {table.Name}Filter>", $"{config.ConcreteNameSpace}.{group.Name}.Query", ClassVisility.Public, nameSpace.ToArray())
						.AppendLine($"public override IQueryable<{table.Name}> Build(IQueryable<{table.Name}> source, {table.Name}Filter filter)")
						.AppendLine("{")
						.IncrementIndent()
						.AppendLine($"var spefications = NewSpecificationList()")
						.IncrementIndent()
						.AppendLine($".And(e => e.{table.NameKey} == filter.Key, f => f.Key.HasValue)")
						.AppendLine($".And(e => filter.Keys.Contains(e.{table.NameKey}), f => f.Keys.IsValidList())")
						.AppendLine($".OrderBy(e => e.{columnOrder})")
						.AppendLine(".Take(filter.PageNumber, filter.PageSize);")
						.DecrementIndent()
						.AppendLine()
						.AppendLine("return CheckSpecifications(spefications, source, filter);")
						.DecrementIndent()
						.AppendLine("}")
						.ClassEnd();

					if (!Directory.Exists(path))
						Directory.CreateDirectory(path);

					File.WriteAllText(file, builder.ToString(), Encoding.UTF8);
				}
			}
		}
Ejemplo n.º 9
0
		private void GenerateEntity(CSharpConfig config, ItemGroup group, Item item)
		{
			string path = Path.Combine(config.EntrityPath, group.Name, "Auto");
			string file = $"{item.Name}Entity.cs";

			var nameSpace = new List<string> { "System", "XCommon.Patterns.Repository.Entity", "System.Runtime.Serialization" };
			nameSpace.AddRange(item.Properties.Where(c => c.NameGroup != group.Name).Select(c => c.NameGroup));

			StringBuilderIndented builder = new StringBuilderIndented();

			builder
				.GenerateFileMessage()
				.ClassInit($"{item.Name}Entity", "EntityBase", $"{config.EntrityNameSpace}.{group.Name}", ClassVisility.Public, true, nameSpace.ToArray());

			foreach (var column in item.Properties)
			{
				builder
					.AppendLine($"public {column.Type} {column.Name} {{ get; set; }}")
					.AppendLine();
			}

			builder
				.AppendLine()
				.AppendLine("[IgnoreDataMember]")
				.AppendLine("public override Guid Key")
				.AppendLine("{")
				.IncrementIndent()
				.AppendLine("get")
				.AppendLine("{")
				.IncrementIndent()
				.AppendLine($"return {item.NameKey};")
				.DecrementIndent()
				.AppendLine("}")
				.AppendLine("set")
				.AppendLine("{")
				.IncrementIndent()
				.AppendLine($"{item.NameKey} = value;")
				.DecrementIndent()
				.AppendLine("}")
				.DecrementIndent()
				.AppendLine("}")
				.ClassEnd();

			WriteFile(path, file, builder);
		}
Ejemplo n.º 10
0
		private void GenerateFilter(CSharpConfig config, ItemGroup group, Item item)
		{
			string path = Path.Combine(config.EntrityPath, group.Name, "Filter");
			string file = $"{item.Name}Filter.cs";

			if (File.Exists(Path.Combine(path, file)))
				return;

			var nameSpace = new List<string> { "System", "XCommon.Patterns.Repository.Entity" };

			StringBuilderIndented builder = new StringBuilderIndented();

			builder
				.ClassInit($"{item.Name}Filter", "FilterBase", $"{config.EntrityNameSpace}.{group.Name}.Filter", ClassVisility.Public, nameSpace.ToArray())
				.ClassEnd();

			WriteFile(path, file, builder);
		}
Ejemplo n.º 11
0
		private void GenerateFactory(CSharpConfig config)
		{
			string path = Path.Combine(config.FactoryPath);
			string file = $"Register.Auto.cs";

			var nameSpace = new List<string> { "XCommon.Patterns.Ioc", "XCommon.Patterns.Specification.Validation", "XCommon.Patterns.Specification.Query" };

			config.DataBaseItems.ForEach(group =>
			{
				nameSpace.Add($"{config.ContractNameSpace}.{group.Name}");
				nameSpace.Add($"{config.ConcreteNameSpace}.{group.Name}");
				nameSpace.Add($"{config.ConcreteNameSpace}.{group.Name}.Query");
				nameSpace.Add($"{config.ConcreteNameSpace}.{group.Name}.Validate");
				nameSpace.Add($"{config.EntrityNameSpace}.{group.Name}");
				nameSpace.Add($"{config.EntrityNameSpace}.{group.Name}.Filter");
				nameSpace.Add($"{config.DataBase.NameSpace}.{group.Name}");
			});

			StringBuilderIndented builder = new StringBuilderIndented();

			builder
				.ClassInit("Register", null, $"{config.FacotryNameSpace}", ClassVisility.Public, true, nameSpace.ToArray())
				.AppendLine("public static void Do(bool unitTest = false)")
				.AppendLine("{")
				.IncrementIndent()
				.AppendLine("RegisterRepository();")
				.AppendLine("RegisterValidate();")
				.AppendLine("RegisterQuery();")
				.AppendLine("RegisterCustom(unitTest);")
				.DecrementIndent()
				.AppendLine("}")
				.AppendLine();

			GenerateFactoryRepository(config, builder);
			GenerateFactoryQuery(config, builder);
			GenerateFactoryValidate(config, builder);

			builder
				.ClassEnd();

			WriteFile(path, file, builder);
		}
Ejemplo n.º 12
0
		internal int Run(CSharpConfig config)
		{
			if (config == null)
				return -1;

			Concrete concrete = new Concrete();
			Contract contract = new Contract();
			Data data = new Data();
			Entity entity = new Entity();
			Factory factory = new Factory();
			Writter.UnitTest unitTest = new Writter.UnitTest();

			data.Run(config);
			entity.Run(config);
			contract.Run(config);
			concrete.Run(config);
			unitTest.Run(config);
			factory.Run(config);

			return 0;
		}
Ejemplo n.º 13
0
		private void ClearFolder(CSharpConfig config)
		{
			if (!Directory.Exists(config.DataBase.Path))
				Directory.CreateDirectory(config.DataBase.Path);
			
			foreach (var directory in Directory.GetDirectories(config.DataBase.Path, "*", SearchOption.TopDirectoryOnly))
			{
				if (directory.Contains("Properties"))
					continue;

				Directory.Delete(directory, true);
			}

			foreach (var file in Directory.GetFiles(config.DataBase.Path, "*.cs", SearchOption.AllDirectories))
			{
				if (file.Contains("AssemblyInfo.cs"))
					continue;

				File.Delete(file);
			}
		}
Ejemplo n.º 14
0
		private void GenerateFactoryCuston(CSharpConfig config)
		{
			string path = Path.Combine(config.FactoryPath);
			string file = $"Register.cs";

			if (File.Exists(Path.Combine(path, file)))
				return;

			var nameSpace = new List<string> { "XCommon.Patterns.Ioc" };

			StringBuilderIndented builder = new StringBuilderIndented();

			builder
				.ClassInit("Register", null, $"{config.FacotryNameSpace}", ClassVisility.Public, true, nameSpace.ToArray())
				.AppendLine("public static void RegisterCustom(bool unitTest)")
				.AppendLine("{")
				.AppendLine("}")
				.ClassEnd();

			WriteFile(path, file, builder);
		}
Ejemplo n.º 15
0
		private void GenerateValidation(CSharpConfig config)
		{
			foreach (var group in config.DataBaseItems)
			{
				foreach (var item in group.Items)
				{
					string path = Path.Combine(config.ConcretePath, group.Name, "Validate");
					string file = $"{item.Name}Validate.cs";

					if (File.Exists(Path.Combine(path, file)))
						continue;

					var nameSpace = new List<string> { "System", "XCommon.Application.Executes", "XCommon.Patterns.Specification.Validation", "XCommon.Patterns.Specification.Validation.Extensions" };
					nameSpace.Add($"{config.EntrityNameSpace}.{group.Name}");

					StringBuilderIndented builder = new StringBuilderIndented();

					builder
						.ClassInit($"{item.Name}Validate", $"SpecificationValidation<{item.Name}Entity>", $"{config.ConcreteNameSpace}.{group.Name}.Validate", ClassVisility.Public, nameSpace.ToArray())						
						.AppendLine($"public override bool IsSatisfiedBy({item.Name}Entity entity, Execute execute)")
						.AppendLine("{")
						.IncrementIndent()
                        .AppendLine("var spefications = NewSpecificationList()")
                        .IncrementIndent()
                        .AppendLine(".AndIsValid(e => e.Key != Guid.Empty, \"Default key isn't valid\");")
                        .DecrementIndent()
                        .AppendLine()
						.AppendLine("return CheckSpecifications(spefications, entity, execute);")
						.DecrementIndent()
						.AppendLine("}")
						.InterfaceEnd();

					

					WriteFile(path, file, builder);
				}
			}
		}
Ejemplo n.º 16
0
		private void GenerateContext(CSharpConfig config)
		{
			string path = config.DataBase.Path;
			string file = $"{config.DataBase.ContextName}.cs";

			List<string> nameSpaces = new List<string> { "System", "Microsoft.EntityFrameworkCore", "Microsoft.EntityFrameworkCore.Infrastructure", "XCommon.Patterns.Ioc", "XCommon.Application" };
			nameSpaces.AddRange(config.DataBaseItems.Select(c => $"{config.DataBase.NameSpace}.{c.Name}"));
			nameSpaces.AddRange(config.DataBaseItems.Select(c => $"{config.DataBase.NameSpace}.{c.Name}.Map"));

			StringBuilderIndented builder = new StringBuilderIndented();

			builder
				.GenerateFileMessage()
				.ClassInit(config.DataBase.ContextName, "DbContext", config.DataBase.NameSpace, ClassVisility.Public, nameSpaces.ToArray())
				.AppendLine()
				.AppendLine("private IApplicationSettings AppSettings => Kernel.Resolve<IApplicationSettings>();")
				.AppendLine();

			foreach (var item in config.DataBaseItems.SelectMany(c => c.Items))
			{
				builder
					.AppendLine($"public DbSet<{item.Name}> {item.Name} {{ get; set; }}")
					.AppendLine();
			}

			builder
				.AppendLine("protected override void OnConfiguring(DbContextOptionsBuilder options)")
				.AppendLine("{")
				.IncrementIndent()
				.AppendLine("if (AppSettings.UnitTest)")
				.AppendLine("{")
				.IncrementIndent()
				.AppendLine($"options")
				.IncrementIndent()
				.AppendLine($".UseInMemoryDatabase(\"{config.DataBase.ContextName}\")")
				.AppendLine(".ConfigureWarnings(config => config.Ignore(InMemoryEventId.TransactionIgnoredWarning));")
				.DecrementIndent()
				.AppendLine()
				.AppendLine("return;")
				.DecrementIndent()
				.AppendLine("}")
				.AppendLine()
				.AppendLine($"options.UseSqlServer(AppSettings.ConnectionString);")
				.AppendLine()
				.DecrementIndent()
				.AppendLine("}")
				.AppendLine()
				.AppendLine("protected override void OnModelCreating(ModelBuilder modelBuilder)")
				.AppendLine("{");

			using (builder.Indent())
			{
				builder
					.AppendLine();

				foreach (var item in config.DataBaseItems.SelectMany(c => c.Items))
				{
					builder.AppendLine($"{item.Name}Map.Map(modelBuilder, AppSettings.UnitTest);");
				}
			}

			builder
				.AppendLine("}")
				.ClassEnd();

			WriteFile(path, file, builder);
		}
Ejemplo n.º 17
0
		private string ProcessRelationShipName(CSharpConfig config, ItemRelationship relationShip, string defaultName)
		{
			if (config.DataBase.Rewrite == null)
				return defaultName;

			var rewrite = config.DataBase.Rewrite.FirstOrDefault(c =>
					c.SchemaPK == relationShip.ItemGroupPK
					&& c.TablePK == relationShip.ItemPK
					&& c.ColumnPK == relationShip.PropertyPK
					&& c.SchemaFK == relationShip.ItemGroupFK
					&& c.TableFK == relationShip.ItemFK
					&& c.ColumnFK == relationShip.PropertyFK);

			if (rewrite != null)
				return rewrite.CustonName;

			return defaultName;
		}
Ejemplo n.º 18
0
		private void ProcessMapRelationShips(CSharpConfig config, StringBuilderIndented builder, Item item)
		{
			foreach (var relationShip in item.Relationships.Where(c => c.RelationshipType == ItemRelationshipType.Single))
			{
				string relationShipNamePK = ProcessRelationShipName(config, relationShip, relationShip.ItemPK);
				string relationShipNameFK = ProcessRelationShipName(config, relationShip, relationShip.ItemFK);

				builder
					.AppendLine("entity")
					.IncrementIndent()
					.AppendLine($".HasOne(d => d.{relationShipNamePK})")
					.AppendLine($".WithMany(p => p.{relationShipNameFK})")
					.AppendLine($".HasForeignKey(d => d.{relationShip.PropertyFK});")
					.DecrementIndent()
					.AppendLine();
			}
		}
Ejemplo n.º 19
0
		private void GenerateEntityMap(CSharpConfig config)
		{
			foreach (var group in config.DataBaseItems)
			{
				foreach (var item in group.Items)
				{
					string path = Path.Combine(config.DataBase.Path, group.Name, "Map");
					string file = $"{item.Name}Map.cs";

					StringBuilderIndented builder = new StringBuilderIndented();

					builder
						.GenerateFileMessage()
						.ClassInit($"{item.Name}Map", null, $"{config.DataBase.NameSpace}.{group.Name}.Map", ClassVisility.Internal, "System", "Microsoft.EntityFrameworkCore")
						.AppendLine("internal static void Map(ModelBuilder modelBuilder, bool unitTest)")
						.AppendLine("{")
						.IncrementIndent()
						.AppendLine($"modelBuilder.Entity<{item.Name}>(entity =>")
						.AppendLine("{")
						.IncrementIndent()
						.AppendLine($"entity.HasKey(e => e.{item.NameKey});")
						.AppendLine()
						.AppendLine("if (!unitTest)")
						.IncrementIndent()
						.AppendLine($"entity.ToTable(\"{item.Name}\", \"{group.Name}\");")
						.DecrementIndent()
						.AppendLine("else")
						.IncrementIndent()
						.AppendLine($"entity.ToTable(\"{group.Name}{item.Name}\");")
						.DecrementIndent()
						.AppendLine();

					ProcessMapColumns(builder, item);
					ProcessMapRelationShips(config, builder, item);

					builder
						.DecrementIndent()
						.AppendLine("});")
						.DecrementIndent()
						.AppendLine("}")
						.ClassEnd();

					WriteFile(path, file, builder);
				}
			}
		}
Ejemplo n.º 20
0
		private void GenerateValidateDataSource(CSharpConfig config, ItemGroup group, Item item)
		{
			string path = Path.Combine(config.UnitTestPath, group.Name, "DataSource");
			string file = $"{item.Name}DataSource.cs";

			if (File.Exists(Path.Combine(path, file)))
				return;

			var className = $"{item.Name}DataSource";
			var nameSpace = new List<string> { "System", "XCommon.Util", "System.Collections.Generic" };
			nameSpace.Add($"{config.EntrityNameSpace}.{group.Name}");
			nameSpace.Add($"{config.DataBase.NameSpace}.{group.Name}");
            nameSpace.Add($"{config.EntrityNameSpace}.{group.Name}.Filter");

			StringBuilderIndented builder = new StringBuilderIndented();

			builder
				.ClassInit(className, string.Empty, $"{config.UnitTestNameSpace}.{group.Name}.DataSource", ClassVisility.Public, false, nameSpace.ToArray());

			builder
				.AppendLine($"public static List<{item.Name}> Source")
				.AppendLine("{")
				.IncrementIndent()
                .AppendLine("get")
                .AppendLine("{")
                .IncrementIndent()            
                .AppendLine($"List<{item.Name}> result = new List<{item.Name}>();")
                .AppendLine()
                .AppendLine("return result;")
                .DecrementIndent()
                .AppendLine("}")
                .DecrementIndent()
                .AppendLine("}")

                .AppendLine($"public static IEnumerable<object[]> EntityValidation")
                .AppendLine("{")
                .IncrementIndent()
                .AppendLine("get")
                .AppendLine("{")
                .IncrementIndent()

                .AppendLine($"PairList<{item.Name}Entity, bool> result = new PairList<{item.Name}Entity, bool>();")
                .AppendLine()
                .AppendLine("result.Add(null, false, \"Null value\");")
                .AppendLine($"result.Add(new {item.Name}Entity(), false, \"Default value\");")
                .AppendLine()
                .AppendLine("return result.Cast();")
                .DecrementIndent()
                .AppendLine("}")
                .DecrementIndent()
                .AppendLine("}")
                
                .AppendLine($"public static IEnumerable<object[]> EntityFilter")
                .AppendLine("{")
                .IncrementIndent()
                .AppendLine("get")
                .AppendLine("{")
                .IncrementIndent()
                .AppendLine($"PairList<List<{item.Name}>, {item.Name}Filter, int> result = new PairList<List<{item.Name}>, {item.Name}Filter, int>();")
                .AppendLine()
                .AppendLine($"result.Add(Source, new {item.Name}Filter(), 0, \"Default filter\");")
                .AppendLine()
                .AppendLine("return result.Cast();")
                .DecrementIndent()
                .AppendLine("}")
                .DecrementIndent()
                .AppendLine("}")

                .ClassEnd();

			WriteFile(path, file, builder);
		}
Ejemplo n.º 21
0
		private void GenerateEntity(CSharpConfig config)
		{
			foreach (var group in config.DataBaseItems)
			{
				foreach (var item in group.Items)
				{
					string path = Path.Combine(config.DataBase.Path, group.Name);
					string file = $"{item.Name}.cs";

					var nameSpace = new List<string> { "System", "System.Collections.Generic" };
					nameSpace.AddRange(item.Relationships.Where(c => c.ItemGroupFK != group.Name).Select(c => $"{config.DataBase.NameSpace}.{c.ItemGroupFK}").Distinct());
					nameSpace.AddRange(item.Relationships.Where(c => c.ItemGroupPK != group.Name).Select(c => $"{config.DataBase.NameSpace}.{c.ItemGroupPK}").Distinct());
					nameSpace.AddRange(item.Properties.Where(c => c.NameGroup != group.Name).Select(c => c.NameGroup));

					StringBuilderIndented builder = new StringBuilderIndented();

					builder
						.GenerateFileMessage()
						.ClassInit(item.Name, null, $"{config.DataBase.NameSpace}.{group.Name}", ClassVisility.Public, nameSpace.ToArray());

					foreach (var property in item.Properties)
					{
						builder
							.AppendLine($"public {property.Type} {property.Name} {{ get; set; }}")
							.AppendLine();
					}

					foreach (var relationShip in item.Relationships.Where(c => c.RelationshipType == ItemRelationshipType.Single))
					{
						string relationShipName = ProcessRelationShipName(config, relationShip, relationShip.ItemPK);

						builder
							.AppendLine($"public virtual {relationShip.ItemPK} {relationShipName} {{ get; set; }}")
							.AppendLine();
					}

					foreach (var relationShip in item.Relationships.Where(c => c.RelationshipType == ItemRelationshipType.Many))
					{
						string relationShipName = ProcessRelationShipName(config, relationShip, relationShip.ItemFK);

						builder
							.AppendLine($"public virtual ICollection<{relationShip.ItemFK}> {relationShipName} {{ get; set; }}")
							.AppendLine();
					}

					builder
						.ClassEnd();

					WriteFile(path, file, builder);
				}
			}
		}
Ejemplo n.º 22
0
		private void GenerateConcrete(CSharpConfig config)
		{
			foreach (var group in config.DataBaseItems)
			{
				foreach (var item in group.Items)
				{
					string path = Path.Combine(config.ConcretePath, group.Name);
					string file = Path.Combine(path, $"{item.Name}Business.cs");

					if (File.Exists(file))
						continue;

					var nameSpace = new List<string> { "System", " XCommon.Patterns.Repository" };
					nameSpace.Add($"{config.EntrityNameSpace}.{group.Name}");
					nameSpace.Add($"{config.EntrityNameSpace}.{group.Name}.Filter");
					nameSpace.Add($"{config.ContractNameSpace}.{group.Name}");
					nameSpace.Add($"{config.DataBase.NameSpace}");
					nameSpace.Add($"{config.DataBase.NameSpace}.{group.Name}");

					StringBuilderIndented builder = new StringBuilderIndented();

					builder
						.ClassInit($"{item.Name}Business", $"RepositoryEFBase<{item.Name}Entity, {item.Name}Filter, {item.Name}, {config.DataBase.ContextName}>, I{item.Name}Business", $"{config.ConcreteNameSpace}.{group.Name}", ClassVisility.Public, nameSpace.ToArray())
						.ClassEnd();

					if (!Directory.Exists(path))
						Directory.CreateDirectory(path);

					File.WriteAllText(file, builder.ToString(), Encoding.UTF8);
				}
			}
		}
Ejemplo n.º 23
0
		private void GenerateFactoryValidate(CSharpConfig config, StringBuilderIndented builder)
		{
			builder
				.AppendLine("private static void RegisterValidate()")
				.AppendLine("{")
				.IncrementIndent();

			foreach (var table in config.DataBaseItems.SelectMany(c => c.Items))
			{
				builder
					.AppendLine($"Kernel.Map<ISpecificationValidation<{table.Name}Entity>>().To<{table.Name}Validate>();");
			}

			builder
				.DecrementIndent()
				.AppendLine("}");
		}
Ejemplo n.º 24
0
		private void GenerateFactoryRepository(CSharpConfig config, StringBuilderIndented builder)
		{
			builder
				.AppendLine("private static void RegisterRepository()")
				.AppendLine("{")
				.IncrementIndent();

			foreach (var table in config.DataBaseItems.SelectMany(c => c.Items))
			{
				builder
					.AppendLine($"Kernel.Map<I{table.Name}Business>().To<{table.Name}Business>();");
			}

			builder
				.DecrementIndent()
				.AppendLine("}");
		}