private Contracts.IGeneratedItem CreateModelFromContract(Type type, Common.UnitType unitType, Common.ItemType itemType) { type.CheckArgument(nameof(type)); var modelName = CreateModelNameFromInterface(type); var typeProperties = ContractHelper.GetAllProperties(type); var interfaces = GetInterfaces(type); var result = new Models.GeneratedItem(unitType, itemType) { FullName = CreateModelFullNameFromInterface(type), FileExtension = StaticLiterals.CSharpFileExtension, }; result.SubFilePath = $"{result.FullName}{result.FileExtension}"; CreateModelAttributes(type, result.Source); result.Add($"public partial class {modelName} : {type.FullName}"); result.Add("{"); result.AddRange(CreatePartialStaticConstrutor(modelName)); result.AddRange(CreatePartialConstrutor("public", modelName)); foreach (var item in ContractHelper.FilterPropertiesForGeneration(typeProperties)) { CreateModelPropertyAttributes(type, item, result.Source); result.AddRange(CreateProperty(item)); } result.AddRange(CreateCopyProperties(type)); foreach (var item in interfaces.Where(e => ContractHelper.HasCopyable(e))) { result.AddRange(CreateCopyProperties(item)); } result.AddRange(CreateFactoryMethods(type, false)); result.Add("}"); result.EnvelopeWithANamespace(CreateModelsNamespace(type), "using System;"); result.FormatCSharpCode(); return(result); }
private Contracts.IGeneratedItem CreateEntityFromContract(Type type, Common.ItemType itemType) { type.CheckArgument(nameof(type)); var baseItfc = GetPersistenceBaseContract(type); var contractHelper = new ContractHelper(type); var result = new Models.GeneratedItem(Common.UnitType.Logic, itemType) { FullName = CreateEntityFullNameFromInterface(type), FileExtension = StaticLiterals.CSharpFileExtension, }; result.SubFilePath = $"{result.FullName}{result.FileExtension}"; CreateEntityAttributes(type, result.Source); result.Add($"partial class {contractHelper.EntityName} : {type.FullName}"); result.Add("{"); result.AddRange(CreatePartialStaticConstrutor(contractHelper.EntityName)); result.AddRange(CreatePartialConstrutor("public", contractHelper.EntityName)); foreach (var item in ContractHelper.GetEntityProperties(type).Where(p => CanCreateProperty(type, p.Name))) { var codeLines = new List <string>(CreateProperty(item)); AfterCreateProperty(type, item, codeLines); result.AddRange(codeLines); } result.AddRange(CreateCopyProperties(type)); result.AddRange(CreateEquals(type)); result.AddRange(CreateGetHashCode(type)); result.AddRange(CreateFactoryMethods(type, baseItfc != null)); result.Add("}"); result.EnvelopeWithANamespace(CreateNameSpace(type), "using System;"); result.FormatCSharpCode(); return(result); }
private Contracts.IGeneratedItem CreatePersistenceController(Type type) { type.CheckArgument(nameof(type)); var entityName = CreateEntityNameFromInterface(type); var subNameSpace = CreateSubNamespaceFromType(type); var entityType = $"{StaticLiterals.EntitiesFolder}.{subNameSpace}.{entityName}"; var controllerName = $"{entityName}Controller"; var baseControllerName = "GenericPersistenceController"; var controllerAttributes = InitLogicControllerAttributes(type); var result = new Models.GeneratedItem(Common.UnitType.Logic, Common.ItemType.PersistenceController) { FullName = CreateLogicControllerFullNameFromInterface(type), FileExtension = StaticLiterals.CSharpFileExtension, }; result.SubFilePath = $"{result.FullName}{result.FileExtension}"; ConvertGenericPersistenceControllerName(type, ref baseControllerName); CreateLogicControllerAttributes(type, controllerAttributes); result.AddRange(controllerAttributes); result.Add($"sealed partial class {controllerName} : {baseControllerName}<{type.FullName}, {entityType}>"); result.Add("{"); result.AddRange(CreatePartialStaticConstrutor(controllerName)); result.AddRange(CreatePartialConstrutor("internal", controllerName, $"{SolutionProperties.DataContextFolder}.IContext context", "base(context)")); result.AddRange(CreatePartialConstrutor("internal", controllerName, "ControllerObject controller", "base(controller)", null, false)); result.Add("}"); result.EnvelopeWithANamespace(CreateLogicControllerNameSpace(type)); result.FormatCSharpCode(); return(result); }
public Contracts.IGeneratedItem CreateEnum(Type type) { type.CheckArgument(nameof(type)); var subPath = CreateSubPathFromType(type); var fileName = $"{ConvertFileName(type.Name)}.{CodeExtension}"; var result = new Models.GeneratedItem(Common.UnitType.AngularApp, Common.ItemType.TypeScriptEnum) { FullName = CreateTypeScriptFullName(type), FileExtension = CodeExtension, }; result.SubFilePath = Path.Combine(ProjectContractsPath, subPath, fileName); result.Add($"export enum {type.Name}" + " {"); foreach (var item in Enum.GetNames(type)) { var value = Enum.Parse(type, item); result.Add($"{item} = {(int)value},"); } result.Add("}"); result.AddRange(result.Source.Eject().Distinct()); FinishCreateContract(type, result.Source); result.FormatCSharpCode(); return(result); }
private Models.GeneratedItem CreateProperties(string separator) { var properties = new List <string>(); var contractsProject = ContractsProject.Create(SolutionProperties); var result = new Models.GeneratedItem(Common.UnitType.General, Common.ItemType.Properties) { FullName = $"Properties", FileExtension = ".csv", }; var menuItem = new MenuItem() { Text = "Home", Value = "home", Path = "/", Icon = "home", Order = 1, }; var types = contractsProject.PersistenceTypes .Union(contractsProject.BusinessTypes) .Union(contractsProject.ModuleTypes) .Union(contractsProject.ShadowTypes); result.SubFilePath = $"{result.FullName}{result.FileExtension}"; result.Add($"AppName{separator}ComponentName{separator}MemberName{separator}MemberInfo{separator}Value"); result.Add($"{SolutionProperties.SolutionName}{separator}NavMenu{separator}Home{separator}{separator}{JsonSerializer.Serialize<MenuItem>(menuItem)}"); result.AddRange(CreateTypeProperties(separator, types)); result.Source.AddRange(properties.Distinct()); return(result); }
private Contracts.IGeneratedItem CreateWebApiController(Type type) { //var routeBase = $"/api/[controller]"; var entityName = CreateEntityNameFromInterface(type); var subNameSpace = CreateSubNamespaceFromType(type); var contractType = $"Contracts.{subNameSpace}.{type.Name}"; var modelType = $"Transfer.{subNameSpace}.{entityName}"; var controllerName = entityName.EndsWith("s") ? entityName : $"{entityName}s"; var result = new Models.GeneratedItem(Common.UnitType.WebApi, Common.ItemType.WebApiController) { FullName = CreateWebApiControllerFullNameFromInterface(type), FileExtension = StaticLiterals.CSharpFileExtension, }; result.SubFilePath = $"{result.FullName}{result.FileExtension}"; ConvertWebApiControllerName(type, ref controllerName); result.Add("using Microsoft.AspNetCore.Mvc;"); result.Add($"using TContract = {contractType};"); result.Add($"using TModel = {modelType};"); result.Add("[ApiController]"); result.Add("[Route(\"Controller\")]"); CreateWebApiControllerAttributes(type, result.Source); result.Add($"public partial class {controllerName}Controller : GenericController<TContract, TModel>"); result.Add("{"); result.Add("}"); result.EnvelopeWithANamespace(CreateWebApiControllerNameSpace(type)); result.FormatCSharpCode(); return(result); }
public Contracts.IGeneratedItem CreateContract(Type type, IEnumerable <Type> types) { type.CheckArgument(nameof(type)); var subPath = CreateSubPathFromType(type); var entityName = CreateEntityNameFromInterface(type); var fileName = $"{ConvertFileName(entityName)}.{CodeExtension}"; var properties = ContractHelper.GetAllProperties(type); var declarationTypeName = string.Empty; var result = new Models.GeneratedItem(Common.UnitType.AngularApp, Common.ItemType.TypeScriptContract) { FullName = CreateTypeScriptFullName(type), FileExtension = CodeExtension, }; result.SubFilePath = Path.Combine(ProjectContractsPath, subPath, fileName); StartCreateContract(type, result.Source); result.Add($"export interface {entityName}" + " {"); foreach (var item in properties) { if (declarationTypeName.Equals(item.DeclaringType.Name) == false) { declarationTypeName = item.DeclaringType.Name; result.Add($"/** {declarationTypeName} **/"); } result.AddRange(CreateTypeScriptProperty(item)); } result.AddRange(CreateContactToContractFromContracts(type, types)); result.Add("}"); result.FormatCSharpCode(); result.Source.Insert(result.Source.Count - 1, StaticLiterals.AngularCustomCodeBeginLabel); result.Source.Insert(result.Source.Count - 1, StaticLiterals.AngularCustomCodeEndLabel); var imports = new List <string>(); imports.AddRange(CreateTypeImports(type)); imports.AddRange(CreateContactToContractImports(type, types)); imports.Add(StaticLiterals.AngularCustomImportBeginLabel); imports.Add(StaticLiterals.AngularCustomImportEndLabel); InsertTypeImports(imports, result.Source); FinishCreateContract(type, result.Source); return(result); }
private Contracts.IGeneratedItem CreateShadowController(Type type) { type.CheckArgument(nameof(type)); var entityName = CreateEntityNameFromInterface(type); var subNameSpace = CreateSubNamespaceFromType(type); var entityType = $"{StaticLiterals.EntitiesFolder}.{subNameSpace}.{entityName}"; var controllerName = $"{entityName}Controller"; var baseControllerName = "GenericShadowController"; var interfaceTypes = type.GetInterfaces(); var sourceGenericType = interfaceTypes.Single(e => e.IsGenericType && e.Name.Equals(StaticLiterals.IShadowName)).GetGenericArguments()[0]; var sourceEntityType = $"{CreateEntityFullNameFromInterface(sourceGenericType)}"; var sourceCtrlType = $"{CreateLogicControllerFullNameFromInterface(sourceGenericType)}"; var result = new Models.GeneratedItem(Common.UnitType.Logic, Common.ItemType.ShadowController) { FullName = CreateLogicControllerFullNameFromInterface(type), FileExtension = StaticLiterals.CSharpFileExtension, }; result.SubFilePath = $"{result.FullName}{result.FileExtension}"; ConvertGenericPersistenceControllerName(type, ref baseControllerName); CreateLogicControllerAttributes(type, result.Source); result.Add($"sealed partial class {controllerName} : {baseControllerName}<{type.FullName}, {entityType}, {sourceGenericType.FullName}, {sourceEntityType}>"); result.Add("{"); var initStatements = new List <string>() { $"sourceEntityController = new {sourceCtrlType}(this);", }; result.AddRange(CreatePartialStaticConstrutor(controllerName)); result.AddRange(CreatePartialConstrutor("public", controllerName, $"{SolutionProperties.DataContextFolder}.IContext context", "base(context)", initStatements)); result.AddRange(CreatePartialConstrutor("public", controllerName, "ControllerObject controller", "base(controller)", initStatements, false)); result.Add($"private {sourceCtrlType} sourceEntityController = null;"); result.Add($"protected override GenericController<{sourceGenericType.FullName}, {sourceEntityType}> SourceEntityController"); result.Add("{"); result.Add($"get => sourceEntityController; // ?? (sourceEntityController = new {sourceCtrlType}(this));"); result.Add($"set => sourceEntityController = value as {sourceCtrlType};"); result.Add("}"); result.Add("}"); result.EnvelopeWithANamespace(CreateLogicControllerNameSpace(type)); result.FormatCSharpCode(); return(result); }
private Contracts.IGeneratedItem CreateDelegateProperties(Type type, Type delegateType, string delegateObjectName, Common.UnitType unitType, Common.ItemType itemType) { type.CheckArgument(nameof(type)); delegateType.CheckArgument(nameof(delegateType)); var modelName = CreateModelNameFromInterface(type); var typeProperties = ContractHelper.GetAllProperties(delegateType); var result = new Models.GeneratedItem(unitType, itemType) { FullName = CreateModelFullNameFromInterface(type), FileExtension = StaticLiterals.CSharpFileExtension, }; result.SubFilePath = $"{result.FullName}{result.FileExtension}"; CreateModelAttributes(type, result.Source); result.Add($"public partial class {modelName}"); result.Add("{"); foreach (var item in ContractHelper.FilterPropertiesForGeneration(typeProperties)) { var propertyType = GetPropertyType(item); if (item.CanRead || item.CanWrite) { CreateModelPropertyAttributes(delegateType, item, result.Source); result.Add($"public {propertyType} {item.Name}"); result.Add("{"); if (item.CanRead) { result.Add($"get => {delegateObjectName}.{item.Name};"); } if (item.CanWrite) { result.Add($"set => {delegateObjectName}.{item.Name} = value;"); } result.Add("}"); } } result.Add("}"); result.EnvelopeWithANamespace(CreateModelsNamespace(type), "using System;"); result.FormatCSharpCode(); return(result); }
private Models.GeneratedItem CreateDbContext(string nameSpace) { var contractsProject = ContractsProject.Create(SolutionProperties); var result = new Models.GeneratedItem(Common.UnitType.Logic, Common.ItemType.DbContext) { FullName = $"{nameSpace}.{SolutionProperties.SolutionName}DbContext", FileExtension = StaticLiterals.CSharpFileExtension, }; result.SubFilePath = $"{result.FullName}PartA{result.FileExtension}"; result.Add($"namespace {nameSpace}"); result.Add("{"); result.Add("using Microsoft.EntityFrameworkCore;"); result.Add("using Microsoft.EntityFrameworkCore.Metadata.Builders;"); result.Add($"partial class {SolutionProperties.SolutionName}DbContext : GenericDbContext"); result.Add("{"); foreach (var type in contractsProject.PersistenceTypes) { string entityName = CreateEntityNameFromInterface(type); string subNameSpace = CreateSubNamespaceFromType(type); string entityNameSet = $"{entityName}Set"; result.Add($"protected DbSet<Entities.{subNameSpace}.{entityName}> {entityNameSet}" + " { get; set; }"); } result.AddRange(CreateSetMethode()); result.AddRange(CreateDoModelCreating()); result.Add("}"); if (nameSpace.HasContent()) { result.Add("}"); } result.AddRange(result.Source.Eject().FormatCSharpCode()); return(result); }
private Contracts.IGeneratedItem CreateCompositeBusinessController(Type type) { type.CheckArgument(nameof(type)); var entityName = CreateEntityNameFromInterface(type); var subNameSpace = CreateSubNamespaceFromType(type); var entityType = $"{StaticLiterals.EntitiesFolder}.{subNameSpace}.{entityName}"; var controllerName = $"{entityName}Controller"; var baseControllerName = "GenericCompositeController"; var interfaceTypes = type.GetInterfaces(); var connectorGenericType = interfaceTypes[0].GetGenericArguments()[0]; var oneGenericType = interfaceTypes[0].GetGenericArguments()[1]; var anotherGenericType = interfaceTypes[0].GetGenericArguments()[2]; var connectorEntityType = $"{CreateEntityFullNameFromInterface(connectorGenericType)}"; var oneEntityType = $"{CreateEntityFullNameFromInterface(oneGenericType)}"; var anotherEntityType = $"{CreateEntityFullNameFromInterface(anotherGenericType)}"; var connectorCtrlType = $"{CreateLogicControllerFullNameFromInterface(connectorGenericType)}"; var oneCtrlType = $"{CreateLogicControllerFullNameFromInterface(oneGenericType)}"; var anotherCtrlType = $"{CreateLogicControllerFullNameFromInterface(anotherGenericType)}"; var result = new Models.GeneratedItem(Common.UnitType.Logic, Common.ItemType.BusinessController) { FullName = CreateLogicControllerFullNameFromInterface(type), FileExtension = StaticLiterals.CSharpFileExtension, }; result.SubFilePath = $"{result.FullName}{result.FileExtension}"; ConvertGenericPersistenceControllerName(type, ref baseControllerName); CreateLogicControllerAttributes(type, result.Source); result.Add($"sealed partial class {controllerName} : {baseControllerName}<{type.FullName}, {entityType}, {connectorGenericType.FullName}, {connectorEntityType}, {oneGenericType.FullName}, {oneEntityType}, {anotherGenericType.FullName}, {anotherEntityType}>"); result.Add("{"); var initStatements = new List <string>() { $"connectorEntityController = new {connectorCtrlType}(this);", $"oneEntityController = new {oneCtrlType}(this);", $"anotherEntityController = new {anotherCtrlType}(this);", }; result.AddRange(CreatePartialStaticConstrutor(controllerName)); result.AddRange(CreatePartialConstrutor("public", controllerName, $"{SolutionProperties.DataContextFolder}.IContext context", "base(context)", initStatements)); result.AddRange(CreatePartialConstrutor("public", controllerName, "ControllerObject controller", "base(controller)", initStatements, false)); result.Add($"private {connectorCtrlType} connectorEntityController = null;"); result.Add($"protected override GenericController<{connectorGenericType.FullName}, {connectorEntityType}> ConnectorEntityController"); result.Add("{"); result.Add($"get => connectorEntityController; // ?? (connectorEntityController = new {connectorCtrlType}(this));"); result.Add($"set => connectorEntityController = value as {connectorCtrlType};"); result.Add("}"); result.Add($"private {oneCtrlType} oneEntityController = null;"); result.Add($"protected override GenericController<{oneGenericType.FullName}, {oneEntityType}> OneEntityController"); result.Add("{"); result.Add($"get => oneEntityController; // ?? (oneEntityController = new {oneCtrlType}(this));"); result.Add($"set => oneEntityController = value as {oneCtrlType};"); result.Add("}"); result.Add($"private {anotherCtrlType} anotherEntityController = null;"); result.Add($"protected override GenericController<{anotherGenericType.FullName}, {anotherEntityType}> AnotherEntityController"); result.Add("{"); result.Add($"get => anotherEntityController; // ?? (anotherEntityController = new {anotherCtrlType}(this));"); result.Add($"set => anotherEntityController = value as {anotherCtrlType};"); result.Add("}"); result.Add("}"); result.EnvelopeWithANamespace(CreateLogicControllerNameSpace(type)); result.FormatCSharpCode(); return(result); }
public Contracts.IGeneratedItem CreateLogicFactory() { var first = true; var contractsProject = ContractsProject.Create(SolutionProperties); var types = contractsProject.PersistenceTypes .Union(contractsProject.ShadowTypes) .Union(contractsProject.BusinessTypes); var result = new Models.GeneratedItem(Common.UnitType.Logic, Common.ItemType.Factory) { FullName = $"{LogicNameSpace}.Factory", FileExtension = StaticLiterals.CSharpFileExtension, }; result.SubFilePath = $"{result.FullName}{result.FileExtension}"; result.Add("public static partial class Factory"); result.Add("{"); result.Add("public static Contracts.Client.IControllerAccess<I> Create<I>() where I : Contracts.IIdentifiable"); result.Add("{"); result.Add("Contracts.Client.IControllerAccess<I> result;"); foreach (var type in types.Where(t => CanCreateLogicAccess(t))) { var entityName = CreateEntityNameFromInterface(type); var controllerNameSpace = $"Controllers.{CreateSubNamespaceFromType(type)}"; if (first) { result.Add($"if (typeof(I) == typeof({type.FullName}))"); } else { result.Add($"else if (typeof(I) == typeof({type.FullName}))"); } result.Add("{"); result.Add($"result = new {controllerNameSpace}.{entityName}Controller(CreateContext()) as Contracts.Client.IControllerAccess<I>;"); result.Add("}"); first = false; } result.Add("else"); result.Add("{"); result.Add("throw new Logic.Modules.Exception.LogicException(Modules.Exception.ErrorType.InvalidControllerType);"); result.Add("}"); result.Add("return result;"); result.Add("}"); result.Add("public static Contracts.Client.IControllerAccess<I> Create<I>(object sharedController) where I : Contracts.IIdentifiable"); result.Add("{"); result.Add("Contracts.Client.IControllerAccess<I> result;"); first = true; foreach (var type in types.Where(t => CanCreateLogicAccess(t))) { var entityName = CreateEntityNameFromInterface(type); var controllerNameSpace = $"Controllers.{CreateSubNamespaceFromType(type)}"; if (first) { result.Add($"if (typeof(I) == typeof({type.FullName}))"); } else { result.Add($"else if (typeof(I) == typeof({type.FullName}))"); } result.Add("{"); result.Add($"result = new {controllerNameSpace}.{entityName}Controller(sharedController as Controllers.ControllerObject) as Contracts.Client.IControllerAccess<I>;"); result.Add("}"); first = false; } result.Add("else"); result.Add("{"); result.Add("throw new Logic.Modules.Exception.LogicException(Modules.Exception.ErrorType.InvalidControllerType);"); result.Add("}"); result.Add("return result;"); result.Add("}"); result.Add("public static Contracts.Client.IControllerAccess<I> Create<I>(string sessionToken) where I : Contracts.IIdentifiable"); result.Add("{"); result.Add("Contracts.Client.IControllerAccess<I> result;"); first = true; foreach (var type in types.Where(t => CanCreateLogicAccess(t))) { var entityName = CreateEntityNameFromInterface(type); var controllerNameSpace = $"Controllers.{CreateSubNamespaceFromType(type)}"; if (first) { result.Add($"if (typeof(I) == typeof({type.FullName}))"); } else { result.Add($"else if (typeof(I) == typeof({type.FullName}))"); } result.Add("{"); result.Add($"result = new {controllerNameSpace}.{entityName}Controller(CreateContext()) " + "{ SessionToken = sessionToken } as Contracts.Client.IControllerAccess<I>;"); result.Add("}"); first = false; } result.Add("else"); result.Add("{"); result.Add("throw new Logic.Modules.Exception.LogicException(Modules.Exception.ErrorType.InvalidControllerType);"); result.Add("}"); result.Add("return result;"); result.Add("}"); result.Add("}"); result.AddRange(EnvelopeWithANamespace(result.Source.Eject(), LogicNameSpace)); result.AddRange(result.Source.Eject().FormatCSharpCode()); return(result); }
public Contracts.IGeneratedItem CreateAdapterFactory() { var first = true; var contractsProject = ContractsProject.Create(SolutionProperties); var types = contractsProject.PersistenceTypes .Union(contractsProject.ShadowTypes) .Union(contractsProject.BusinessTypes); var result = new Models.GeneratedItem(Common.UnitType.Adapters, Common.ItemType.Factory) { FullName = $"{AdapterNameSpace}.Factory", FileExtension = StaticLiterals.CSharpFileExtension, }; result.SubFilePath = $"{result.FullName}{result.FileExtension}"; result.Add("public static partial class Factory"); result.Add("{"); result.Add("public static Contracts.Client.IAdapterAccess<I> Create<I>()"); result.Add("{"); result.Add("Contracts.Client.IAdapterAccess<I> result = null;"); result.Add("if (Adapter == AdapterType.Controller)"); result.Add("{"); foreach (var type in types.Where(t => CanCreateLogicAccess(t) && CanCreateAdapterAccess(t))) { var entityName = CreateEntityNameFromInterface(type); var controllerNameSpace = CreateControllerNameSpace(type); if (first) { result.Add($"if (typeof(I) == typeof({type.FullName}))"); } else { result.Add($"else if (typeof(I) == typeof({type.FullName}))"); } result.Add("{"); result.Add($"result = new Controller.GenericControllerAdapter<{type.FullName}>() as Contracts.Client.IAdapterAccess<I>;"); result.Add("}"); first = false; } result.Add("}"); result.Add("else if (Adapter == AdapterType.Service)"); result.Add("{"); first = true; foreach (var type in types.Where(t => CanCreateLogicAccess(t) && CanCreateAdapterAccess(t))) { var modelName = CreateEntityNameFromInterface(type); var modelNameSpace = CreateTransferNameSpace(type); var extUri = modelName.EndsWith("s") ? $"{modelName}" : $"{modelName}s"; ConvertExtUri(type, ref extUri); if (first) { result.Add($"if (typeof(I) == typeof({type.FullName}))"); } else { result.Add($"else if (typeof(I) == typeof({type.FullName}))"); } result.Add("{"); result.Add($"result = new Service.GenericServiceAdapter<{type.FullName}, {modelNameSpace}.{modelName}>(BaseUri, \"{extUri}\")"); result.Add(" as Contracts.Client.IAdapterAccess<I>;"); result.Add("}"); first = false; } result.Add("}"); result.Add("return result;"); result.Add("}"); result.Add("public static Contracts.Client.IAdapterAccess<I> Create<I>(string sessionToken)"); result.Add("{"); result.Add("Contracts.Client.IAdapterAccess<I> result = null;"); result.Add("if (Adapter == AdapterType.Controller)"); result.Add("{"); first = true; foreach (var type in types.Where(t => CanCreateLogicAccess(t) && CanCreateAdapterAccess(t))) { var entityName = CreateEntityNameFromInterface(type); var controllerNameSpace = CreateControllerNameSpace(type); if (first) { result.Add($"if (typeof(I) == typeof({type.FullName}))"); } else { result.Add($"else if (typeof(I) == typeof({type.FullName}))"); } result.Add("{"); result.Add($"result = new Controller.GenericControllerAdapter<{type.FullName}>(sessionToken) as Contracts.Client.IAdapterAccess<I>;"); result.Add("}"); first = false; } result.Add("}"); result.Add("else if (Adapter == AdapterType.Service)"); result.Add("{"); first = true; foreach (var type in types.Where(t => CanCreateLogicAccess(t) && CanCreateAdapterAccess(t))) { var modelName = CreateEntityNameFromInterface(type); var modelNameSpace = CreateTransferNameSpace(type); var extUri = modelName.EndsWith("s") ? $"{modelName}" : $"{modelName}s"; ConvertExtUri(type, ref extUri); if (first) { result.Add($"if (typeof(I) == typeof({type.FullName}))"); } else { result.Add($"else if (typeof(I) == typeof({type.FullName}))"); } result.Add("{"); result.Add($"result = new Service.GenericServiceAdapter<{type.FullName}, {modelNameSpace}.{modelName}>(sessionToken, BaseUri, \"{extUri}\") as Contracts.Client.IAdapterAccess<I>;"); result.Add("}"); first = false; } result.Add("}"); result.Add("return result;"); result.Add("}"); result.Add("}"); result.AddRange(EnvelopeWithANamespace(result.Source.Eject(), AdapterNameSpace)); result.AddRange(result.Source.Eject().FormatCSharpCode()); return(result); }
/// <summary> /// Diese Methode erstellt den Programmcode der Beziehungen zwischen den Entitaeten aus den Schnittstellen-Typen. /// </summary> /// <param name="type">Der Schnittstellen-Typ.</param> /// <param name="types">Die Schnittstellen-Typen.</param> /// <param name="mapPropertyName">Ein Lambda-Ausdruck zum konvertieren des Eigenschaftsnamen.</param> /// <returns>Die Entitaet als Text.</returns> private Contracts.IGeneratedItem CreateEntityToEntityFromContracts(Type type, IEnumerable <Type> types) { type.CheckArgument(nameof(type)); types.CheckArgument(nameof(types)); var typeName = CreateEntityNameFromInterface(type); var result = new Models.GeneratedItem(Common.UnitType.Logic, Common.ItemType.PersistenceEntity) { FullName = CreateEntityFullNameFromInterface(type), FileExtension = StaticLiterals.CSharpFileExtension, }; result.SubFilePath = $"{result.FullName}PartB{result.FileExtension}"; result.Add($"partial class {typeName}"); result.Add("{"); foreach (var other in types) { var otherHelper = new ContractHelper(other); if (otherHelper.ContextType != CommonBase.Attributes.ContextType.View) { var otherName = GeneratorObject.CreateEntityNameFromInterface(other); foreach (var pi in other.GetProperties()) { if (pi.Name.Equals($"{typeName}Id")) { var otherFullName = GeneratorObject.CreateEntityFullNameFromInterface(other); var navigationName = $"{otherName}s"; result.Add(($"public System.Collections.Generic.ICollection<{otherFullName}> {navigationName} " + "{ get; set; }")); } } } } var interfaces = new List <Type>(); var typeInterface = GetTypeInterface(type); interfaces.Add(type); foreach (var item in GeneratorObject.GetInterfaces(type) .Where(t => t != typeInterface)) { interfaces.Add(item); } foreach (var item in interfaces) { foreach (var pi in item.GetProperties()) { foreach (var other in types) { var otherHelper = new ContractHelper(other); if (otherHelper.ContextType != CommonBase.Attributes.ContextType.View) { var otherName = GeneratorObject.CreateEntityNameFromInterface(other); if (pi.Name.Equals($"{otherName}Id")) { var propHelper = new ContractPropertyHelper(pi); var otherFullName = GeneratorObject.CreateEntityFullNameFromInterface(other); var navigationName = propHelper.NavigationName.GetValueOrDefault(otherName); result.Add(($"[System.ComponentModel.DataAnnotations.Schema.ForeignKey(\"{pi.Name}\")]")); result.Add(($"public {otherFullName} {navigationName} " + "{ get; set; }")); } else if (pi.Name.StartsWith($"{otherName}Id_")) { var data = pi.Name.Split("_"); if (data.Length == 2) { var otherFullName = GeneratorObject.CreateEntityFullNameFromInterface(other); result.Add(($"[System.ComponentModel.DataAnnotations.Schema.ForeignKey(\"{pi.Name}\")]")); result.Add(($"public {otherFullName} {data[1]} " + "{ get; set; }")); } } } } } } result.Add("}"); result.EnvelopeWithANamespace(CreateNameSpace(type)); result.FormatCSharpCode(); return(result); }
private Models.GeneratedItem CreateTranslations(string separator) { var translations = new List <string>(); var contractsProject = ContractsProject.Create(SolutionProperties); var result = new Models.GeneratedItem(Common.UnitType.General, Common.ItemType.Translations) { FullName = $"Translations", FileExtension = ".csv", }; result.SubFilePath = $"{result.FullName}{result.FileExtension}"; result.Add($"AppName{separator}KeyLanguage{separator}Key{separator}ValueLanguage{separator}Value"); var key = string.Empty; var types = contractsProject.PersistenceTypes .Union(contractsProject.BusinessTypes) .Union(contractsProject.ModuleTypes) .Union(contractsProject.ShadowTypes); var properties = types.SelectMany(t => t.GetAllPropertyInfos()) .GroupBy(p => p.Name) .Select(g => g.FirstOrDefault()); translations.Add($"{SolutionProperties.SolutionName}{separator}En{separator}NewRef{separator}De{separator}New"); translations.Add($"{SolutionProperties.SolutionName}{separator}En{separator}ViewRef{separator}De{separator}View"); translations.Add($"{SolutionProperties.SolutionName}{separator}En{separator}EditRef{separator}De{separator}Edit"); translations.Add($"{SolutionProperties.SolutionName}{separator}En{separator}DeleteRef{separator}De{separator}Delete"); translations.Add($"{SolutionProperties.SolutionName}{separator}En{separator}Reload{separator}De{separator}Reload"); translations.Add($"{SolutionProperties.SolutionName}{separator}En{separator}Cancel{separator}De{separator}Cancel"); translations.Add($"{SolutionProperties.SolutionName}{separator}En{separator}Confirm{separator}De{separator}Confirm"); translations.Add($"{SolutionProperties.SolutionName}{separator}En{separator}Submit{separator}De{separator}Submit"); translations.Add($"{SolutionProperties.SolutionName}{separator}En{separator}SubmitClose{separator}De{separator}SubmitClose"); foreach (var item in types) { var entityName = CreateEntityNameFromInterface(item); translations.Add($"{SolutionProperties.SolutionName}{separator}En{separator}{entityName}MasterComponent.{separator}De{separator}"); translations.Add($"{SolutionProperties.SolutionName}{separator}En{separator}{entityName}DetailsComponent.{separator}De{separator}"); } foreach (var item in properties.OrderBy(p => p.Name)) { key = $"{item.Name}"; translations.Add($"{SolutionProperties.SolutionName}{separator}En{separator}{key}{separator}De{separator}{item.Name}"); } key = "LoginMenu"; translations.Add($"{SolutionProperties.SolutionName}{separator}En{separator}{key}.Access-Authorization{separator}De{separator}Access-Authorization"); translations.Add($"{SolutionProperties.SolutionName}{separator}En{separator}{key}.Identity-User{separator}De{separator}Identity-User"); translations.Add($"{SolutionProperties.SolutionName}{separator}En{separator}{key}.Role-Management{separator}De{separator}Role-Management"); translations.Add($"{SolutionProperties.SolutionName}{separator}En{separator}{key}.Change password{separator}De{separator}Change password"); translations.Add($"{SolutionProperties.SolutionName}{separator}En{separator}{key}.Reset password{separator}De{separator}Reset password"); translations.Add($"{SolutionProperties.SolutionName}{separator}En{separator}{key}.Translation{separator}De{separator}Translation"); translations.Add($"{SolutionProperties.SolutionName}{separator}En{separator}{key}.Settings{separator}De{separator}Settings"); translations.Add($"{SolutionProperties.SolutionName}{separator}En{separator}{key}.Logout{separator}De{separator}Logout"); foreach (var type in types.OrderBy(t => t.Name)) { var entityName = CreateEntityNameFromInterface(type); key = $"{entityName}"; translations.Add($"{SolutionProperties.SolutionName}{separator}En{separator}{key}.TitelDetails{separator}De{separator}TitelDetails"); translations.Add($"{SolutionProperties.SolutionName}{separator}En{separator}{key}.TitleEditModel{separator}De{separator}TitleEditModel"); translations.Add($"{SolutionProperties.SolutionName}{separator}En{separator}{key}.TitleConfirmDelete{separator}De{separator}TitleConfirmDelete"); } result.Source.AddRange(translations.Distinct()); return(result); }