private void Check(SourceAnalyzer.Book expectedResult, string text) { var actualResult = new BookParser().TryParse(text); Assert.AreEqual(expectedResult, actualResult); Assert.AreEqual(text, actualResult.ToString()); }
public void Display() { if (_parser == null) { _parser = new BookParser(this._fileName); } _parser.Display(); }
public int GetNumPages() { if (this.parser == null) { this.parser = new BookParser(this.book); } return(parser.GetNumPages()); }
public IEnumerable<Book> GetBooks() { using (var stream = Open()) { var parser = new BookParser { Log = Log }; Date created; using (var reader = parser.Open(stream, out created)) return parser.GetBooks(reader).ToArray(); } }
public void CanParseBookXml() { Book book = BookParser.Parse(_xml); CheckIf.EqualId("3dd199f14b9d79e170caa4653fa152f2", book.Id, "Book id should be parsed"); List <Account> accounts = book.Accounts; List <Transaction> transactions = book.Transactions; Assert.AreEqual(3, accounts.Count, "Accounts should be parsed"); Assert.AreEqual(3, transactions.Count, "Transactions should be parsed"); }
public object Get(BookModels request) { if (!string.IsNullOrEmpty(request.AmazonUrl)) { try { var response = BookParser.GetBookDetails(request.AmazonUrl); return(response); } catch { } } if (request.Id > 0) { var book = BookRepository.Find(request.Id); book.Description = HttpContext.Current.Server.HtmlDecode(book.Description); return(book); } var books = new List <BookModels>(); if (request.CategoryId <= 0) { var userAuth = this.GetSession(); var userAuthId = userAuth.Id.To <int>(); books = BookRepository.All().Where(a => a.UserId == userAuthId && (request.CategoryId <= 0 || a.CategoryId == request.CategoryId)).ToList(); } else { books = BookRepository.All().Where(a => request.CategoryId <= 0 || a.CategoryId == request.CategoryId).ToList(); } foreach (var book in books) { book.CategoryText = LookupRepository.Find(book.CategoryId).Name; book.Description = HttpContext.Current.Server.HtmlDecode(book.Description); } return(books); }
public void LoadBook(BookInfo book_info) { string title = book_info.title; string content = DownloadBookContent(book_info.link); pages = BookParser.GetPages(content); page_cnt = pages.Count; page_idx_l = 0; page_idx_r = 1; transform.GetChild(1).GetChild(0).GetComponent <Text>().text = pages[page_idx_l]; GetComponent <PhotonView>().RPC("SetText", PhotonTargets.Others, new int[] { 1, 0 }, pages[page_idx_l]); transform.GetChild(1).GetChild(1).GetComponent <Text>().text = page_idx_l.ToString(); GetComponent <PhotonView>().RPC("SetText", PhotonTargets.Others, new int[] { 1, 1 }, page_idx_l.ToString()); transform.GetChild(2).GetChild(0).GetComponent <Text>().text = pages[page_idx_r]; GetComponent <PhotonView>().RPC("SetText", PhotonTargets.Others, new int[] { 2, 0 }, pages[page_idx_r]); transform.GetChild(2).GetChild(1).GetComponent <Text>().text = page_idx_r.ToString(); GetComponent <PhotonView>().RPC("SetText", PhotonTargets.Others, new int[] { 2, 1 }, page_idx_r.ToString()); }
public void Convert(CatalogParser parser, XmlReader reader, Date created, Stream bookStream, Stream volumeStream) { // There are almost 42,000 books and 520,000 files in the project Gutenberg. We set // up 59 * 10,000 steps here to have the progress bar stretching quite good and still // having a little space to grow for the project content. var progress = Log.Action(59, "Converting catalog..."); int bookCount = 0, skippedCount = 0, volumeCount = 0, totalCount = 0; var bookParser = new BookParser { Log = Log }; var volumeParser = new VolumeParser { Log = Log }; using (var bookWriter = bookParser.Create(bookStream, created)) using (var volumeWriter = volumeParser.Create(volumeStream, created)) { foreach (var item in parser.GetItems(reader)) { var book = item as Book; if (book != null) { // Book 9140 and a couple of others are invalid. if (string.IsNullOrEmpty(book.Title)) { Log.Verbose("Skipping book {0} with no title.", book.Number); ++skippedCount; } else { bookParser.Write(bookWriter, book); } ++bookCount; } else { volumeParser.Write(volumeWriter, (Volume) item); ++volumeCount; } // One step after every 10,000 items run nicely on my laptop; less loaded the // CPU with constant reporting and more made the console wait for too long. if (++totalCount % 10000 == 0) progress.Continue("{0} items processed...", totalCount); } bookParser.Finalize(bookWriter); volumeParser.Finalize(volumeWriter); } Log.Verbose("{0} books and {1} volumes were processed, {2} books skipped.", bookCount, volumeCount, skippedCount); progress.Finish(); }
public void ParseObject() { var node = new BookParser(new StringReader("obj { expr: value\n expr2: value2\n }")).Parse(); node.ToString().Should().BeEquivalentTo("#root {\nobj {\nexpr: value\nexpr2: value2\n}\n}"); }
public void ParseProperties() { var node = new BookParser(new StringReader("expr: value\n expr2: value2")).Parse(); node.ToString().Should().BeEquivalentTo("#root {\nexpr: value\nexpr2: value2\n}"); }
public void IgnoreBracketsInString() { var node = new BookParser(new StringReader("expr: \"{{[(\"")).Parse(); node.ToString().Should().BeEquivalentTo("#root {\nexpr: \"{{[(\"\n}"); }
public void ParsePropertyWithMultilineString() { var node = new BookParser(new StringReader("expr: \"l1\nl2\"")).Parse(); node.ToString().Should().BeEquivalentTo("#root {\nexpr: \"l1\nl2\"\n}"); }
public void ParsePropertyWithMultilineNestedParenthesis() { var node = new BookParser(new StringReader("expr: ((value\n)+2\n)+2\n")).Parse(); node.ToString().Should().BeEquivalentTo("#root {\nexpr: ((value\n)+2\n)+2\n}"); }
public void ParsePropertyWithMultilineBracket() { var node = new BookParser(new StringReader("expr: $ABS{value\n+2}")).Parse(); node.ToString().Should().BeEquivalentTo("#root {\nexpr: $ABS{value\n+2}\n}"); }