public static void ImportToSqlAndMongo(BoardgameSimulatorData data, MongoConnection mongoData, string filePath = "../../../DataSources/xml/")
        {
            if (!Directory.Exists(filePath))
            {
                Console.WriteLine("There are no xml files present in " + filePath + " suitable for importing!");
                return;
            }

            var files = Directory.GetFiles(filePath).Select(x => x).Where(x => Path.GetExtension(x) == ".xml");

            Console.WriteLine("Importing from xml into Sql and MongoDb initialized.");

            foreach (var file in files)
            {
                var heroes = GetHeroes(file);
                var items = GetItems(file);

                Console.WriteLine("importing into sql...");
                AddHeroesToSql(heroes, data);
                AddItemsToSql(items, data);

                Console.WriteLine("importing into mongodb...");
                AddHeroesToMongo(heroes, mongoData);
                AddItemsToMongo(items, mongoData);
            }

            Console.WriteLine("Importing from xml into Sql and MongoDb completed!");
        }
        public static void Seed()
        {
            var data = new BoardgameSimulatorSqLiteData();

            var oldEntries = data.UnitsCosts.All().ToList();

            foreach (var entry in oldEntries)
            {
                data.UnitsCosts.Delete(entry);
            }

            var random = new Random();

            var sqldata = new BoardgameSimulatorData();

            var unitNames = sqldata.Units.All().Select(u => u.Name).ToList();

            Console.WriteLine("Seeding data into SqLite initialized.");

            foreach (var unit in unitNames)
            {
                var randomNumber = random.Next(150, 3501);

                data.UnitsCosts.Add(new UnitCost
                {
                    UnitName = unit,
                    RecruitCost = randomNumber
                });
            }

            data.UnitsCosts.SaveChanges();

            Console.WriteLine("Seeding of SqLite completed!");
        }
        public static void SeedBattleLogsToSql(MongoConnection mongoConnection, BoardgameSimulatorData data)
        {
            if (data == null)
            {
                return;
            }

            var logs = new GenericData<DummyBattleLog>(mongoConnection.Database, "battlelogs");

            var logsFromMongo = logs.GetAllDataFromCollection();

            SeedDataFromMongoDb(data, null, null, null, null, logsFromMongo);
        }
        private static void AddHeroesToSql(IEnumerable<DummyHero> heroes, BoardgameSimulatorData data)
        {
            foreach (var hero in heroes)
            {
                data.Heroes.Add(new Hero
                {
                    Name = hero.Name,
                    UnitId = hero.UnitId,
                    SkillId = hero.SkillId
                });
            }

            data.SaveChanges();
        }
        private static void AddItemsToSql(IEnumerable<DummyItem> items, BoardgameSimulatorData data)
        {
            foreach (var item in items)
            {
                data.Items.Add(new Item
                {
                    Name = item.Name,
                    DamageBonus = item.DamageBonus,
                    HealthBonus = item.HealthBonus,
                    HeroId = item.HeroId
                });
            }

            data.SaveChanges();
        }
        /// <summary>
        /// It is imperative that the steps be executed in strict order, else errors and crashes may occur
        /// </summary>
        public static void Demo()
        {
            var data = new BoardgameSimulatorData(new BoardgameSimulatorDbContext());

            var mysql = new BoardgameSimulatorMySqlData();

            var mongoConnection = new MongoConnection();

            // Comment this line before starting the app, otherwise it will crash,
            // telling you that you have no rights to write into the MongoLab Db
            MongoDbDataSeeder.SeedToMongoDb(mongoConnection);

            // Feeds data from the MongoDb to SQL
            MongoDbDataSeeder.SeedToSql(mongoConnection, data);

            // Generates excel reports from which the db will later be seeded
            XlsReportGenerator.GenerateArmiesInExcel2003();

            // Feeds data from the excel reports into SQL
            ArmiesReportsSeeder.SeedArmies();

            // Feeds army vs army data from the MongoDb to SQL
            MongoDbDataSeeder.SeedBattleLogsToSql(mongoConnection, data);

            // Seeds the SqLiteDb with additional data about units
            SqLiteDataSeeder.Seed();

            // Additional data is exported from SQL into json files and into the MySQLDb
            JsonAndMySqlSeeder.Seed(mysql, data);

            var pdfGen = new PdfGenerator();
            pdfGen.CreatePerksGroupArmyReport(data.Armies.All());
            pdfGen.CreatePdfSkillsPotentialReport(data.Skills.All());

            var sqlite = new BoardgameSimulatorSqLiteData();

            var armyVs = mysql.ArmyVsArmyReports.All();
            var armyE = sqlite.UnitsCosts.All();

            new ExcelGenerator().CreateBattleLogExcelReport(armyVs, armyE);

            XmlImporter.ImportToSqlAndMongo(data, mongoConnection);

            new XmlGenerator().CreateHeroesReport(data.Heroes.All());
        }
        public static void SeedToSql(MongoConnection mongoConnection, BoardgameSimulatorData data)
        {
            if (data == null)
            {
                return;
            }

            var skills = new GenericData<DummySkill>(mongoConnection.Database, "skills");
            var units = new GenericData<DummyUnit>(mongoConnection.Database, "units");
            var perks = new GenericData<DummyAlignmentPerk>(mongoConnection.Database, "perks");
            var heroes = new GenericData<DummyHero>(mongoConnection.Database, "heroes");

            var skillsFromMongo = skills.GetAllDataFromCollection();
            var unitsFromMongo = units.GetAllDataFromCollection();
            var perksFromMongo = perks.GetAllDataFromCollection();
            var heroesFromMongo = heroes.GetAllDataFromCollection();

            SeedDataFromMongoDb(data, skillsFromMongo, unitsFromMongo, perksFromMongo, heroesFromMongo, null);
        }
 private static void SeedUnits(BoardgameSimulatorData data, IEnumerable<DummyUnit> units)
 {
     foreach (var unit in units)
     {
         data.Units.Add(new Unit
         {
             Name = unit.Name,
             AttackType = (AttackType)unit.AttackType,
             Damage = unit.Damage,
             AttackRate = unit.AttackRate,
             Health = unit.Health
         });
     }
 }
 private static void SeedSkills(BoardgameSimulatorData data, IEnumerable<DummySkill> skills)
 {
     foreach (var skill in skills)
     {
         data.Skills.Add(new Skill
         {
             Name = skill.Name,
             Cooldown = skill.Cooldown,
             Damage = skill.Damage
         });
     }
 }
 private static void SeedPerks(BoardgameSimulatorData data, IEnumerable<DummyAlignmentPerk> perks)
 {
     foreach (var perk in perks)
     {
         data.AlignmentPerks.Add(new AlignmentPerk
         {
             Name = perk.Name,
             Type = perk.Type,
             DamageMultiplier = perk.DamageModifier,
             HealthMultiplier = perk.HealthModifier
         });
     }
 }
 private static void SeedHeroes(BoardgameSimulatorData data, IEnumerable<DummyHero> heroes)
 {
     foreach (var hero in heroes)
     {
         data.Heroes.Add(new Hero
         {
             Name = hero.Name,
             UnitId = hero.UnitId,
             SkillId = hero.SkillId,
         });
     }
 }
        private static void SeedDataFromMongoDb(BoardgameSimulatorData data,
            IEnumerable<DummySkill> skillsFromMongo,
            IEnumerable<DummyUnit> unitsFromMongo,
            IEnumerable<DummyAlignmentPerk> perksFromMongo,
            IEnumerable<DummyHero> heroesFromMongo,
            IEnumerable<DummyBattleLog> battleLogsFromMongo)
        {
            Console.WriteLine("Seeeding data from MongoDb into SQL initialized.");

            if (skillsFromMongo != null)
            {
                SeedSkills(data, skillsFromMongo);
                data.SaveChanges();
                Console.WriteLine("Skill entries successfully seeded into SQL");
            }

            if (unitsFromMongo != null)
            {
                SeedUnits(data, unitsFromMongo);
                data.SaveChanges();
                Console.WriteLine("Unit entries successfully seeded into SQL");
            }

            if (perksFromMongo != null)
            {
                SeedPerks(data, perksFromMongo);
                data.SaveChanges();
                Console.WriteLine("Perk entries successfully seeded into SQL");
            }

            if (heroesFromMongo != null)
            {
                SeedHeroes(data, heroesFromMongo);
                data.SaveChanges();
                Console.WriteLine("Hero entries successfully seeded into SQL");
            }

            if (battleLogsFromMongo != null)
            {
                SeedBattleLogs(data, battleLogsFromMongo);
                data.SaveChanges();
                Console.WriteLine("BattleLog entries successfully seeded into SQL");
            }

            Console.WriteLine("Seeeding data from MongoDb into SQL completed.");
        }
 private static void SeedBattleLogs(BoardgameSimulatorData data,
     IEnumerable<DummyBattleLog> logs)
 {
     foreach (var log in logs)
     {
         data.BattleLogs.Add(new BattleLog
         {
             Army1Id = log.Army1Id,
             Army2Id = log.Army2Id,
             Date = log.Date
         });
     }
 }