public void GenerateBookData() { StreamReader reader = new StreamReader("poetry.txt"); string line; while ((line = reader.ReadLine()) != null) { try { Book b = ParseLine(line); var rand = _generator.Next(100, 1000); for (int i = 0; i < rand; i++) { Library l = Libraries.SearchNode( new Library(libraryNames[_generator.Next(0, libraryNames.Length)]), Libraries.Root).Data; Book c = new Book(b.Author, b.Title, b.CodeIsbn, b.CodeEan, b.Genre, l, counterOfBooks); BooksByIsbn.Add(c); BooksByUniqueId.Add(c); BooksByName.Add(c); counterOfBooks++; } } catch (Exception e) { Console.WriteLine("While reading data from file, this exception occured: {0}", e.StackTrace); } } }
public void ReadBooksFromFile(string filename) { // title, author, uid, isbn, ean, reader name, reader surname, ruid, from, to, archived, library StreamReader w = new StreamReader(filename); string line; while ((line = w.ReadLine()) != null) { var b = ParseBook(line); if (b != null) { BooksByName.Add(b); BooksByIsbn.Add(b); BooksByUniqueId.Add(b); NumberOfBooks++; } } w.Close(); }