public BeerService(IBeerstoreDatabaseSettings settings) { _mongoDbHandler = new MongoDbHandler(settings); _beers = _mongoDbHandler.GetDataBase().GetCollection <Beer>(settings.BeerCollectionName); }
// Warning - will not work - see comment above ProblemFour method invokation in Main() public static void Main() { var mongoHandler = new MongoDbHandler(); var sqlHandler = new SqlServerHandler(); var mySqlHandler = new MySqlHandler(); var pdfHandler = new PdfHandler(); var xmlToSql = new XmlToSqlServerLoader(); var excellHandler = new ExcellHandler(); var mongoToSql = new MongoToSqlServerLoader(); var zipExtractor = new ZipExtractor(); var jsonHandler = new JsonHandler(); var sqliteHandler = new SqliteHandler(); var xmlHandler = new XmlHandler(); if (!Directory.Exists(OutputDirectory)) { Directory.CreateDirectory(OutputDirectory); } //// Mongolab.com credentials - Username: TeamXenon , Passsword: xenon123 ProblemOne(mongoHandler, mongoToSql, zipExtractor, excellHandler); ProblemTwo(pdfHandler); ProblemThree(xmlHandler); //// NOTE!!! - you need to go to CarParts.Data.MySql project and in its App.config file //// you should change the password in the connectionString tag with which you connect to your localhost instance of the MySQL Workbench server. ProblemFour(sqlHandler, mySqlHandler, jsonHandler); ProblemFive(mongoHandler, xmlToSql); ProblemSix(excellHandler, sqlHandler, sqliteHandler, mySqlHandler); }
public void Seed() { this.mongoHandler = new MongoDbHandler(); this.excelHandler = new ExcelXlsHandler(); this.SeedVendors(); this.SeedCategories(); this.SeedDetails(); this.SeedProducts(); }
private void MigrateVendors(MongoDbHandler mongoHandler) { var vendors = mongoHandler.ReadCollection("Vendors").Result; using (var db = new CarPartsDbContext()) { foreach (var vendor in vendors) { var sqlVendor = new Vendor(); sqlVendor.Id = vendor["_id"].AsInt32; sqlVendor.Name = vendor["Name"].AsString; db.Vendors.Add(sqlVendor); } db.SaveChanges(); } }
private void MigrateManufacturers(MongoDbHandler mongoHandler) { var manufacturers = mongoHandler.ReadCollection("Manufacturers").Result; using (var db = new CarPartsDbContext()) { foreach (var manufacturer in manufacturers) { var sqlManufacturer = new Manufacturer(); sqlManufacturer.Id = manufacturer["_id"].AsInt32; sqlManufacturer.Name = manufacturer["Name"].AsString; db.Manufacturers.Add(sqlManufacturer); } db.SaveChanges(); } }
private static void ProblemFive(MongoDbHandler mongoHandler, XmlToSqlServerLoader xmlToSql) { var xmlHandler = new XmlHandler(); var countries = xmlHandler.GetCountries(); // If these are runned before they will throw because coutries are already added to the cloud and have unique constraint to their name in sql server. // You can delete physically the data and run the method if you like. xmlToSql.LoadCountries(countries); /*try // Just in case :) { mongoHandler.WriteCollection<XmlCountry>("Countries", countries); } catch (Exception ex) { }*/ Console.WriteLine("Successfully write down countries from XML to MongoDB and SqlServer databases"); }
private void MigrateParts(MongoDbHandler mongoHandler) { var parts = mongoHandler.ReadCollection("Parts").Result; using (var db = new CarPartsDbContext()) { foreach (var part in parts) { var sqlPart = new Part(); sqlPart.Id = part["_id"].AsInt32; sqlPart.Name = part["Name"].AsString; sqlPart.Price = decimal.Parse(part["Price"].AsString); sqlPart.ManufacturerId = part["ManufacturerId"].AsInt32; sqlPart.Manufacturer = db.Manufacturers.Where(m => m.Id == sqlPart.ManufacturerId) .FirstOrDefault(); foreach (var categoryId in part["Categories"] as BsonArray) { int category = categoryId.AsInt32; sqlPart.Categories.Add((PartCategory)category); } var vendorIds = new List<int>(); foreach (var vendorId in part["VendorIds"] as BsonArray) { vendorIds.Add(vendorId.AsInt32); } sqlPart.Vendors = db.Vendors.Where(v => vendorIds.Contains(v.Id)).ToList(); sqlPart.Manufacturer.Parts.Add(sqlPart); foreach (var vendor in sqlPart.Vendors) { vendor.Parts.Add(sqlPart); } db.Parts.Add(sqlPart); } db.SaveChanges(); } }
public ComapanyQueryHandler() { _mongoDbHandler = new MongoDbHandler<Company>(); }
public ComapanyQueryHandler() { _mongoDbHandler = new MongoDbHandler <Company>(); }
public void Load(MongoDbHandler mongoHandler) { this.MigrateManufacturers(mongoHandler); this.MigrateVendors(mongoHandler); this.MigrateParts(mongoHandler); }
private static void ProblemOne(MongoDbHandler mongoHandler, MongoToSqlServerLoader mongoToSql, ZipExtractor extractor, ExcellHandler excellHandler) { /*// populating database in mongolab with some useless testing data try { new mongodataseeder().seed(mongohandler); } catch (exception ex) { console.writeline("just in case you uncomment and try to populate the cloud database with existing id's and it throws :)"); }*/ mongoToSql.Load(mongoHandler); Console.WriteLine("successsfully added all in a sql database"); extractor.Extract(); Console.WriteLine("Files extracted successfully."); excellHandler.MigrateFromExcellToSqlServer(); Console.WriteLine("successfully added sales table from excell files."); }
public MongoDbService(IBeerstoreDatabaseSettings settings) { _mongoDbHandler = new MongoDbHandler(settings); }