Пример #1
0
        private static void ImportMongoToSql()
        {
            var mongoCreator = new MongoCreator();
            var db = mongoCreator.GetDatabase(MongoCreator.DatabaseName, MongoCreator.DatabaseHost);
            var myths = db.GetCollection<BsonDocument>("MagicalCreatureMythologyData");
            var data = myths.FindAll();

            var dbsql = new MagicalCreatureDbContext();

            var locations = dbsql.Locations.Select(o => o.Name).ToString();

            foreach (var item in data)
            {
                var loctionData = item["LocationOfOrigin"].AsString;

                if(!locations.Contains(loctionData))
                {
                    var loc = new Location { Name = loctionData };
                    dbsql.Locations.Add(loc);

                    var mythDataNme = item["Name"].AsString;
                    var mythology = new Mythology { Name = mythDataNme, Location = loc };

                    dbsql.Mythologies.Add(mythology);
                }
                else
                {
                    var mythDataNme = item["Name"].AsString;
                    var mythology = new Mythology { Name = mythDataNme, LocationId = locations.IndexOf(loctionData) };
                    dbsql.Mythologies.Add(mythology);
                }

            }

            dbsql.SaveChanges();
        }
Пример #2
0
        private static void UpdateMythologies()
        {
            XmlDocument doc = new XmlDocument();
            doc.Load("../../../DataSystem/AddData.xml");
            XmlNode rootNode = doc.DocumentElement;

            var dbsql = new MagicalCreatureDbContext();

            var mongoCreator = new MongoCreator();
            var db = mongoCreator.GetDatabase(MongoCreator.DatabaseName, MongoCreator.DatabaseHost);

            foreach (XmlNode node in rootNode.ChildNodes)
            {
                var name = node["name"].InnerText;
                var description = node["description"].InnerText;

                var myth = dbsql.Mythologies.First(x => x.Name == name);
                myth.Discription = description;

                var collection = db.GetCollection<BsonDocument>("MagicalCreatureMythologyData");
                var mythDb = collection.FindAll().First(x => x["Name"] == name);
                mythDb["Description"] = description;

                Console.WriteLine(mythDb["Description"].AsString);
                collection.Save(mythDb);
            }
            dbsql.SaveChanges();
        }
Пример #3
0
        private static void CreteMongoDb()
        {
            var mongoCreator =  new MongoCreator();

            var db1 = mongoCreator.GetDatabase(MongoCreator.DatabaseName, MongoCreator.DatabaseHost);
            var transports = db1.GetCollection<BsonDocument>("MagicalCreatureMythologyData");

            var count = transports.FindAll().Count();

            if(count==0)
            {
                mongoCreator.GenerateSampleData();
                transports = db1.GetCollection<BsonDocument>("MagicalCreatureMythologyData");
                count = transports.FindAll().Count();
                Console.WriteLine("MythologiesCreated" + count);
                return;
            }

            transports = db1.GetCollection<BsonDocument>("MagicalCreatureMythologyData");
            count = transports.FindAll().Count();

            Console.WriteLine("Mongo db Exists with " + count);
        }