Beispiel #1
0
		private void TypeScript(string path, string name, string selector, string htmlRoot, string feture)
		{
			var file = $"{selector}.component.ts";

			if (File.Exists(Path.Combine(path, file)))
			{
				Console.WriteLine($"File already exists: {file}");
				return;
			}


			StringBuilderIndented builder = new StringBuilderIndented();
			string templateUrl = $"\"{htmlRoot}/{feture}/{selector}.html\",";

			builder
				.AppendLine("import { Component, OnInit } from \"@angular/core\";")
				.AppendLine()
				.AppendLine("@Component({")
				.IncrementIndent()
				.AppendLine($"selector: \"{selector}\",")
				.AppendLine("templateUrl: " + templateUrl.ToLower())
				.AppendLine($"styles: [require(\"./{selector}.scss\")]")
				.DecrementIndent()
				.AppendLine("})")
				.AppendLine($"export class {name.GetName()}Component implements OnInit {{")
				.IncrementIndent()
				.AppendLine("constructor() { }")
				.AppendLine()
				.AppendLine("ngOnInit(): void { }")
				.DecrementIndent()
				.AppendLine("}");

			WriteFile(path, file, builder);
		}
Beispiel #2
0
        internal void Run(string path, List<string> services)
		{
			path = path.ToLower();

			foreach (string service in services)
			{
				var file = Path.Combine(path, $"{service.GetSelector()}.service.ts").ToLower();

				if (File.Exists(Path.Combine(path, file)))
				{
					Console.WriteLine($"File already exists: {file}");
					return;
				}

				StringBuilderIndented builder = new StringBuilderIndented();

				builder
					.AppendLine("import { Injectable } from \"@angular/core\"; ")
					.AppendLine("import { Http, Response } from \"@angular/http\"; ")
					.AppendLine()
					.AppendLine("@Injectable()")
					.AppendLine($"export class {service.GetName()}Service {{")
					.IncrementIndent()
					.AppendLine("constructor(private http: Http) { }")
					.DecrementIndent()
					.AppendLine("}");

				WriteFile(path, file, builder);

				Console.WriteLine($"Generated component {service.GetName()}");
			}
		}
Beispiel #3
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");
		}
Beispiel #4
0
		protected void WriteFile(string path, string file, StringBuilderIndented builder)
		{
			if (!Directory.Exists(path))
				Directory.CreateDirectory(path);

			string fullPath = Path.Combine(path, file);

			File.WriteAllText(fullPath, builder.ToString(), Encoding.UTF8);
		}
Beispiel #5
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);
		}
Beispiel #6
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);
				}
			}
		}
Beispiel #7
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);
		}
Beispiel #8
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);
		}
Beispiel #9
0
		internal void Run(TypeScriptResource config, IndexExport index)
		{
			if (config.Resources == null || config.Resources.Count <= 0)
				return;

			StringBuilderIndented builder = new StringBuilderIndented();

			builder
				.AppendLine("import { Injectable } from \"@angular/core\";");

			if (config.LazyLoad)
			{
				builder
					.AppendLine("import { Http, Response } from \"@angular/http\";")
					.AppendLine("import { Observable } from \"rxjs/Observable\";");
			}

			builder
				.AppendLine("import { Map } from \"../entity\";")
				.AppendLine();

			Resources = new List<GeneratorResourceEntity>();

			GetResouces(config);
			BuildLanguageSuported(builder);
			BuildInterface(builder);

			if (!config.LazyLoad)
				BuildClass(config, builder);

			BuidService(config, builder);

			if (!Directory.Exists(config.Path))
				Directory.CreateDirectory(config.Path);

			var file = config.File.GetSelector() + ".service.ts";

			WriteFile(config.Path.ToLower(), file, builder);

			Index.Run(config.Path);

			index.Run(config.Path);
			Console.WriteLine("Generate resource typescript - OK");
		}
Beispiel #10
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);
		}
Beispiel #11
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);
		}
Beispiel #12
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);
				}
			}
		}
Beispiel #13
0
		private void Sass(string path, string selector, List<string> styleInclude)
		{
			var file = $"{selector}.scss";

			if (File.Exists(Path.Combine(path, file)))
			{
				Console.WriteLine($"File already exists: {file}");
				return;
			}

			StringBuilderIndented builder = new StringBuilderIndented();

			styleInclude.ForEach(c => builder.AppendLine(c));

			if (styleInclude.Count > 0)
				builder.AppendLine();

			builder
				.AppendLine($".{selector} {{")
				.AppendLine("}");

			WriteFile(path, file, builder);
		}
Beispiel #14
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);
				}
			}
		}
Beispiel #15
0
		private void ProcessMapColumns(StringBuilderIndented builder, Item item)
		{
			foreach (var property in item.Properties)
			{
				builder
					.Append($"entity.Property(e => e.{property.Name})");

				using (builder.Indent())
				{
					if (!property.Nullable)
						builder
							.AppendLine()
							.Append(".IsRequired()");

					if (property.Type == "string" && !string.IsNullOrEmpty(property.Size) && property.Size != "MAX")
						builder
							.AppendLine()
							.Append($".HasMaxLength({property.Size})");

					if (property.Key)
						builder
							.AppendLine()
							.Append(".ValueGeneratedNever()");
				}

				builder
					.Append(";")
					.AppendLine()
					.AppendLine();

			}
		}
Beispiel #16
0
		private void BuildNormalService(TypeScriptResource config, StringBuilderIndented builder)
		{
			builder
				.AppendLine("switch (this.Language.Name) {")
				.IncrementIndent();

			foreach (var culture in config.Cultures)
			{
				builder
					.AppendLine($"case \"{culture.Name}\":")
					.IncrementIndent();

				foreach (var resource in Resources)
				{
					builder
						.AppendLine($"this.{resource.ResourceName} = new {resource.ResourceName}{GetCultureName(culture.Name)}();");
				}

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

			builder
				.DecrementIndent()
				.AppendLine("}");
		}
Beispiel #17
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);
				}
			}
		}
Beispiel #18
0
		private void BuildLanguageSuportedContructor(TypeScriptResource config, StringBuilderIndented builder)
		{
			foreach (var culture in config.Cultures)
			{
				builder.AppendLine($"this.Languages.push({{ Name: \"{culture.Name}\", Description: \"{culture.Description}\" }});");
			}
		}
Beispiel #19
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("}");
		}
Beispiel #20
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("}");
		}
Beispiel #21
0
 public StringBuilderIndented(StringBuilderIndented from)
 {
     _indent = from._indent;
 }
Beispiel #22
0
            public Indenter(StringBuilderIndented stringBuilder)
            {
                _stringBuilder = stringBuilder;

                _stringBuilder.IncrementIndent();
            }
Beispiel #23
0
		private void BuildInterface(StringBuilderIndented builder)
		{
			foreach (var resource in Resources)
			{
				builder
					.AppendLine($"export interface I{resource.ResourceName} {{")
					.IncrementIndent();

				foreach (var value in resource.Values.FirstOrDefault().Properties)
				{
					builder
						.AppendLine($"{value.Key}: string;");
				}

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

			builder
				.AppendLine("export interface IResource {")
				.IncrementIndent()
				.AppendLine("Culture: string;");

			foreach (var resource in Resources)
			{
				builder
					.AppendLine($"{resource.ResourceName}: I{resource.ResourceName};");
			}

			builder
				.DecrementIndent()
				.AppendLine("}")
				.AppendLine();
		}
Beispiel #24
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);
				}
			}
		}
Beispiel #25
0
		private void BuildLazyService(TypeScriptResource config, StringBuilderIndented builder)
		{
			builder
				.AppendLine("if (this.Resources[this.Language.Name]) {")
				.IncrementIndent()
				.AppendLine("let resource: IResource = this.Resources[this.Language.Name];")
				.AppendLine();

			foreach (var resource in Resources)
			{
				builder
					.AppendLine($"this.{resource.ResourceName} = resource.{resource.ResourceName};");
			}

			builder
				.AppendLine()
				.AppendLine("return;")
				.DecrementIndent()
				.AppendLine("}")
				.AppendLine()
				.AppendLine($"this.http.get(`{config.RequestAddress}/${{this.Language.Name}}`)")
				.IncrementIndent()
				.AppendLine(".map((response: Response, index: number) => response.json())")
				.AppendLine(".subscribe((resource: IResource) => {")
				.IncrementIndent()
				.AppendLine("this.Resources[resource.Culture] = resource;")
				.AppendLine();

			foreach (var resource in Resources)
			{
				builder
					.AppendLine($"this.{resource.ResourceName} = resource.{resource.ResourceName};");
			}

			builder
				.DecrementIndent()
				.AppendLine("});");
		}
Beispiel #26
0
		private void ProcessEnum()
		{
			StringBuilderIndented builder = new StringBuilderIndented();

            builder
                .GenerateFileMessage();

            foreach (var enumItem in TSEnums)
			{
				builder
					.AppendLine($"export enum {enumItem.Name} {{")
					.IncrementIndent();

				foreach (var values in enumItem.Values)
				{
					builder
						.AppendLine($"{values.Key} = {values.Value},");
				}

				builder
					.DecrementIndent()
					.AppendLine("}")
					.AppendLine();
			}
            
            WriteFile(Config.Path.ToLower(), "enum.ts", builder);
		}
Beispiel #27
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();
			}
		}
Beispiel #28
0
		private void BuildLanguageSuported(StringBuilderIndented builder)
		{
			builder
				.AppendLine("export class ApplicationCulture {")
				.IncrementIndent()
				.AppendLine("public Name: string;")
				.AppendLine("public Description: string;")
				.DecrementIndent()
				.AppendLine("}")
				.AppendLine();
		}
Beispiel #29
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);
		}
Beispiel #30
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);
		}
Beispiel #31
0
		private void ProcessTypes()
		{
			foreach (var file in TSClass.Select(c => c.FileName).Distinct().OrderBy(c => c))
			{
				var fileName = file.GetSelector();
				var importItems = TSClass.Where(c => c.FileName == file).SelectMany(c => c.Imports).ToList();

				StringBuilderIndented builder = new StringBuilderIndented();

                builder
                    .GenerateFileMessage();

                if (importItems.Any())
				{
					bool imported = false;

					foreach (var importFile in importItems.Where(c => c.File != file).Select(c => c.File).Distinct())
					{
						imported = true;

						var classes = importItems.Where(c => c.File == importFile).Select(c => c.Class).Distinct().ToArray();
						var import = string.Join(", ", classes);

						builder
							.AppendLine($"import {{ {import} }} from \"./{importFile.Replace(".ts", string.Empty)}\";");
					}

					if (imported)
					{
						builder
						    .AppendLine();
					}
				}

				foreach (var className in TSClass.Where(c => c.FileName == file).Select(c => c.Class).Distinct().OrderBy(c => c))
				{
					var tsClass = TSClass
						.Where(c => c.FileName == file && c.Class == className)
						.FirstOrDefault();

					var generics = tsClass.Properties
						.Where(c => c.Generic)
						.Select(c => c.Type)
						.ToList();

					string classNamePrint = tsClass.Class;

					if (generics.Count > 0)
					{
						classNamePrint = classNamePrint.Substring(0, classNamePrint.IndexOf('`'));
						classNamePrint += "<";
						classNamePrint += string.Join(", ", generics);
						classNamePrint += ">";
					}

					builder
						.AppendLine($"export interface I{classNamePrint} {{")
						.IncrementIndent();

					foreach (var property in tsClass.Properties)
					{
						string nullable = property.Nullable ? "?" : "";

						builder
							.AppendLine($"{property.Name}{nullable}: {property.Type}; ");
					}

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

                if (GeneratedEntities.Contains(fileName))
                {
                    throw new Exception($"Two file with same name cannot be generated: {fileName}");
                }

                GeneratedEntities.Add(fileName);
                WriteFile(Config.Path.ToLower(), fileName, builder);
			}
		}
Beispiel #32
0
		private void Html(string path, string selector, bool outlet)
		{
			var file = $"{selector}.html";

			if (File.Exists(Path.Combine(path, file)))
			{
				Console.WriteLine($"File already exists: {file}");
				return;
			}

			StringBuilderIndented builder = new StringBuilderIndented();

			builder
				.AppendLine($"<div class=\"{selector}\">")
				.IncrementIndent()
				.AppendLine($"<h1>Hey! I\"m {selector}</h1>");


			if (outlet)
			{
				builder
					.AppendLine("<router-outlet></router-outlet>");
			}

			builder
				.DecrementIndent()
				.AppendLine("</div>");

			WriteFile(path, file, builder);
		}