Exemplo n.º 1
0
        public static void IsertExpenses(MongoExpense mongoExpense, string connectionString,
            string databaseName, string collectionName)
        {
            var client = new MongoClient(connectionString);
            var server = client.GetServer();
            var database = server.GetDatabase(databaseName);
            var collection = database.GetCollection(collectionName);

            collection.Insert(mongoExpense);
        }
Exemplo n.º 2
0
        public static void IsertExpenses(MongoExpense mongoExpense, string connectionString,
                                         string databaseName, string collectionName)
        {
            var client     = new MongoClient(connectionString);
            var server     = client.GetServer();
            var database   = server.GetDatabase(databaseName);
            var collection = database.GetCollection(collectionName);

            collection.Insert(mongoExpense);
        }
Exemplo n.º 3
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");
                    }
                }
            }
        }
Exemplo n.º 4
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");
                    }
                }
            }
        }
Exemplo n.º 5
0
        private static ICollection <MongoExpense> GetVendorMongoExpensesFromXml()
        {
            XmlDocument document = new XmlDocument();

            document.Load(@"..\..\Vendor.xml");

            List <MongoExpense> expenses = new List <MongoExpense>();

            using (var db = new SupermarketContext())
            {
                XmlNode sales = document.DocumentElement;
                foreach (XmlNode sale in sales.ChildNodes)
                {
                    foreach (XmlNode expense in sale.ChildNodes)
                    {
                        DateTime date            = DateTime.ParseExact(expense.Attributes[0].Value, "MMM-yyyy", CultureInfo.InvariantCulture);
                        string   vendorName      = sale.Attributes[0].Value;
                        int      currentVendorId =
                            (from v in db.Vendors
                             where v.VendorName == vendorName
                             select v.Id).First();

                        var currentExpense = new MongoExpense
                        {
                            Month    = date,
                            Value    = decimal.Parse(expense.InnerText),
                            VendorId = currentVendorId
                        };

                        expenses.Add(currentExpense);
                    }
                }
            }

            return(expenses);
        }