Exemple #1
0
        /// <summary>
        /// Loads books from <paramref name="storage"/>.
        /// </summary>
        /// <exception cref="ArgumentNullException">Throws if <paramref name="storage"/>
        /// is null</exception>
        /// <exception cref="BookListException">Throws if some errors while
        /// loading books from <paramref name="storage"/></exception>
        public void LoadBooksList(IBookListStorage storage)
        {
            if (ReferenceEquals(storage, null))
            {
                throw new ArgumentNullException($"{nameof(storage)} is null");
            }

            logger.Debug("Loading book list from {0}", nameof(storage));
            IEnumerable <Book> loadedBooks;

            try
            {
                loadedBooks = storage.LoadBookList();
            }
            catch (Exception ex)
            {
                logger.Warn(ex, "An error has occurred during loading book's list from {0}.", nameof(storage));
                throw new BookListException($"An error has occurred during loading book's list from {nameof(storage)}.", ex);
            }

            if (ReferenceEquals(loadedBooks, null))
            {
                logger.Warn("LoadBookList returned null.");
                throw new BookListException($"{nameof(LoadBooksList)} returned null.");
            }
            list = (List <Book>)loadedBooks;
        }
Exemple #2
0
 /// <summary>
 /// Load collection to <see cref="bookList"> from storage.
 /// </summary>
 /// <param name="storage">Storage.</param>
 /// <exception cref="ArgumentNullException">
 /// Throws when <see cref="storage"> is null.
 /// </exception>
 public void Load(IBookListStorage storage)
 {
     if (storage == null)
     {
         throw new ArgumentNullException(nameof(storage));
     }
     bookList = new List <Book>(storage.LoadBookList());
 }