示例#1
0
        /// <summary>
        /// Adds a set of new file-based books to the database.
        /// </summary>
        /// <param name="rootPath">The root path to the folder containing the file-based books</param>
        /// <param name="path">The path to the folder containg the file-based books,
        /// starting from the root path</param>
        public void BulkAddNewFilesBasedBooks(string rootPath, string path)
        {
            bool allBooksReadable = true;
            List <IDiscEntry> bulkLoadFilesList;

            try
            {
                bulkLoadFilesList = new List <IDiscEntry>();
                IDiscEntry bulkLoadEntry = new Folder(rootPath, path);

                bulkLoadEntry.BulkLoadSingleFiles(bulkLoadFilesList);
            }

            catch (Exception ex)
            {
                throw new BookEntitiesException(ex.Message, ex);
            }

            foreach (IDiscEntry newFile in bulkLoadFilesList)
            {
                try
                {
                    Book newBook = new Book(newFile, newFile.Path, false, newFile.Name);
                    DatabaseManager.Instance.PerformDataUpdate(new UpdateStoreAction(newBook));
                    newBook.ReadStructureFromDisc();

                    booksData.AddNewBook(newBook);
                }

                catch (Exception)
                {
                    allBooksReadable = false;
                }
            }

            if (allBooksReadable == false)
            {
                throw new BookEntitiesException("Some of the books could not be read from the disc.", null);
            }
        }