Exemplo n.º 1
0
        public static void Main()
        {
            var databaseContext = new ComputersContextMongoDb();
            var data = new ComputerDataMongoDb(databaseContext);

            // var collection = data.Laptop.FindAll();
            var collection = data.Mice.FindAll();

            foreach (var item in collection)
            {
                Console.WriteLine(item.Model);
            }

            // var laptopCollection = new List<Laptop>
            // {
            //     new Laptop { Model = "Lenovo", Manufacturer = "Lenovo Corp.", Class = "Business" , Price = 2500},
            //     new Laptop { Model = "Dell", Manufacturer = "Dell Corp.", Class = "Business", Price = 2600},
            //     new Laptop { Model = "HP", Manufacturer = "HP Corp.", Class = "Business", Price = 2800 }
            // };

            // var mouseCollection = new List<Mouse>
            // {
            //     new Mouse {Model = "Naga Epic Chroma", Dpi = 8200, Manufacturer = "Razer", IsWireless = true, Price = 350},
            //     new Mouse {Model = "Copperhead", Dpi = 8200, Manufacturer = "Razer", IsWireless = true, Price = 250},
            //     new Mouse {Model = "Taipan", Dpi = 8200, Manufacturer = "Razer", IsWireless = false, Price = 300},
            // };

            // data.Save<Laptop>("laptops", laptopCollection);
            // data.Save<Mouse>("mice", mouseCollection);

            // data.Delete("laptops");
            // data.Delete("mice");
        }
Exemplo n.º 2
0
        public static void Main()
        {
            var db = new StoreContext();
            var databaseContext = new ComputersContextMongoDb();
            var mongoDb = new ComputerDataMongoDb(databaseContext);
            var dataForMongoDb = new List<Manufacturer>();

            var xmlManufacurersToImportWithGeneric = XmlDataImporterGeneric.ImportXmlData<Manufacturer>(@"..\..\LaptopManufacturers.xml");  // TODO make table with Unique values + remove ID?

            Console.WriteLine("Adding Manufacturers....");
            foreach (var manufacturer in xmlManufacurersToImportWithGeneric)
            {
                db.Manufacturers.Add(manufacturer);
                Console.WriteLine("{0} added successfully", manufacturer.Name);
            }

            var xmlManufacurersToImportWithSimple = XmlDataImporterSimple.ImportXmlData(@"..\..\LaptopManufacturers.xml");
            foreach (var manufacturer in xmlManufacurersToImportWithSimple)
            {
                db.Manufacturers.Add(manufacturer);
                dataForMongoDb.Add(manufacturer);

                Console.WriteLine("{0} added successfully", manufacturer.Name);
            }

            db.SaveChanges();
            Console.WriteLine("XML import to SQL complete!");

            mongoDb.Save("manufacturers", dataForMongoDb);
            Console.WriteLine("XML import to MongoDb complete!");

            Console.WriteLine();
            Console.WriteLine("XML Exporting from database.....");
            Console.WriteLine();
            XmlFileExporter.GenerateXmlReport(ExportDirectory, db);
            Console.WriteLine("Report successfully exported to {0}", ExportDirectory);
        }
Exemplo n.º 3
0
        public static void Main()
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<StoreContext, Configuration>());

            var databaseContext = new ComputersContextMongoDb();
            var data = new ComputerDataMongoDb(databaseContext);
            var db = new StoreContext();

            var laptopCollection = data.Laptop.FindAll();
            var mouseCollection = data.Mice.FindAll();

            var manufacturers = new Dictionary<string, Manufacturer>();
            var classes = new Dictionary<string, LaptopClass>();

            foreach (var item in laptopCollection)
            {
                if (!manufacturers.ContainsKey(item.Manufacturer))
                {
                    if (db.Manufacturers.Any(x => x.Name == item.Manufacturer))
                    {
                        manufacturers.Add(item.Manufacturer, db.Manufacturers.First(x => x.Name == item.Manufacturer));
                    }
                    else
                    {
                        manufacturers.Add(item.Manufacturer, new Manufacturer { Name = item.Manufacturer });
                    }
                }

                if (!classes.ContainsKey(item.Class))
                {
                    if (db.Classes.Any(x => x.Name == item.Class))
                    {
                        classes.Add(item.Class, db.Classes.First(x => x.Name == item.Class));
                    }
                    else
                    {
                        classes.Add(item.Class, new LaptopClass { Name = item.Class });
                    }
                }

                var laptop = new Laptop
                {
                    Model = item.Model,
                    Manufacturer = manufacturers[item.Manufacturer],
                    Class = classes[item.Class],
                    Price = item.Price
                };

                db.Laptops.AddOrUpdate(laptop);
            }

            foreach (var item in mouseCollection)
            {
                if (!manufacturers.ContainsKey(item.Manufacturer))
                {
                    if (db.Manufacturers.Any(x => x.Name == item.Manufacturer))
                    {
                        manufacturers.Add(item.Manufacturer, db.Manufacturers.First(x => x.Name == item.Manufacturer));
                    }
                    else
                    {
                        manufacturers.Add(item.Manufacturer, new Manufacturer { Name = item.Manufacturer });
                    }
                }

                var mouse = new Mouse
                {
                    Model = item.Model,
                    Manufacturer = manufacturers[item.Manufacturer],
                    Dpi = item.Dpi,
                    IsWireless = item.IsWireless,
                    Price = item.Price
                };

                db.Mice.Add(mouse);
            }

            db.SaveChanges();
            var pdfExporter = new PdfFileExporter();
            pdfExporter.GenerateComputersReports(PdfReportsFolderPath, PdfReportsFileName, db);

            ////var jsonExporter = new JsonExporter();
            //// TODO: Returns default date for some reason - help pls probably culture issue
            ////var date = jsonExporter.GetDate();
            ////jsonExporter.GenerateReportsForGivenDate(JSONReportsFolderPath, date, db);
        }