private LinkedList <Book> GenerateShelf(DbBuffer buffer) { var books = new LinkedList <Book>(); var totalWidth = 0.0f; while (true) { // find entry with good size if it exsists DataEntry entry; do { if ((entry = buffer.NextEntry()) == null) { Debug.Log("Database buffer return null"); return(books); // db ran out } } while (entry.Width > shelfWidth * 100); var book = new Book(entry); if (book.Width < MinWidth) { continue; } totalWidth += book.Width; if (totalWidth >= shelfWidth) { break; } addShelf(books, book); } return(books); }
/// <summary> /// Given initial conditions, query the database until this object is filled with /// <see cref="Book"/> objects. Any chained <see cref="Bookshelf"/> objects will also have this /// function called. /// </summary> /// <param name="direction">direction to load</param> /// <exception cref="ArgumentOutOfRangeException">if direction is invalid</exception> public void Load(Direction direction) { if (!done) { return; } done = false; // Load self // FIXME The Identity direction does not include the starting book when populating DbBuffer buffer; switch (direction) { case Direction.Right: addShelf = AddRight; addTable = AddRight; buffer = new DbBuffer(End, direction); break; case Direction.Left: addShelf = AddLeft; addTable = AddLeft; buffer = new DbBuffer(Start, direction); break; case Direction.Identity: addShelf = AddRight; addTable = AddRight; buffer = new DbBuffer(Start, Direction.Right); break; default: throw new ArgumentOutOfRangeException("direction", direction, message: null); } PopulateTable(buffer); done = true; // Load chain foreach (var entry in chain) { entry.bookshelf.Start = Start; entry.bookshelf.End = End; entry.bookshelf.Load(entry.direction); } }
private void PopulateTable(DbBuffer buffer) { for (var i = 0; i < shelfCount; i++) { var books = GenerateShelf(buffer); if (books.Count == 0) { break; } addTable(Table, books); } if (Table.Count > 0) { Start = Table.First.Value.First.Value.CallNumber; End = Table.Last.Value.Last.Value.CallNumber; } else { Start = End = ""; } }