예제 #1
0
        public IEnumerable <string> CreateWebApiControllers()
        {
            List <string>    result           = new List <string>();
            ContractsProject contractsProject = ContractsProject.Create(SolutionProperties);
            var types = contractsProject.PersistenceTypes.Union(contractsProject.BusinessTypes);

            foreach (var type in types)
            {
                if (CanCreate(nameof(CreateWebApiControllers), type))
                {
                    result.AddRange(EnvelopeWithANamespace(CreateWebApiController(type), CreateWebApiNameSpace(type)));
                }
            }
            return(result);
        }
        public IEnumerable <string> CreatePersistenceTransfers()
        {
            List <string>    result           = new List <string>();
            ContractsProject contractsProject = ContractsProject.Create(SolutionProperties);

            foreach (var type in contractsProject.PersistenceTypes)
            {
                if (CanCreate(type))
                {
                    result.AddRange(EnvelopeWithANamespace(CreateTransferFromInterface(type), CreateNameSpace(type), "using System.Text.Json.Serialization;"));
                    result.AddRange(EnvelopeWithANamespace(CreatePersistenceTransfer(type), CreateNameSpace(type)));
                }
            }
            return(result);
        }
        public IEnumerable <string> CreateModulesModels()
        {
            List <string>    result           = new List <string>();
            ContractsProject contractsProject = ContractsProject.Create(SolutionProperties);

            foreach (var type in contractsProject.ModuleTypes)
            {
                if (CanCreate(type))
                {
                    result.AddRange(EnvelopeWithANamespace(CreateModelFromInterface(type), CreateNameSpace(type)));
                    result.AddRange(EnvelopeWithANamespace(CreateModuleModel(type), CreateNameSpace(type)));
                }
            }
            return(result);
        }
        public IEnumerable <string> CreateBusinesssEntities()
        {
            List <string>    result           = new List <string>();
            ContractsProject contractsProject = ContractsProject.Create(SolutionProperties);

            foreach (var type in contractsProject.BusinessTypes)
            {
                if (CanCreateEntity(type))
                {
                    result.AddRange(EnvelopeWithANamespace(CreateEntityFromInterface(type), CreateNameSpace(type), "using System;"));
                    result.AddRange(EnvelopeWithANamespace(CreateBusinessEntity(type), CreateNameSpace(type)));
                }
            }
            return(result);
        }
예제 #5
0
        public IEnumerable <string> CreatePersistenceEntities()
        {
            List <string>    result           = new List <string>();
            ContractsProject contractsProject = ContractsProject.Create(SolutionProperties);
            var persistenceTypes = contractsProject.PersistenceTypes;

            foreach (var type in persistenceTypes)
            {
                if (CanCreate(type))
                {
                    string nameSpace = CreateNameSpace(type);

                    result.AddRange(EnvelopeWithANamespace(CreateEntityFromInterface(type), nameSpace, "using System;"));
                    result.AddRange(EnvelopeWithANamespace(CreatePersistenceEntity(type), nameSpace));
                    result.AddRange(EnvelopeWithANamespace(CreateEntityToEntityFromContracts(type, persistenceTypes, null), nameSpace));
                }
            }
            return(result);
        }
        public IEnumerable <string> CreateDbContext(string nameSpace)
        {
            List <string>    result           = new List <string>();
            bool             first            = true;
            ContractsProject contractsProject = ContractsProject.Create(SolutionProperties);

            if (nameSpace.HasContent())
            {
                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  = GetSubNamespaceFromInterface(type);
                string entityNameSet = $"{entityName}Set";

                result.Add($"protected DbSet<Entities.{subNameSpace}.{entityName}> {entityNameSet}" + " { get; set; }");
            }

            result.Add("public override DbSet<E> Set<I, E>()");
            result.Add("{");
            result.Add("DbSet<E> result = null;");

            foreach (var type in contractsProject.PersistenceTypes)
            {
                string entityName    = CreateEntityNameFromInterface(type);
                string entityNameSet = $"{entityName}Set";

                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 = {entityNameSet} as DbSet<E>;");
                result.Add("}");
                first = false;
            }
            result.Add("return result;");
            result.Add("}");

            if (CanModelCreating())
            {
                result.Add("partial void DoModelCreating(ModelBuilder modelBuilder)");
                result.Add("{");
                foreach (var type in contractsProject.PersistenceTypes)
                {
                    string entityName      = CreateEntityNameFromInterface(type);
                    string subNameSpace    = GetSubNamespaceFromInterface(type);
                    string entityNameSpace = $"{SolutionProperties.EntitiesFolder}.{subNameSpace}";
                    string entityType      = $"{entityNameSpace}.{entityName}";

                    result.Add($"modelBuilder.Entity<{entityType}>()");
                    result.Add($".ToTable(nameof({entityType}), nameof({entityNameSpace}))");
                    result.Add($".HasKey(nameof({entityType}.Id));");
                    result.Add($"modelBuilder.Entity<{entityType}>().Property(p => p.Timestamp).IsRowVersion();");
                    result.Add($"ConfigureEntityType(modelBuilder.Entity<{entityType}>());");
                }
                result.Add("}");
                foreach (var type in contractsProject.PersistenceTypes)
                {
                    string entityName      = CreateEntityNameFromInterface(type);
                    string subNameSpace    = GetSubNamespaceFromInterface(type);
                    string entityNameSpace = $"{SolutionProperties.EntitiesFolder}.{subNameSpace}";
                    string entityType      = $"{entityNameSpace}.{entityName}";

                    result.Add($"partial void ConfigureEntityType(EntityTypeBuilder<{entityType}> entityTypeBuilder);");
                }
            }

            result.Add("}");
            if (nameSpace.HasContent())
            {
                result.Add("}");
            }
            return(result);
        }
예제 #7
0
        public IEnumerable <string> CreateLogicFactory()
        {
            List <string>    result           = new List <string>();
            ContractsProject contractsProject = ContractsProject.Create(SolutionProperties);
            var types = contractsProject.PersistenceTypes.Union(contractsProject.BusinessTypes);
            var first = true;

            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 = null;");
            foreach (var type in types.Where(t => CanCreateLogicAccess(t)))
            {
                string entityName          = CreateEntityNameFromInterface(type);
                string controllerNameSpace = $"Controllers.{GetSubNamespaceFromInterface(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("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 = null;");
            first = true;
            foreach (var type in types.Where(t => CanCreateLogicAccess(t)))
            {
                string entityName          = CreateEntityNameFromInterface(type);
                string controllerNameSpace = $"Controllers.{GetSubNamespaceFromInterface(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("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 = null;");
            first = true;
            foreach (var type in types.Where(t => CanCreateLogicAccess(t)))
            {
                string entityName          = CreateEntityNameFromInterface(type);
                string controllerNameSpace = $"Controllers.{GetSubNamespaceFromInterface(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("return result;");
            result.Add("}");
            result.Add("}");

            return(EnvelopeWithANamespace(result, LogicNameSpace));
        }
예제 #8
0
        public IEnumerable <string> CreateAdapterFactory()
        {
            List <string>    result           = new List <string>();
            ContractsProject contractsProject = ContractsProject.Create(SolutionProperties);
            var types = contractsProject.PersistenceTypes.Union(contractsProject.BusinessTypes);
            var first = true;

            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)))
            {
                string entityName          = CreateEntityNameFromInterface(type);
                string 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)))
            {
                string modelName      = CreateEntityNameFromInterface(type);
                string modelNameSpace = CreateTransferNameSpace(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 Service.GenericServiceAdapter<{type.FullName}, {modelNameSpace}.{modelName}>(BaseUri, \"{modelName}\")");
                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)))
            {
                string entityName          = CreateEntityNameFromInterface(type);
                string 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)))
            {
                string modelName      = CreateEntityNameFromInterface(type);
                string modelNameSpace = CreateTransferNameSpace(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 Service.GenericServiceAdapter<{type.FullName}, {modelNameSpace}.{modelName}>(sessionToken, BaseUri, \"{modelName}\") as Contracts.Client.IAdapterAccess<I>;");
                result.Add("}");
                first = false;
            }
            result.Add("}");
            result.Add("return result;");
            result.Add("}");

            result.Add("}");
            return(EnvelopeWithANamespace(result, AdapterNameSpace));
        }