Esempio n. 1
0
        public static void CreateEntity(string solutionDirectory, Entity entity, IFileSystem fileSystem)
        {
            try
            {
                var classPath = ClassPathHelper.EntityClassPath(solutionDirectory, $"{entity.Name}.cs");

                if (!fileSystem.Directory.Exists(classPath.ClassDirectory))
                {
                    fileSystem.Directory.CreateDirectory(classPath.ClassDirectory);
                }

                if (fileSystem.File.Exists(classPath.FullClassPath))
                {
                    throw new FileAlreadyExistsException(classPath.FullClassPath);
                }

                using (var fs = fileSystem.File.Create(classPath.FullClassPath))
                {
                    var data = GetEntityFileText(classPath.ClassNamespace, entity);
                    fs.Write(Encoding.UTF8.GetBytes(data));
                }

                GlobalSingleton.AddCreatedFile(classPath.FullClassPath.Replace($"{solutionDirectory}{fileSystem.Path.DirectorySeparatorChar}", ""));
            }
            catch (FileAlreadyExistsException e)
            {
                WriteError(e.Message);
                throw;
            }
            catch (Exception e)
            {
                WriteError($"An unhandled exception occurred when running the API command.\nThe error details are: \n{e.Message}");
                throw;
            }
        }
Esempio n. 2
0
        public static void CreateController(string solutionDirectory, Entity entity, bool AddSwaggerComments)
        {
            try
            {
                var classPath = ClassPathHelper.ControllerClassPath(solutionDirectory, $"{Utilities.GetControllerName(entity.Plural)}.cs");

                if (!Directory.Exists(classPath.ClassDirectory))
                {
                    Directory.CreateDirectory(classPath.ClassDirectory);
                }

                if (File.Exists(classPath.FullClassPath))
                {
                    throw new FileAlreadyExistsException(classPath.FullClassPath);
                }

                using (FileStream fs = File.Create(classPath.FullClassPath))
                {
                    var data = GetControllerFileText(classPath.ClassNamespace, entity, AddSwaggerComments);
                    fs.Write(Encoding.UTF8.GetBytes(data));
                }

                GlobalSingleton.AddCreatedFile(classPath.FullClassPath.Replace($"{solutionDirectory}{Path.DirectorySeparatorChar}", ""));
            }
            catch (FileAlreadyExistsException e)
            {
                WriteError(e.Message);
                throw;
            }
            catch (Exception e)
            {
                WriteError($"An unhandled exception occurred when running the API command.\nThe error details are: \n{e.Message}");
                throw;
            }
        }
Esempio n. 3
0
        public static void CreateWebAppFactory(string solutionDirectory, ApiTemplate template, Entity entity)
        {
            try
            {
                var classPath = ClassPathHelper.TestWebAppFactoryClassPath(solutionDirectory, $"CustomWebApplicationFactory.cs", template.SolutionName);

                if (!Directory.Exists(classPath.ClassDirectory))
                {
                    Directory.CreateDirectory(classPath.ClassDirectory);
                }

                if (File.Exists(classPath.FullClassPath))
                {
                    File.Delete(classPath.FullClassPath); // saves me from having to make a remover!
                }
                using (FileStream fs = File.Create(classPath.FullClassPath))
                {
                    var data = GetWebAppFactoryFileText(classPath, template, entity);
                    fs.Write(Encoding.UTF8.GetBytes(data));
                }

                GlobalSingleton.AddCreatedFile(classPath.FullClassPath.Replace($"{solutionDirectory}{Path.DirectorySeparatorChar}", ""));
            }
            catch (FileAlreadyExistsException e)
            {
                WriteError(e.Message);
                throw;
            }
            catch (Exception e)
            {
                WriteError($"An unhandled exception occurred when running the API command.\nThe error details are: \n{e.Message}");
                throw;
            }
        }
Esempio n. 4
0
        public static void CreateGitIgnore(string solutionDirectory)
        {
            try
            {
                var filePath = Path.Combine(solutionDirectory, ".gitignore");

                if (File.Exists(filePath))
                {
                    throw new FileAlreadyExistsException(filePath);
                }

                using (FileStream fs = File.Create(filePath))
                {
                    var data = "";
                    data = GetGitIgnoreFileText();
                    fs.Write(Encoding.UTF8.GetBytes(data));
                }

                GlobalSingleton.AddCreatedFile(filePath.Replace($"{solutionDirectory}{Path.DirectorySeparatorChar}", ""));
            }
            catch (FileAlreadyExistsException e)
            {
                WriteError(e.Message);
                throw;
            }
            catch (Exception e)
            {
                WriteError($"An unhandled exception occurred when running the API command.\nThe error details are: \n{e.Message}");
                throw;
            }
        }
Esempio n. 5
0
        public static void DeleteEntityWriteTests(string solutionDirectory, Entity entity, string solutionName, string dbContextName)
        {
            try
            {
                var classPath = ClassPathHelper.TestRepositoryClassPath(solutionDirectory, $"Delete{entity.Name}RepositoryTests.cs", entity.Name, solutionName);

                if (!Directory.Exists(classPath.ClassDirectory))
                {
                    Directory.CreateDirectory(classPath.ClassDirectory);
                }

                if (File.Exists(classPath.FullClassPath))
                {
                    throw new FileAlreadyExistsException(classPath.FullClassPath);
                }

                using (FileStream fs = File.Create(classPath.FullClassPath))
                {
                    var data = DeleteRepositoryTestFileText(classPath, entity, solutionName, dbContextName);
                    fs.Write(Encoding.UTF8.GetBytes(data));
                }

                GlobalSingleton.AddCreatedFile(classPath.FullClassPath.Replace($"{solutionDirectory}{Path.DirectorySeparatorChar}", ""));
            }
            catch (FileAlreadyExistsException e)
            {
                WriteError(e.Message);
                throw;
            }
            catch (Exception e)
            {
                WriteError($"An unhandled exception occurred when running the API command.\nThe error details are: \n{e.Message}");
                throw;
            }
        }
Esempio n. 6
0
        public static void Create(string solutionDirectory, string solutionName)
        {
            try
            {
                var classPath = ClassPathHelper.HttpClientExtensionsClassPath(solutionDirectory, solutionName, $"HttpClientExtensions.cs");

                if (!Directory.Exists(classPath.ClassDirectory))
                {
                    Directory.CreateDirectory(classPath.ClassDirectory);
                }

                if (File.Exists(classPath.FullClassPath))
                {
                    File.Delete(classPath.FullClassPath); // saves me from having to make a remover!
                }
                using (FileStream fs = File.Create(classPath.FullClassPath))
                {
                    var data = CreateHttpClientExtensionsText(classPath);
                    fs.Write(Encoding.UTF8.GetBytes(data));
                }

                GlobalSingleton.AddCreatedFile(classPath.FullClassPath.Replace($"{solutionDirectory}{Path.DirectorySeparatorChar}", ""));
            }
            catch (FileAlreadyExistsException e)
            {
                WriteError(e.Message);
                throw;
            }
            catch (Exception e)
            {
                WriteError($"An unhandled exception occurred when running the API command.\nThe error details are: \n{e.Message}");
                throw;
            }
        }
Esempio n. 7
0
        private static void CreateFakerFile(string solutionDirectory, string objectToFakeClassName, Entity entity, ApiTemplate template)
        {
            var fakeFilename = $"Fake{objectToFakeClassName}.cs";
            var classPath    = ClassPathHelper.TestFakesClassPath(solutionDirectory, fakeFilename, entity.Name, template.SolutionName);

            if (File.Exists(classPath.FullClassPath))
            {
                throw new FileAlreadyExistsException(classPath.FullClassPath);
            }

            using (FileStream fs = File.Create(classPath.FullClassPath))
            {
                var data = GetFakeFileText(classPath.ClassNamespace, objectToFakeClassName, entity);
                fs.Write(Encoding.UTF8.GetBytes(data));

                GlobalSingleton.AddCreatedFile(classPath.FullClassPath.Replace($"{solutionDirectory}{Path.DirectorySeparatorChar}", ""));
            }
        }
Esempio n. 8
0
        public static void CreateDtoFile(string solutionDirectory, Entity entity, Dto dto)
        {
            var dtoFileName = $"{Utilities.GetDtoName(entity.Name, dto)}.cs";
            var classPath   = ClassPathHelper.DtoClassPath(solutionDirectory, dtoFileName, entity.Name);

            if (File.Exists(classPath.FullClassPath))
            {
                throw new FileAlreadyExistsException(classPath.FullClassPath);
            }

            using (FileStream fs = File.Create(classPath.FullClassPath))
            {
                var data = GetDtoFileText(classPath, entity, dto);
                fs.Write(Encoding.UTF8.GetBytes(data));

                GlobalSingleton.AddCreatedFile(classPath.FullClassPath.Replace($"{solutionDirectory}{Path.DirectorySeparatorChar}", ""));
            }
        }
Esempio n. 9
0
        public static void AddSeeders(string solutionDirectory, ApiTemplate template)
        {
            try
            {
                if (template.AuthSetup.InMemoryUsers != null)
                {
                    foreach (var user in template.AuthSetup.InMemoryUsers)
                    {
                        var classPath = ClassPathHelper.IdentitySeederClassPath(solutionDirectory, $"{Utilities.GetIdentitySeederName(user)}.cs");

                        if (!Directory.Exists(classPath.ClassDirectory))
                        {
                            Directory.CreateDirectory(classPath.ClassDirectory);
                        }

                        if (File.Exists(classPath.FullClassPath))
                        {
                            throw new FileAlreadyExistsException(classPath.FullClassPath);
                        }

                        using (FileStream fs = File.Create(classPath.FullClassPath))
                        {
                            var data = SeederFunctions.GetIdentitySeederFileText(classPath.ClassNamespace, user);
                            fs.Write(Encoding.UTF8.GetBytes(data));
                        }

                        GlobalSingleton.AddCreatedFile(classPath.FullClassPath.Replace($"{solutionDirectory}{Path.DirectorySeparatorChar}", ""));
                    }
                }

                //Confirm all seeder registrations done in startup, if not, do here?
            }
            catch (FileAlreadyExistsException e)
            {
                WriteError(e.Message);
                throw;
            }
            catch (Exception e)
            {
                WriteError($"An unhandled exception occured when running the API command.\nThe error details are: \n{e.Message}");
                throw;
            }
        }
Esempio n. 10
0
        public static void AddSeeders(string solutionDirectory, ApiTemplate template)
        {
            try
            {
                foreach (var entity in template.Entities)
                {
                    var classPath = ClassPathHelper.SeederClassPath(solutionDirectory, $"{Utilities.GetSeederName(entity)}.cs");

                    if (!Directory.Exists(classPath.ClassDirectory))
                    {
                        Directory.CreateDirectory(classPath.ClassDirectory);
                    }

                    if (File.Exists(classPath.FullClassPath))
                    {
                        throw new FileAlreadyExistsException(classPath.FullClassPath);
                    }

                    using (FileStream fs = File.Create(classPath.FullClassPath))
                    {
                        var data = SeederFunctions.GetEntitySeederFileText(classPath.ClassNamespace, entity, template);
                        fs.Write(Encoding.UTF8.GetBytes(data));
                    }

                    GlobalSingleton.AddCreatedFile(classPath.FullClassPath.Replace($"{solutionDirectory}{Path.DirectorySeparatorChar}", ""));
                }

                RegisterAllSeeders(solutionDirectory, template);
            }
            catch (FileAlreadyExistsException e)
            {
                WriteError(e.Message);
                throw;
            }
            catch (Exception e)
            {
                WriteError($"An unhandled exception occurred when running the API command.\nThe error details are: \n{e.Message}");
                throw;
            }
        }
Esempio n. 11
0
        private static void CreateIRepositoryClass(string solutionDirectory, Entity entity)
        {
            var classPath = ClassPathHelper.IRepositoryClassPath(solutionDirectory, $"{Utilities.GetRepositoryName(entity.Name, true)}.cs", entity.Name);

            if (!Directory.Exists(classPath.ClassDirectory))
            {
                Directory.CreateDirectory(classPath.ClassDirectory);
            }

            if (File.Exists(classPath.FullClassPath))
            {
                throw new FileAlreadyExistsException(classPath.FullClassPath);
            }

            using (FileStream fs = File.Create(classPath.FullClassPath))
            {
                var data = GetIRepositoryFileText(classPath.ClassNamespace, entity);
                fs.Write(Encoding.UTF8.GetBytes(data));
            }

            GlobalSingleton.AddCreatedFile(classPath.FullClassPath.Replace($"{solutionDirectory}{Path.DirectorySeparatorChar}", ""));
        }
Esempio n. 12
0
        private static void BuildValidatorClass(string solutionDirectory, Entity entity, Validator validator)
        {
            var classPath = ClassPathHelper.ValidationClassPath(solutionDirectory, $"{Utilities.ValidatorNameGenerator(entity.Name, validator)}.cs", entity.Name);

            if (!Directory.Exists(classPath.ClassDirectory))
            {
                Directory.CreateDirectory(classPath.ClassDirectory);
            }

            if (File.Exists(classPath.FullClassPath))
            {
                throw new FileAlreadyExistsException(classPath.FullClassPath);
            }

            using (FileStream fs = File.Create(classPath.FullClassPath))
            {
                var data = "";
                if (validator == Validator.Creation)
                {
                    data = GetCreationValidatorFileText(classPath.ClassNamespace, entity);
                }
                else if (validator == Validator.Update)
                {
                    data = GetUpdateValidatorFileText(classPath.ClassNamespace, entity);
                }
                else if (validator == Validator.Manipulation)
                {
                    data = GetManipulationValidatorFileText(classPath.ClassNamespace, entity);
                }
                else
                {
                    throw new Exception("Unrecognized validator exception."); // this shouldn't really be possible, so not adding a special validator, but putting here for good measure
                }
                fs.Write(Encoding.UTF8.GetBytes(data));
            }

            GlobalSingleton.AddCreatedFile(classPath.FullClassPath.Replace($"{solutionDirectory}{Path.DirectorySeparatorChar}", ""));
        }
Esempio n. 13
0
        /// <summary>
        /// this build will only do a skeleton app settings for the initial project build.
        /// </summary>
        /// <param name="solutionDirectory"></param>
        public static void CreateAppSettings(string solutionDirectory)
        {
            try
            {
                var appSettingFilename = "appsettings.json";
                var classPath          = ClassPathHelper.AppSettingsClassPath(solutionDirectory, $"{appSettingFilename}");

                if (!Directory.Exists(classPath.ClassDirectory))
                {
                    Directory.CreateDirectory(classPath.ClassDirectory);
                }

                if (File.Exists(classPath.FullClassPath))
                {
                    File.Delete(classPath.FullClassPath);
                }

                using (FileStream fs = File.Create(classPath.FullClassPath))
                {
                    var data = "";
                    data = GetAppSettingsText();
                    fs.Write(Encoding.UTF8.GetBytes(data));
                }

                GlobalSingleton.AddCreatedFile(classPath.FullClassPath.Replace($"{solutionDirectory}{Path.DirectorySeparatorChar}", ""));
            }
            catch (FileAlreadyExistsException e)
            {
                WriteError(e.Message);
                throw;
            }
            catch (Exception e)
            {
                WriteError($"An unhandled exception occurred when running the API command.\nThe error details are: \n{e.Message}");
                throw;
            }
        }
Esempio n. 14
0
        public static void CreateDbContext(string solutionDirectory, ApiTemplate template)
        {
            try
            {
                var classPath = ClassPathHelper.DbContextClassPath(solutionDirectory, $"{template.DbContext.ContextName}.cs");

                if (!Directory.Exists(classPath.ClassDirectory))
                {
                    Directory.CreateDirectory(classPath.ClassDirectory);
                }

                if (File.Exists(classPath.FullClassPath))
                {
                    throw new FileAlreadyExistsException(classPath.FullClassPath);
                }

                using (FileStream fs = File.Create(classPath.FullClassPath))
                {
                    var data = GetContextFileText(classPath.ClassNamespace, template);
                    fs.Write(Encoding.UTF8.GetBytes(data));
                }

                RegisterContext(solutionDirectory, template);

                GlobalSingleton.AddCreatedFile(classPath.FullClassPath.Replace($"{solutionDirectory}{Path.DirectorySeparatorChar}", ""));
            }
            catch (FileAlreadyExistsException e)
            {
                WriteError(e.Message);
                throw;
            }
            catch (Exception e)
            {
                WriteError($"An unhandled exception occurred when running the API command.\nThe error details are: \n{e.Message}");
                throw;
            }
        }
Esempio n. 15
0
        /// <summary>
        /// this build will create environment based app settings files.
        /// </summary>
        public static void CreateAppSettings(string solutionDirectory, EnvironmentGateway env, string gatewayProjectName, List <Microservice> microservices)
        {
            try
            {
                var appSettingFilename = Utilities.GetAppSettingsName(env.EnvironmentName);
                var classPath          = ClassPathHelper.GatewayAppSettingsClassPath(solutionDirectory, $"{appSettingFilename}", gatewayProjectName);

                if (!Directory.Exists(classPath.ClassDirectory))
                {
                    Directory.CreateDirectory(classPath.ClassDirectory);
                }

                if (File.Exists(classPath.FullClassPath))
                {
                    File.Delete(classPath.FullClassPath);
                }

                using (FileStream fs = File.Create(classPath.FullClassPath))
                {
                    var data = "";
                    data = GetAppSettingsText(env, microservices);
                    fs.Write(Encoding.UTF8.GetBytes(data));
                }

                GlobalSingleton.AddCreatedFile(classPath.FullClassPath.Replace($"{solutionDirectory}{Path.DirectorySeparatorChar}", ""));
            }
            catch (FileAlreadyExistsException e)
            {
                WriteError(e.Message);
                throw;
            }
            catch (Exception e)
            {
                WriteError($"An unhandled exception occurred when running the API command.\nThe error details are: \n{e.Message}");
                throw;
            }
        }
        public static void CreateLaunchSettings(string solutionDirectory, string gatewayProjectName, IFileSystem fileSystem)
        {
            try
            {
                var classPath = ClassPathHelper.GatewayLaunchSettingsClassPath(solutionDirectory, $"launchSettings.json", gatewayProjectName);

                if (!fileSystem.Directory.Exists(classPath.ClassDirectory))
                {
                    fileSystem.Directory.CreateDirectory(classPath.ClassDirectory);
                }

                if (fileSystem.File.Exists(classPath.FullClassPath))
                {
                    throw new FileAlreadyExistsException(classPath.FullClassPath);
                }

                using (var fs = fileSystem.File.Create(classPath.FullClassPath))
                {
                    var data = "";
                    data = GetLaunchSettingsText();
                    fs.Write(Encoding.UTF8.GetBytes(data));
                }

                GlobalSingleton.AddCreatedFile(classPath.FullClassPath.Replace($"{solutionDirectory}{fileSystem.Path.DirectorySeparatorChar}", ""));
            }
            catch (FileAlreadyExistsException e)
            {
                WriteError(e.Message);
                throw;
            }
            catch (Exception e)
            {
                WriteError($"An unhandled exception occurred when running the API command.\nThe error details are: \n{e.Message}");
                throw;
            }
        }
Esempio n. 17
0
        public static void CreateRoles(string solutionDirectory, List <string> roles)
        {
            try
            {
                var classPath = ClassPathHelper.DomainEnumClassPath(solutionDirectory, $"Role.cs");

                if (!Directory.Exists(classPath.ClassDirectory))
                {
                    Directory.CreateDirectory(classPath.ClassDirectory);
                }

                if (File.Exists(classPath.FullClassPath))
                {
                    File.Delete(classPath.FullClassPath);
                }

                using (FileStream fs = File.Create(classPath.FullClassPath))
                {
                    var data = "";
                    data = GetRoleFileText(classPath.ClassNamespace, roles);
                    fs.Write(Encoding.UTF8.GetBytes(data));
                }

                GlobalSingleton.AddCreatedFile(classPath.FullClassPath.Replace($"{solutionDirectory}{Path.DirectorySeparatorChar}", ""));
            }
            catch (FileAlreadyExistsException e)
            {
                WriteError(e.Message);
                throw;
            }
            catch (Exception e)
            {
                WriteError($"An unhandled exception occured when running the API command.\nThe error details are: \n{e.Message}");
                throw;
            }
        }
        public static void CreateInfrastructureIdentityServiceExtension(string solutionDirectory, List <Policy> policies, IFileSystem fileSystem)
        {
            try
            {
                var classPath = ClassPathHelper.InfrastructureIdentityProjectRootClassPath(solutionDirectory, $"ServiceRegistration.cs");

                if (!fileSystem.Directory.Exists(classPath.ClassDirectory))
                {
                    fileSystem.Directory.CreateDirectory(classPath.ClassDirectory);
                }

                if (fileSystem.File.Exists(classPath.FullClassPath))
                {
                    throw new FileAlreadyExistsException(classPath.FullClassPath);
                }

                using (var fs = fileSystem.File.Create(classPath.FullClassPath))
                {
                    var data = "";
                    data = GetServiceRegistrationText(classPath.ClassNamespace, policies);
                    fs.Write(Encoding.UTF8.GetBytes(data));
                }

                GlobalSingleton.AddCreatedFile(classPath.FullClassPath.Replace($"{solutionDirectory}{fileSystem.Path.DirectorySeparatorChar}", ""));
            }
            catch (FileAlreadyExistsException e)
            {
                WriteError(e.Message);
                throw;
            }
            catch (Exception e)
            {
                WriteError($"An unhandled exception occurred when running the API command.\nThe error details are: \n{e.Message}");
                throw;
            }
        }
Esempio n. 19
0
        public static void CreateStartup(string solutionDirectory, string envName, ApiTemplate template)
        {
            try
            {
                var classPath = envName == "Startup" ? ClassPathHelper.StartupClassPath(solutionDirectory, $"Startup.cs") : ClassPathHelper.StartupClassPath(solutionDirectory, $"Startup{envName}.cs");

                if (!Directory.Exists(classPath.ClassDirectory))
                {
                    Directory.CreateDirectory(classPath.ClassDirectory);
                }

                if (File.Exists(classPath.FullClassPath))
                {
                    throw new FileAlreadyExistsException(classPath.FullClassPath);
                }

                using (FileStream fs = File.Create(classPath.FullClassPath))
                {
                    var data = "";
                    data = GetStartupText(envName, template);
                    fs.Write(Encoding.UTF8.GetBytes(data));
                }

                GlobalSingleton.AddCreatedFile(classPath.FullClassPath.Replace($"{solutionDirectory}{Path.DirectorySeparatorChar}", ""));
            }
            catch (FileAlreadyExistsException e)
            {
                WriteError(e.Message);
                throw;
            }
            catch (Exception e)
            {
                WriteError($"An unhandled exception occurred when running the API command.\nThe error details are: \n{e.Message}");
                throw;
            }
        }
Esempio n. 20
0
        public static void CreateInfrastructureSharedCsProj(string solutionDirectory)
        {
            try
            {
                var classPath = ClassPathHelper.InfrastructureSharedProjectClassPath(solutionDirectory);

                if (!Directory.Exists(classPath.ClassDirectory))
                {
                    Directory.CreateDirectory(classPath.ClassDirectory);
                }

                if (File.Exists(classPath.FullClassPath))
                {
                    throw new FileAlreadyExistsException(classPath.FullClassPath);
                }

                using (FileStream fs = File.Create(classPath.FullClassPath))
                {
                    var data = "";
                    data = GetInfrastructureSharedCsProjFileText();
                    fs.Write(Encoding.UTF8.GetBytes(data));
                }

                GlobalSingleton.AddCreatedFile(classPath.FullClassPath.Replace($"{solutionDirectory}{Path.DirectorySeparatorChar}", ""));
            }
            catch (FileAlreadyExistsException e)
            {
                WriteError(e.Message);
                throw;
            }
            catch (Exception e)
            {
                WriteError($"An unhandled exception occurred when running the API command.\nThe error details are: \n{e.Message}");
                throw;
            }
        }