public static void CreateAndSaveProductReports(string mongoConnectionString, string jsonFilePath)
        {
            using (var context = new SupermarketMSSql.Model.SupermarketReportsEntities())
            {
                var allProductsIds = context.Products.Select(x => x.Productid);

                foreach (var id in allProductsIds)
                {
                    ProductReport report = ProductReportsManager.GenerateProductReport(id);
                    ProductReportsManager.SaveToFileSystemAsJson(report, jsonFilePath);
                    MongoDbManager.SaveToMongoDB(report, mongoConnectionString, DatabaseName, CollectionName);
                }
            }
        }
Esempio n. 2
0
        public static void ReadXmlExpenses(string pathToFile)
        {
            XmlTextReader reader = new XmlTextReader(pathToFile);

            string   vendorName = string.Empty;
            DateTime date       = new DateTime();
            decimal  expenses   = 0;

            using (reader)
            {
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        if (reader.HasAttributes)
                        {
                            reader.MoveToNextAttribute();
                            if (reader.Name == "vendor")
                            {
                                vendorName = reader.Value;
                            }
                            else if (reader.Name == "month")
                            {
                                date = DateTime.Parse(reader.Value);
                            }
                        }

                        reader.MoveToElement();
                    }

                    if (reader.NodeType == XmlNodeType.Element && reader.Name == "expenses")
                    {
                        var expenseStr = reader.ReadInnerXml();
                        expenses = decimal.Parse(expenseStr);

                        int vendorId = MsSqlManager.InsertExpenses(vendorName, date, expenses);

                        MongoExpense mongoExpense = new MongoExpense(vendorId, date, expenses);

                        MongoDbManager.IsertExpenses(mongoExpense, "mongodb://localhost",
                                                     "SupermarketProductReports", "Expenses");
                    }
                }
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            MsSqlManager.MigrateDataFromMySqlToMSSql();
            Console.WriteLine("Migrated database from mysql to sqlserver.");

            string zipPath = "../../Sample-Sales-Reports.zip";

            string destinationPath = "../../SalesReports";

            ZipManager.Unzip(zipPath, destinationPath);
            Console.WriteLine("Unziped archive...");

            ExcelFilesManager.ReadExcelData(destinationPath);
            Console.WriteLine("Excel data read.");

            //ZipManager.DeleteTempFiles(destinationPath);
            //Console.WriteLine("Deleted temp files");

            PdfManager.CreateSalesReportPdfFile("../../SalesReports/SalesReport.pdf");
            Console.WriteLine("Pdf created");

            XmlManager.PrintToXML();
            Console.WriteLine("Xml created");

            string mongoConnectionString = Settings.Default.MongoDbConnectionString;

            ProductReportsManager.CreateAndSaveProductReports(mongoConnectionString, "../../");
            Console.WriteLine("Products reports saved in mongo and mssql");

            string xmlExpenses = "../../expenses.xml";

            XmlManager.ReadXmlExpenses(xmlExpenses);

            var productReports = MongoDbManager.ReadProductsReport(mongoConnectionString, "SupermarketProductReports", "ProductsReports");

            SQLiteManager.InsertProductReports(productReports);
            Console.WriteLine("SQLite populated");

            ExcelFilesManager.WriteDataFromSQLite();
            Console.WriteLine("Excel file created");
        }