Esempio n. 1
0
        static void ReadFromXML(XmlTextWriter writer)
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load("../../review-queries.xml");
            string xPathQuery = "/review-queries";

            XmlNodeList bookList = xmlDoc.SelectNodes(xPathQuery);

            foreach (XmlNode bookNode in bookList)
            {
                foreach (XmlNode queryNode in bookNode.SelectNodes("query"))
                {
                    string type      = queryNode.Attributes["type"].Value;
                    string startDate = queryNode.GetNodeContent("start-date");
                    string endDate   = queryNode.GetNodeContent("end-date");
                    string author    = queryNode.GetNodeContent("author-name");

                    if (type == "by-period")
                    {
                        var reviews = BookstoreDAL.FindReviewsByPeriod(startDate, endDate);
                        BookstoreDAL.WriteReviews(writer, reviews);
                    }
                    else
                    {
                        var reviews = BookstoreDAL.FindReviewsByAuthor(author);
                        BookstoreDAL.WriteReviews(writer, reviews);
                    }
                }
            }
        }
        static void ReadFromXML()
        {
            TransactionScope tran = new TransactionScope(
                TransactionScopeOption.Required,
                new TransactionOptions()
            {
                IsolationLevel = IsolationLevel.RepeatableRead
            });

            using (tran)
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load("../../simple-books.xml");
                string xPathQuery = "/catalog/book";

                XmlNodeList bookList = xmlDoc.SelectNodes(xPathQuery);
                foreach (XmlNode bookNode in bookList)
                {
                    string  title   = bookNode.GetNodeContent("title");
                    string  isbn    = bookNode.GetNodeContent("isbn");
                    string  author  = bookNode.GetNodeContent("author");
                    decimal price   = ParseNullableDecimal(bookNode.GetNodeContent("price"));
                    string  website = bookNode.GetNodeContent("web-site");

                    BookstoreDAL.AddBook(title, isbn, author, price, website);
                }
                tran.Complete();
            }
        }
Esempio n. 3
0
        private static void ImportComplexBooks()
        {
            #region parseXml

            string filePath = "../../xml/complex-books.xml";
            var    result   = Helpers.DeserializeFromXml <ComplexCatalog>(filePath);

            #endregion

            result.Books.ForEachStoppable(b => BookstoreDAL.AddBook(b.Title, b.ISBN, b.Authors, b.Price, b.Url, b.Reviews));
        }
Esempio n. 4
0
        private static void ImportSimpleBooks()
        {
            #region parseXml

            string filePath = "../../xml/simple-books.xml";
            var    result   = Helpers.DeserializeFromXml <SampleCatalog>(filePath);

            #endregion

            result.Books.ForEachStoppable(b => BookstoreDAL.AddBook(b.Title, b.ISBN, b.Author, b.Price, b.Url));
        }
Esempio n. 5
0
        static void ReadFromXML()
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load("../../simple-query.xml");
            string xPathQuery = "/query";

            XmlNodeList bookList = xmlDoc.SelectNodes(xPathQuery);

            foreach (XmlNode bookNode in bookList)
            {
                string title  = bookNode.GetNodeContent("title");
                string author = bookNode.GetNodeContent("author");
                string isbn   = bookNode.GetNodeContent("isbn");
                var    books  = BookstoreDAL.SearchForBook(title, author, isbn);
                if (books.Count > 0)
                {
                    Dictionary <string, int> booksTitles = new Dictionary <string, int>();
                    string sameTitle        = books[0].Title;
                    int    sameTitleCounter = 0;
                    for (int i = 1; i < books.Count; i++)
                    {
                        if (books[i].Title == sameTitle)
                        {
                            sameTitleCounter++;
                        }
                        else if (books[i].Title != sameTitle && i == books.Count - 1)
                        {
                            booksTitles.Add("asd", 5);
                            booksTitles.Add(sameTitle, sameTitleCounter);
                            sameTitle        = books[i].Title;
                            sameTitleCounter = 0;
                        }
                        if (i == books.Count - 1)
                        {
                            booksTitles.Add(sameTitle, sameTitleCounter);
                            sameTitle        = books[i].Title;
                            sameTitleCounter = 0;
                        }
                    }

                    foreach (var booktitle in booksTitles)
                    {
                        Console.WriteLine(booktitle.Key + " --> " + booktitle.Value + " reviews");
                    }
                    Console.WriteLine();
                }
                else
                {
                    Console.WriteLine("Nothing Found");
                }
            }
        }
        static void Main(string[] args)
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load("../../complex-books.xml");
            string xPathQuery = "/catalog/book";

            XmlNodeList bookList = xmlDoc.SelectNodes(xPathQuery);

            foreach (XmlNode bookNode in bookList)
            {
                string title = bookNode.GetNodeContent("title");
                string isbn  = bookNode.GetNodeContent("isbn");

                List <string> authors     = new List <string>();
                string        authorsNode = bookNode.GetNodeContent("authors");
                if (authorsNode != null)
                {
                    foreach (XmlNode author in bookNode.SelectSingleNode("authors").SelectNodes("author"))
                    {
                        authors.Add(author.InnerText);
                    }
                }

                decimal price   = ParseNullableDecimal(bookNode.GetNodeContent("price"));
                string  website = bookNode.GetNodeContent("web-site");

                List <string> reviews        = new List <string>();
                List <string> reviewsDates   = new List <string>();
                List <string> reviewsAuthors = new List <string>();
                string        reviewsNode    = bookNode.GetNodeContent("reviews");
                if (reviewsNode != null)
                {
                    foreach (XmlNode review in bookNode.SelectNodes("reviews"))
                    {
                        foreach (XmlNode rev in review)
                        {
                            reviews.Add(rev.InnerText.Trim());

                            if (rev.Attributes["date"] != null)
                            {
                                reviewsDates.Add(rev.Attributes["date"].Value.ToString());
                            }
                            else
                            {
                                reviewsDates.Add(DateTime.Now.ToString("dd-MMM-yyy"));
                            }

                            if (rev.Attributes["author"] != null)
                            {
                                reviewsAuthors.Add(rev.Attributes["author"].Value);
                            }
                            else
                            {
                                reviewsAuthors.Add("anonymous");
                            }
                        }
                    }
                }

                BookstoreDAL.AddBooksReview(title, isbn, authors, price, website,
                                            reviews, reviewsDates, reviewsAuthors);
            }
        }