/// <summary>
        /// Load list of books from <see cref="storage"/>.
        /// </summary>
        /// <param name="storage"> Storage to load a list of books. </param>
        /// <exception cref="ArgumentNullException">Thrown when storage is null </exception>
        /// <exception cref="ArgumentException">Thrown when book list can't be loaded from storage</exception>
        public void Load(IBookListStorage storage)
        {
            if (storage == null)
            {
                Logger?.Info("Unhandled ArgumentNullException:");
                Logger?.Error("Argument \"storage\" in Load method can't be null.");
                throw new ArgumentNullException(nameof(storage));
            }

            try
            {
                _books = storage.Load() as List <Book>;
            }
            catch (Exception ex)
            {
                Logger?.Info("Unhandled Exception:");
                Logger?.Error("Some error while loading books from storage occuried.");
                throw;
            }

            if (_books == null)
            {
                Logger?.Info("Unhandled ArgumentException:");
                Logger?.Error($"Can't load book list from {nameof(storage)}.");
                throw new ArgumentException($"Can't load book list from {nameof(storage)}.");
            }
        }
        /// <summary>
        /// Load collection of books from specified storage
        /// </summary>
        /// <param name="bookListStorage"></param>
        /// <exception cref="ArgumentNullException"></exception>
        public void LoadBooks(IBookListStorage bookListStorage)
        {
            if (bookListStorage == null)
            {
                throw new ArgumentNullException();
            }

            Books = bookListStorage.Load();
        }
Esempio n. 3
0
 /// <summary>
 /// Load list of books from the storage.
 /// </summary>
 /// <param name="storage"> Storage to load the list of books from. </param>
 public void Load(IBookListStorage storage)
 {
     if (storage?.Load() == null)
     {
         this.logger.Error("Refused to load the books. Invalid storage.", new ArgumentNullException(nameof(storage)), storage);
         throw new ArgumentNullException(nameof(storage));
     }
     else
     {
         this.books = storage.Load();
         this.logger.Debug("Books were successfully loaded to the storage.");
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Loading books from binary file
        /// </summary>
        /// <param name="storage"></param>
        /// <exception cref="ArgumentNullException">Argument must not be null</exception>
        /// <returns>Before safed BookListServide</returns>
        public void LoadFromStorage(IBookListStorage storage)
        {
            if (storage == null)
            {
                throw new ArgumentNullException(nameof(storage));
            }

            foreach (Book book in storage.Load())
            {
                AddBook(book);
            }

            logger.Debug($"List of books loaded from storage");
        }
Esempio n. 5
0
 /// <summary>
 /// Loads collection of books from storage
 /// </summary>
 public void LoadFromStorage()
 {
     bookList.Clear();
     bookList = storage.Load();
     logger.Info($"Collection of books have loaded to file");
 }
 /// <summary>
 /// Load list of books from <see cref="storage"/>.
 /// </summary>
 /// <returns> Storage to load a list of books. </returns>
 public void Load(IBookListStorage storage)
 {
     this.books = storage?.Load() ?? throw new ArgumentNullException(nameof(storage));
 }
Esempio n. 7
0
 public BookListService(IBookListStorage bookListStorage)
 {
     books = new List <Book>(bookListStorage.Load());
 }