/// <summary> /// Save collection to file /// </summary> /// <param name="filePath"></param> /// <param name="books"></param> /// <returns></returns> private static bool SaveBookCollection(string filePath, ICollection <Book> books) { IBookReadWrite bookReadWrite = new BookBinaryReadWrite(filePath); try { bookReadWrite.WriteCollection(books); logger.Info("Successfully saved to file"); return(true); } catch (Exception ex) { logger.Warn($"Write book collection to file fails: {ex}"); return(false); } }
/// <summary> /// Reads collection from file /// </summary> /// <param name="filePath"></param> /// <returns></returns> private static ICollection <Book> ReadBookCollection(string filePath) { IBookReadWrite bookReadWrite = new BookBinaryReadWrite(filePath); ICollection <Book> booksCollection = new List <Book>(); try { booksCollection = bookReadWrite.ReadCollection(); logger.Info($"Book collection successfully readed from {filePath}"); } catch (Exception ex) { logger.Warn($"Read book collection exceprion: {ex}"); } return(new BookListStorage(booksCollection)); }