/// <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> /// 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; }
/// <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); }
/// <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()); }
/// <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); }
public BookListService(IBookListStorage bookListStorage) { if (ReferenceEquals(bookListStorage, null)) { throw new ArgumentException(); } this.bookListStorage = bookListStorage; }
/// <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); }
public void GetBookListFromStorage(IBookListStorage storage) { IEnumerable <Book> bookList = storage.ReadFromStorage(); foreach (Book book in bookList) { this.AddBook(book); } }
public void Save(IBookListStorage bookListStorage) { if (ReferenceEquals(bookListStorage, null)) { throw new ArgumentNullException(); } bookListStorage.SaveBooks(Books); }
/// <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()); }
/// <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; }
/// <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"); }
/// <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(); }
/// <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); } }
/// <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!"); }
/// <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"); }
/// <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!"); }
/// <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."); } }
/// <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); } }
/// <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"); }
/// <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; } }
public void SaveStorage(IBookListStorage storageExtern) { storageExtern.SaveStorage(books); }
public void LoadStorage(IBookListStorage storageExtern) { storageExtern.LoadStorage(out books); }
public BookListService(IBookListStorage bookListStorage) { _bookListStorage = bookListStorage; _books=new List<Book>(); }