/// <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)}.");
            }
        }
Beispiel #2
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;
        }
Beispiel #3
0
 /// <summary>
 /// Save <see cref="bookList"> in storage.
 /// </summary>
 /// <param name="storage">Storage.</param>
 /// <exception cref="ArgumentNullException">
 /// Throws when <see cref="storage"> is null.
 /// </exception>
 public void Save(IBookListStorage storage)
 {
     if (storage == null)
     {
         throw new ArgumentNullException(nameof(storage));
     }
     storage.SaveBookList(bookList);
 }
Beispiel #4
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());
 }
Beispiel #5
0
 /// <summary>
 /// Load book's list from file
 /// </summary>
 /// <param name="fileName">File's name</param>
 public void LoadData(IBookListStorage bookListStorage)
 {
     if (bookListStorage == null)
     {
         throw new ArgumentNullException();
     }
     bookList = bookListStorage.LoadData(logger);
 }
Beispiel #6
0
 public BookListService(IBookListStorage bookListStorage)
 {
     if (ReferenceEquals(bookListStorage, null))
     {
         throw new ArgumentException();
     }
     this.bookListStorage = bookListStorage;
 }
Beispiel #7
0
 /// <summary>
 /// Save book's list in file
 /// </summary>
 /// <param name="fileName">File's name</param>
 public void SaveData(IBookListStorage bookListStorage)
 {
     if (bookListStorage == null)
     {
         throw new ArgumentNullException();
     }
     bookListStorage.StoreData(logger, bookList);
 }
        /// <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();
        }
        /// <summary>
        /// Save collection of books in specified storage
        /// </summary>
        /// <param name="bookListStorage"></param>
        /// <exception cref="ArgumentNullException"></exception>
        public void SaveBooks(IBookListStorage bookListStorage)
        {
            if (bookListStorage == null)
            {
                throw new ArgumentNullException();
            }

            bookListStorage.Save(Books);
        }
Beispiel #10
0
        public void GetBookListFromStorage(IBookListStorage storage)
        {
            IEnumerable <Book> bookList = storage.ReadFromStorage();

            foreach (Book book in bookList)
            {
                this.AddBook(book);
            }
        }
Beispiel #11
0
        public void Save(IBookListStorage bookListStorage)
        {
            if (ReferenceEquals(bookListStorage, null))
            {
                throw new ArgumentNullException();
            }

            bookListStorage.SaveBooks(Books);
        }
Beispiel #12
0
        /// <summary>
        /// Load books from the repo
        /// </summary>
        /// <param name="repo">The repo to load from</param>
        /// <exception cref="ArgumentNullException">Throws when repo is null</exception>
        public void LoadFrom(IBookListStorage repo)
        {
            if (repo == null)
            {
                throw new ArgumentNullException($"{nameof(repo)} must be not null");
            }

            books = new List <Book>(repo.ReadBooks());
        }
Beispiel #13
0
        /// <summary>
        /// Save this storage to the repo
        /// </summary>
        /// <param name="repo">The repo to store</param>
        /// <exception cref="ArgumentNullException">Throws when repo is null</exception>
        public void SaveTo(IBookListStorage repo)
        {
            if (repo == null)
            {
                throw new ArgumentNullException($"{nameof(repo)} must be not null");
            }

            repo.WriteBooks(books);
        }
        /// <summary>
        /// Initializes an instance of the <see cref="BookListService"/> with the passed book list storage.
        /// </summary>
        /// <param name="bookListStorage">An instance of an interface.</param>
        /// <exception cref="ArgumentNullException">
        /// Thrown when <paramref name="bookListStorage"/> equal to null.
        /// </exception>
        public BookListService(IBookListStorage bookListStorage)
        {
            if (ReferenceEquals(bookListStorage, null))
            {
                throw new ArgumentNullException(nameof(bookListStorage));
            }

            Books            = new List <Book>();
            _bookListStorage = bookListStorage;
        }
Beispiel #15
0
        /// <summary>
        /// Saving books to binary file
        /// </summary>
        /// <param name="storage">Storage provider</param>
        /// <exception cref="ArgumentNullException">Argument must not be null</exception>
        public void SaveToStorage(IBookListStorage storage)
        {
            if (storage == null)
            {
                throw new ArgumentNullException(nameof(storage));
            }

            storage.Save(books);
            logger.Debug($"List of books saved to the storage");
        }
Beispiel #16
0
        /// <summary>
        /// Constructor of book
        /// </summary>
        /// <param name="bookStorage">object of <see cref="IBookListStorage"/></param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="bookStorage"/>if it is null.
        /// </exception>
        public BookService(IBookListStorage bookStorage)
        {
            if (bookStorage is null)
            {
                throw new ArgumentNullException(nameof(bookStorage));
            }

            this.bookStorage = bookStorage;
            listBooks        = this.bookStorage.LoadBook().ToList();
        }
Beispiel #17
0
        /// <summary>
        /// Save list of books to the storage.
        /// </summary>
        /// <param name="storage"> Storage to save the list of books. </param>
        public void Save(IBookListStorage storage)
        {
            if (storage == null)
            {
                this.logger.Error("Refused to store the books. Invalid storage.", new ArgumentNullException(nameof(storage)), storage);
                throw new ArgumentNullException(nameof(storage));
            }

            storage.Save(this.books);
            this.logger.Debug("Books were successfully saved in the storage.");
        }
 public void SaveIntoStorage(IBookListStorage storage)
 {
     try
     {
         storage.SaveBooks(BookList);
     }
     catch (Exception ex)
     {
         throw new BooksStorageException("Error was occured while saving books from the storage", ex);
     }
 }
Beispiel #19
0
        /// <summary>
        /// Loads from storage.
        /// </summary>
        /// <param name="storage">The storage.</param>
        /// <exception cref="ArgumentNullException">storage</exception>
        public void LoadFromStorage(IBookListStorage storage)
        {
            Logger.Info($"Loading from storage!");
            if (ReferenceEquals(storage, null))
            {
                throw new ArgumentNullException($"{nameof(storage)} is null");
            }

            BookList = storage.LoadFromStorage();
            Logger.Info($"Loading from storage completed!");
        }
Beispiel #20
0
        /// <summary>
        /// Saves the in storage.
        /// </summary>
        /// <param name="storage">The storage.</param>
        /// <exception cref="ArgumentNullException">Throw when the storage is null</exception>
        public void SaveInStorage(IBookListStorage storage)
        {
            if (ReferenceEquals(storage, null))
            {
                throw new ArgumentNullException($"Argument {nameof(storage)} is null");
            }

            storage.SaveBooks(Books);

            logger.Debug($"List of books saved successfully!\n");
        }
Beispiel #21
0
        /// <summary>
        /// Saves to storage.
        /// </summary>
        /// <param name="storage">The storage.</param>
        /// <exception cref="ArgumentNullException">storage</exception>
        public void SaveToStorage(IBookListStorage storage)
        {
            Logger.Info($"Saving to storage started!");
            if (ReferenceEquals(storage, null))
            {
                Logger.Error($"{nameof(storage)} is null!");
                throw new ArgumentNullException($"{nameof(storage)} is null");
            }

            storage.SaveToStorage(BookList);
            Logger.Info($"Saving to storage completed!");
        }
Beispiel #22
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.");
     }
 }
Beispiel #23
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");
        }
        //private IBookListStorage<Book> BookListStorage { get; }

        #endregion

        #region .ctor

        /// <summary>
        /// .ctor
        /// </summary>
        /// <param name="bookListStorage">List of books.</param>

        public BookListService(IBookListStorage <Book> bookListStorage)
        {
            if (bookListStorage == null)
            {
                throw new ArgumentNullException();
            }

            try
            {
                BookList = (List <Book>)bookListStorage.ReadBooks();
            }
            catch (Exception ex)
            {
                throw new BookListServiceException("Unable to download from file: ", ex);
            }
        }
Beispiel #25
0
        /// <summary>
        /// Loads from storage.
        /// </summary>
        /// <param name="storage">The storage.</param>
        /// <exception cref="ArgumentNullException">Throw when the storage is null</exception>
        public void LoadFromStorage(IBookListStorage storage)
        {
            if (ReferenceEquals(storage, null))
            {
                throw new ArgumentNullException($"Argument {nameof(storage)} is null");
            }

            Books.Clear();

            foreach (var book in storage.LoadBooks())
            {
                AddBook(book);
            }

            logger.Debug($"List of books loaded successfully!\n");
        }
Beispiel #26
0
 /// <summary>
 /// Stores books to <paramref name="storage"/>
 /// </summary>
 /// <exception cref="ArgumentNullException">Throws if <paramref name="storage"/>
 ///  is null</exception>
 /// <exception cref="BookListException">Throws if some errors while storing books
 /// if <paramref name="storage"/></exception>
 public void StoreBooksList(IBookListStorage storage)
 {
     if (ReferenceEquals(storage, null))
     {
         throw new ArgumentNullException();
     }
     try
     {
         logger.Debug("Saving book list.");
         storage.StoreBookList(list);
     }
     catch (Exception ex)
     {
         logger.Warn(ex, "An error has occurred during saving book's list to storage.");
         throw new BookListException($"An error has occurred during saving book's list to {nameof(storage)}.", ex);
     }
 }
        public void GetFromStorage(IBookListStorage storage)
        {
            List <Book> gettedBooks;

            try
            {
                gettedBooks = storage.GetBooks();
            }
            catch (Exception ex)
            {
                throw new BooksStorageException("Error was occured while getting books from the storage", ex);
            }

            foreach (Book book in gettedBooks)
            {
                Add(book);
            }
        }
        /// <summary>
        /// Saves list of books into <see cref="storage"/>.
        /// </summary>
        /// <param name="storage"> Storage of the list of books. </param>
        /// <exception cref="ArgumentNullException">Thrown when storage is null</exception>
        public void Save(IBookListStorage storage)
        {
            if (storage == null)
            {
                Logger?.Info("Unhandled ArgumentNullException:");
                Logger?.Error("Argument \"storage\" in Save method can't be null.");
                throw new ArgumentNullException(nameof(storage));
            }

            try
            {
                storage.Save(_books);
            }
            catch (Exception ex)
            {
                Logger?.Info("Unhandled Exception:");
                Logger?.Error("Some error while saving books to storage occuried.");
                throw;
            }
        }
Beispiel #29
0
 public void SaveStorage(IBookListStorage storageExtern)
 {
     storageExtern.SaveStorage(books);
 }
Beispiel #30
0
 public void LoadStorage(IBookListStorage storageExtern)
 {
     storageExtern.LoadStorage(out books);
 }
 public BookListService(IBookListStorage bookListStorage)
 {
     _bookListStorage = bookListStorage;
     _books=new List<Book>();
 }