public MaterialsSeederFromDir(DataContainer dataContainer, string configDir)
 {
     this.configDir     = configDir;
     this.dataContainer = dataContainer;
 }
Beispiel #2
0
 public MaterialsSeeder(DataContainer dataContainer)
 {
     this.dataContainer = dataContainer;
 }
Beispiel #3
0
        /// <summary>
        /// Seed database with materials and comment for testing purposes
        /// </summary>
        public void SeedAddTestData(IList <string> catTokens, bool titleAppendCategoryName = false)
        {
            CheckDbConnectionAndExitIfFailed();

            const string seedCommandDots = SeedCommand + ":";

            if (catTokens.Contains(SeedCommand))
            {
                catTokens[catTokens.IndexOf(SeedCommand)] = seedCommandDots + Category.RootCategoryName;
            }
            catTokens = catTokens.Select(x => x.Substring(seedCommandDots.Length)).ToList();

            SeedTestData();


            void SeedTestData()
            {
                using var db = new DataBaseConnection(providerName, connectionString);

                var dataContainer = new DataContainer
                {
                    Categories        = db.Categories.ToList(),
                    Users             = db.Users.ToList(),
                    currentMaterialId = db.Materials.Any() ? db.Materials.Max(x => x.Id) + 1 : 1,
                    currentCommentId  = db.Comments.Any() ? db.Comments.Max(x => x.Id) + 1 : 1
                };

                var titlesPath = Path.Combine(this.configDirectoryPath, SeederPathsNames.InitDir,
                                              SeederPathsNames.SeedTemplatesDir, SeederPathsNames.FishTitlesFile);
                var paragraphsPath = Path.Combine(this.configDirectoryPath, SeederPathsNames.InitDir,
                                                  SeederPathsNames.SeedTemplatesDir,
                                                  SeederPathsNames.FishParagraphsFile);
                var titles = Regex.Matches(File.ReadAllText(titlesPath), "<h1>(.*?)</h1>", RegexOptions.Singleline)
                             .Select(x => x.Groups[1].Value).ToList();
                var paragraphs = Regex
                                 .Matches(File.ReadAllText(paragraphsPath), "<p>(.*?)</p>", RegexOptions.Singleline)
                                 .Select(x => x.Groups[1].Value).ToList();


                var materialsSeeder = new MaterialsSeeder(dataContainer, titles, paragraphs);

                foreach (var catToken in catTokens)
                {
                    var parts          = catToken.Split(":");
                    var categoryName   = parts[0];
                    int?materialsCount = null;
                    if (parts.Length > 1)
                    {
                        materialsCount = int.Parse(parts[1]);
                    }
                    int?commentsCount = null;
                    if (parts.Length > 2)
                    {
                        commentsCount = int.Parse(parts[2]);
                    }

                    if (materialsCount.HasValue)
                    {
                        materialsSeeder.MinMaterialCount = materialsSeeder.MaxMaterialCount = materialsCount.Value;
                    }

                    if (commentsCount.HasValue)
                    {
                        materialsSeeder.CommentsCount = commentsCount.Value;
                    }

                    materialsSeeder.TitleAppendCategoryName = titleAppendCategoryName;

                    materialsSeeder.SeedCategoryAndSub(categoryName);
                }

                new DataBaseSeeder(db, dataContainer).SeedMaterials().PostSeedMaterials();
            }
        }
Beispiel #4
0
 public DataBaseSeeder(DataBaseConnection db, DataContainer dataContainer)
 {
     this.dataContainer = dataContainer;
     this.db            = db;
 }
Beispiel #5
0
 public MenuSeeder(DataContainer dataContainer, string configDir)
 {
     this.configDir     = configDir;
     this.dataContainer = dataContainer;
 }
 public ComponentsSeeder(DataContainer dataContainer, string configDir)
 {
     this.configDir     = configDir;
     this.dataContainer = dataContainer;
 }
Beispiel #7
0
 public InitialSeeder(string configDir)
 {
     this.configDir  = configDir;
     dataContainer   = new DataContainer();
     usersJsonSeeder = new UsersJsonSeeder(dataContainer, configDir);
 }
 public MaterialsSeeder(DataContainer dataContainer, List <string> titles, List <string> paragraphs)
 {
     this.dataContainer = dataContainer;
     this.titles        = titles;
     this.paragraphs    = paragraphs;
 }
Beispiel #9
0
        /// <summary>
        /// Seed database with materials and comment for testing purposes
        /// </summary>
        public void SeedAddTestData(IList <string> catTokens, bool titleAppendCategoryName = false)
        {
            CheckDbConnectionAndExitIfFailed();

            const string seedCommandDots = SeedCommand + ":";

            if (catTokens.Contains(SeedCommand))
            {
                catTokens[catTokens.IndexOf(SeedCommand)] = seedCommandDots + Category.RootName;
            }
            catTokens = catTokens.Select(x => x.Substring(seedCommandDots.Length)).ToList();

            SeedTestData();


            void SeedTestData()
            {
                using var db = new DataBaseConnection(providerName, connectionString);

                var dataContainer = new DataContainer
                {
                    Categories        = db.Categories.ToList(),
                    Users             = db.Users.ToList(),
                    currentMaterialId = db.Materials.Any() ? db.Materials.Max(x => x.Id) + 1 : 1,
                    currentCommentId  = db.Comments.Any() ? db.Comments.Max(x => x.Id) + 1 : 1
                };

                var materialsSeeder = new MaterialsSeeder(dataContainer);

                foreach (var catToken in catTokens)
                {
                    var parts          = catToken.Split(":");
                    var categoryName   = parts[0];
                    int?materialsCount = null;
                    if (parts.Length > 1)
                    {
                        materialsCount = int.Parse(parts[1]);
                    }
                    int?commentsCount = null;
                    if (parts.Length > 2)
                    {
                        commentsCount = int.Parse(parts[2]);
                    }

                    if (materialsCount.HasValue)
                    {
                        materialsSeeder.MinMaterialCount = materialsSeeder.MaxMaterialCount = materialsCount.Value;
                    }

                    if (commentsCount.HasValue)
                    {
                        materialsSeeder.CommentsCount = commentsCount.Value;
                    }

                    materialsSeeder.TitleAppendCategoryName = titleAppendCategoryName;

                    materialsSeeder.SeedCategoryAndSub(categoryName);
                }

                new DataBaseSeeder(db, dataContainer).SeedMaterials().PostSeedMaterials();
            }
        }
Beispiel #10
0
 public CategoriesSeeder(DataContainer dataContainer)
 {
     this.dataContainer = dataContainer;
 }
 public SectionsSeeder(DataContainer dataContainer, string configDir)
 {
     this.configDir     = configDir;
     this.dataContainer = dataContainer;
     sectionTypes       = new SectionTypes();
 }