static void Main() { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("../../simple-query.xml"); string xPathQuery = "/query"; XmlNode query = xmlDoc.SelectSingleNode(xPathQuery); string title = query.InnerTextOrNull("title"); string author = query.InnerTextOrNull("author"); string isbn = query.InnerTextOrNull("isbn"); List <Book> foundBooks = BookStoreDAL.SimpleSearchForBooks(title, author, isbn); if (foundBooks.Count != 0) { Console.WriteLine("{0} books found:", foundBooks.Count); foreach (var book in foundBooks) { Console.WriteLine("{0} --> {1} reviews", book.Title, book.Reviews.Count == 0 ? "no" : book.Reviews.Count.ToString()); } } else { Console.WriteLine("Nothing found"); } }
static void Main() { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; using (TransactionScope tran = new TransactionScope( TransactionScopeOption.Required, new TransactionOptions() { IsolationLevel = IsolationLevel.RepeatableRead })) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("../../simple-books.xml"); string xPathQuery = "/catalog/book"; XmlNodeList booksList = xmlDoc.SelectNodes(xPathQuery); foreach (XmlNode bookNode in booksList) { string author = bookNode.InnerTextOrNull("author"); string title = bookNode.InnerTextOrNull("title"); string isbn = bookNode.InnerTextOrNull("isbn"); string price = bookNode.InnerTextOrNull("price"); string website = bookNode.InnerTextOrNull("web-site"); BookStoreDAL.SimpleBooksImport(author, title, isbn, price, website); } tran.Complete(); } }
static void Main() { string fileName = "../../reviews-search-results.xml"; using (XmlTextWriter writer = new XmlTextWriter(fileName, Encoding.UTF8)) { writer.Formatting = Formatting.Indented; writer.IndentChar = '\t'; writer.Indentation = 1; writer.WriteStartDocument(); writer.WriteStartElement("search-results"); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("../../reviews-queries.xml"); string xPathQuery = "/review-queries/query"; XmlNodeList queryList = xmlDoc.SelectNodes(xPathQuery); foreach (XmlNode query in queryList) { List <Review> reviews = new List <Review>(); string type = query.Attributes["type"].Value; if (type == "by-author") { string authorName = query.SelectSingleNode("author-name").InnerText; reviews = BookStoreDAL.SearchForReviewsByAuthor(authorName); } else { string startDate = query.SelectSingleNode("start-date").InnerText; string endDate = query.SelectSingleNode("end-date").InnerText; reviews = BookStoreDAL.SearchForReviewsByPeriod(startDate, endDate); } writer.WriteStartElement("result-set"); foreach (var review in reviews) { writer.WriteStartElement("review"); writer.WriteElementString("date", review.DateCreated.ToString()); writer.WriteElementString("content", review.Text.ToString()); writer.WriteStartElement("book"); writer.WriteElementString("title", review.Book.Title); if (review.Book.Authors.Count != 0) { writer.WriteElementString("authors", string.Join(", ", review.Book.Authors.Select(x => x.Name).ToList())); } if (review.Book.ISBNnumber != null) { writer.WriteElementString("isbn", review.Book.ISBNnumber); } if (review.Book.Website != null) { writer.WriteElementString("url", review.Book.Website); } writer.WriteEndElement(); writer.WriteEndElement(); } writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndDocument(); } }
static void Main() { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; using (TransactionScope tran = new TransactionScope( TransactionScopeOption.Required, new TransactionOptions() { IsolationLevel = IsolationLevel.RepeatableRead })) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("../../complex-books.xml"); string xPathQuery = "/catalog/book"; XmlNodeList booksList = xmlDoc.SelectNodes(xPathQuery); foreach (XmlNode bookNode in booksList) { List <string> authors = new List <string>(); XmlNode authorsNode = bookNode.SelectSingleNode("authors"); if (authorsNode != null) { XmlNodeList authorsList = authorsNode.SelectNodes("author"); foreach (XmlNode author in authorsList) { authors.Add(author.InnerText); } } string title = bookNode.InnerTextOrNull("title"); string isbn = bookNode.InnerTextOrNull("isbn"); string price = bookNode.InnerTextOrNull("price"); string website = bookNode.InnerTextOrNull("web-site"); List <ReviewImport> reviews = new List <ReviewImport>(); XmlNode reviewsNode = bookNode.SelectSingleNode("reviews"); if (reviewsNode != null) { XmlNodeList reviewsList = reviewsNode.SelectNodes("review"); foreach (XmlNode review in reviewsList) { string reviewStr = review.InnerText; string date = null; if (review.Attributes["date"] != null) { date = review.Attributes["date"].Value; } string author = null; if (review.Attributes["author"] != null) { author = review.Attributes["author"].Value; } reviews.Add(new ReviewImport(reviewStr, author, date)); } } BookStoreDAL.ComplexBooksImport(authors, title, isbn, price, website, reviews); } tran.Complete(); } }