Exemple #1
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 => CanCreate(nameof(CreateLogicFactory), 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 => CanCreate(nameof(CreateLogicFactory), 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("}");
            return(EnvelopeWithANamespace(result, LogicNameSpace));
        }
Exemple #2
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>() where I : Contracts.IIdentifiable");
            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 => CanCreate(nameof(CreateAdapterFactory), 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 => CanCreate(nameof(CreateAdapterFactory), 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}\") as Contracts.Client.IAdapterAccess<I>;");
                result.Add("}");
                first = false;
            }
            result.Add("}");
            result.Add("return result;");
            result.Add("}");
            result.Add("}");
            return(EnvelopeWithANamespace(result, AdapterNameSpace));
        }
Exemple #3
0
        public static ContractsProject Create(SolutionProperties solutionProperties)
        {
            solutionProperties.CheckArgument(nameof(solutionProperties));

            ContractsProject result = new ContractsProject();

            result.SolutionProperties = solutionProperties;
            return(result);
        }
        public IEnumerable <string> CreateBusinessControllers()
        {
            List <string>    result           = new List <string>();
            ContractsProject contractsProject = ContractsProject.Create(SolutionProperties);

            foreach (var type in contractsProject.BusinessTypes)
            {
                if (CanCreate(nameof(CreateBusinessControllers), type))
                {
                    result.AddRange(EnvelopeWithANamespace(CreateBusinessController(type), CreateLogicControllerNameSpace(type)));
                }
            }
            return(result);
        }
        public IEnumerable <string> CreateModulesEntities()
        {
            List <string>    result           = new List <string>();
            ContractsProject contractsProject = ContractsProject.Create(SolutionProperties);

            foreach (var type in contractsProject.ModuleTypes)
            {
                if (CanCreateEntity(type))
                {
                    result.AddRange(EnvelopeWithANamespace(CreateEntityFromInterface(type), CreateNameSpace(type), "using System;"));
                    result.AddRange(EnvelopeWithANamespace(CreateModuleEntity(type), CreateNameSpace(type)));
                }
            }
            return(result);
        }
        public IEnumerable <string> CreateBusinessTransfers()
        {
            List <string>    result           = new List <string>();
            ContractsProject contractsProject = ContractsProject.Create(SolutionProperties);

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

            foreach (var type in contractsProject.BusinessTypes)
            {
                if (CanCreate(type))
                {
                    result.AddRange(EnvelopeWithANamespace(CreateModelFromInterface(type), CreateNameSpace(type)));
                    result.AddRange(EnvelopeWithANamespace(CreateBusinessModel(type), CreateNameSpace(type)));
                }
            }
            return(result);
        }
Exemple #8
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);
        }