Ejemplo n.º 1
0
        public static void AddSeeders(string solutionDirectory, List <Entity> entities, string dbContextName, string projectBaseName)
        {
            foreach (var entity in entities)
            {
                var classPath = ClassPathHelper.DummySeederClassPath(solutionDirectory, $"{Utilities.GetSeederName(entity)}.cs", projectBaseName);

                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, dbContextName, solutionDirectory, projectBaseName);
                    fs.Write(Encoding.UTF8.GetBytes(data));
                }
            }

            RegisterAllSeeders(solutionDirectory, entities, dbContextName, projectBaseName);
        }
Ejemplo n.º 2
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;
            }
        }
Ejemplo n.º 3
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;
            }
        }
Ejemplo n.º 4
0
        public static void AddSeeders(string srcDirectory, List <Entity> entities, string dbContextName, string projectBaseName)
        {
            try
            {
                foreach (var entity in entities)
                {
                    var classPath = ClassPathHelper.SeederClassPath(srcDirectory, $"{Utilities.GetSeederName(entity)}.cs", projectBaseName);

                    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, dbContextName, srcDirectory, projectBaseName);
                        fs.Write(Encoding.UTF8.GetBytes(data));
                    }
                }

                RegisterAllNewSeeders(srcDirectory, entities, dbContextName, projectBaseName);
            }
            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;
            }
        }