示例#1
0
        /// <summary>
        /// Writes the books.
        /// </summary>
        /// <param name="storage">The storage.</param>
        /// <param name="books">The books.</param>
        /// <exception cref="ArgumentNullException">storage in null
        /// or
        /// filePath is null or empty</exception>
        /// <exception cref="CustomException">There is no such storage</exception>
        /// <exception cref="StackTrace"></exception>
        public void WriteBooks(IStogare storage, IEnumerable <Book> books)
        {
            if (storage == null)
            {
                throw new ArgumentNullException($"{nameof(storage)} is null");
            }

            try
            {
                storage.WriteBooks(books.ToList());
            }
            catch (IOException e)
            {
                logger.Log(e, e.Message, LogLevel.Fatal);
                throw new CustomException(e, new StackTrace(e), "There is no such storage");
            }
        }
示例#2
0
        /// <summary>
        /// Reads the books.
        /// </summary>
        /// <param name="storage">The storage.</param>
        /// <returns>
        /// Copy of current collection
        /// </returns>
        /// <exception cref="ArgumentNullException">storage</exception>
        /// <exception cref="CustomException">There is no such storage</exception>
        /// <exception cref="StackTrace"></exception>
        public IEnumerable <Book> ReadBooks(IStogare storage)
        {
            if (storage == null)
            {
                throw new ArgumentNullException($"{nameof(storage)} is null");
            }

            try
            {
                this.books = storage.ReadBooks();
            }
            catch (IOException e)
            {
                logger.Log(e, e.Message, LogLevel.Fatal);
                throw new CustomException(e, new StackTrace(e), "There is no such storage");
            }

            return(this.books.ToList());
        }