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);
        }
        private Contracts.IGeneratedItem CreateOneToManyBusinessController(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 = "GenericOneToManyController";
            var interfaceTypes     = type.GetInterfaces();
            var oneGenericType     = interfaceTypes[0].GetGenericArguments()[0];
            var manyGenericType    = interfaceTypes[0].GetGenericArguments()[1];
            var oneEntityType      = $"{CreateEntityFullNameFromInterface(oneGenericType)}";
            var manyEntityType     = $"{CreateEntityFullNameFromInterface(manyGenericType)}";
            var oneCtrlType        = $"{CreateLogicControllerFullNameFromInterface(oneGenericType)}";
            var manyCtrlType       = $"{CreateLogicControllerFullNameFromInterface(manyGenericType)}";
            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}, {oneGenericType.FullName}, {oneEntityType}, {manyGenericType.FullName}, {manyEntityType}>");
            result.Add("{");

            var initStatements = new List <string>()
            {
                $"oneEntityController = new {oneCtrlType}(this);",
                $"manyEntityController = new {manyCtrlType}(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 {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 {manyCtrlType} manyEntityController = null;");
            result.Add($"protected override GenericController<{manyGenericType.FullName}, {manyEntityType}> ManyEntityController");
            result.Add("{");
            result.Add($"get => manyEntityController; // ?? (manyEntityController = new {manyCtrlType}(this));");
            result.Add($"set => manyEntityController = value as {manyCtrlType};");
            result.Add("}");

            result.Add("}");
            result.EnvelopeWithANamespace(CreateLogicControllerNameSpace(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);
        }
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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 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);
        }
예제 #9
0
        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);
        }
예제 #10
0
        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);
        }