コード例 #1
0
 public BookListStorage(IBookStorage storage, string file) : this(storage)
 {
     if (!string.IsNullOrWhiteSpace(file))
     {
         storage.FilePath = file;
     }
 }
コード例 #2
0
        public AuthorQuery(IBookStorage bookStorage)
        {
            _bookStorage = bookStorage;

            FieldAsync <AuthorType, Abstractions.Types.Author?>(
                "findAuthor",
                "Find author by identifier",
                new QueryArguments {
                new QueryArgument(typeof(NonNullGraphType <IntGraphType>))
                {
                    Name        = "id",
                    Description = "Author's identifier"
                }
            },
                resolve: FindAuthorResolver);

            FieldAsync <NonNullGraphType <ListGraphType <AuthorType> >, IEnumerable <Abstractions.Types.Author> >(
                "findAuthors",
                "Find all authors by template of author's name",
                new QueryArguments
            {
                new QueryArgument(typeof(NonNullGraphType <StringGraphType>))
                {
                    Name        = "Name",
                    Description = "Name template"
                }
            },
                resolve: FindAuthorsResolver);
        }
コード例 #3
0
 public void Load(IBookStorage storage)
 {
     foreach (var book in storage.Load())
     {
         AddBook(book);
     }
 }
コード例 #4
0
        public BookQuery(IBookStorage bookStorage)
        {
            _bookStorage = bookStorage;

            FieldAsync <BookType, Abstractions.Types.Book?>(
                "findBook",
                "Find book by identifier",
                new QueryArguments {
                new QueryArgument(typeof(NonNullGraphType <IntGraphType>))
                {
                    Name        = "id",
                    Description = "Identifier of the book"
                }
            },
                FindBookResolver);

            FieldAsync <NonNullGraphType <ListGraphType <BookType> >, IEnumerable <Abstractions.Types.Book> >(
                "findBooks",
                "Find books by filter",
                new QueryArguments {
                new QueryArgument(typeof(NonNullGraphType <GetBooksFilterType>))
                {
                    Name        = "filter",
                    Description = "Filter"
                }
            },
                FindBooksResolver);
        }
コード例 #5
0
 /// <summary>
 /// Loads from storage.
 /// </summary>
 /// <param name="storage">Storage.</param>
 public void ReadFromStorage(IBookStorage storage)
 {
     if (ReferenceEquals(storage, null))
     {
         throw new ArgumentNullException($"{nameof(storage)} is null");
     }
     bookList = storage.ReadFromStorage();
 }
コード例 #6
0
 /// <summary>
 /// Loads from storage.
 /// </summary>
 /// <param name="storage">Storage.</param>
 public void LoadFromStorage(IBookStorage storage)
 {
     if (storage == null)
     {
         throw new ArgumentNullException($"{nameof(storage)} is invalid!");
     }
     bookList = new List <Book>(storage.ReadFromStorage());
 }
コード例 #7
0
 /// <summary>
 /// Saves to storage.
 /// </summary>
 /// <param name="storage">Storage.</param>
 public void SaveToStorage(IBookStorage storage)
 {
     if (storage == null)
     {
         throw new ArgumentNullException($"{nameof(storage)} is invalid!");
     }
     storage.WriteToStorage(bookList);
 }
コード例 #8
0
 public BookProcessor(IBookDataProvider bookDataProvider,
                      IBookParser bookParser,
                      IBookStorage bookStorage)
 {
     _bookDataProvider = bookDataProvider;
     _bookParser       = bookParser;
     _bookStorage      = bookStorage;
 }
コード例 #9
0
 /// <summary>
 /// Ctor for bookStorage's initialization
 /// </summary>
 /// <param name="bookStorage"></param>
 public BookService(IBookStorage bookStorage)
 {
     if (ReferenceEquals(bookStorage, null))
     {
         throw new ArgumentException();
     }
     this.bookStorage = bookStorage;
 }
コード例 #10
0
 /// <summary>
 /// Save collection of books to storage.
 /// </summary>
 /// <param name="storage">Storage to save.</param>
 public void SaveToStorage(IBookStorage storage)
 {
     if (ReferenceEquals(storage, null))
     {
         throw new ArgumentException($"{nameof(storage)} is null.");
     }
     storage.WriteToStorage(bookList);
 }
コード例 #11
0
 Bloom.Book.Book BookFactory(BookInfo bookInfo, IBookStorage storage, bool editable)
 {
     return(new Bloom.Book.Book(bookInfo, storage, null, new CollectionSettings(new NewCollectionSettings()
     {
         PathToSettingsFile = CollectionSettings.GetPathForNewSettings(_folder.Path, "test"), Language1Iso639Code = "xyz"
     }),
                                new PageSelection(),
                                new PageListChangedEvent(), new BookRefreshEvent()));
 }
コード例 #12
0
        /// <summary>
        /// Ctor of BookService with the passed parameter.
        /// </summary>
        /// <param name="bookStorage">Storage implementation.</param>
        public BookListService(IBookStorage storage)
        {
            if (ReferenceEquals(storage, null))
            {
                throw new ArgumentNullException("storage is null");
            }

            this.storage = storage;
        }
コード例 #13
0
        public BookListStorage(IBookStorage storage)
        {
            if (storage == null)
            {
                throw new ArgumentNullException("storage", "Try to set null as storage.");
            }

            this.CurrentStorage = storage;
        }
コード例 #14
0
        public void Setup()
        {
            _bookDataProviderFake = A.Fake <IBookDataProvider>(options => options.Strict());

            _bookParserFake = A.Fake <IBookParser>(options => options.Strict());

            _bookStorageFake = A.Fake <IBookStorage>(options => options.Strict());

            _bookProcessor = new BookProcessor(_bookDataProviderFake, _bookParserFake, _bookStorageFake);
        }
コード例 #15
0
 public void LoadBooksFromStorage(IBookStorage storage)
 {
     foreach (Book book in storage.Load())
     {
         if (!books.Contains(book))
         {
             books.Add(book);
         }
     }
 }
コード例 #16
0
 /// <summary>
 /// Implement BookListService.
 /// </summary>
 /// <param name="books"></param>
 /// <param name="filePathForStorage"></param>
 public BookListService(Book[] books, IBookStorage storage, string filePathForStorage = null)
 {
     this.collection    = new List <Book>();
     this.booksToAdd    = new List <Book>();
     this.booksToRemove = new List <Book>();
     this.storage       = new BookListStorage(storage, filePathForStorage);
     foreach (Book b in books)
     {
         this.AddBook(b);
     }
 }
コード例 #17
0
        /// <summary>   Saves the books into storage. </summary>
        /// <exception cref="ArgumentNullException">    Thrown when one or more required arguments are
        ///                                             null. </exception>
        /// <param name="storage">  The storage. </param>
        public void SaveBooksIntoStorage(IBookStorage storage)
        {
            if (storage == null)
            {
                logger.WriteError($"{nameof(storage)} is null");
                throw new ArgumentNullException($"{nameof(storage)} cant be a null");
            }

            storage.SaveBooks(Books);
            logger.WriteInfo($"Books added to {nameof(storage)}");
        }
コード例 #18
0
 public void LoadBooks(IBookStorage bs)
 {
     try
     {
         books = bs.Load();
     }
     catch (SerializationException e)
     {
         logger.Error("Can't load books." + e.Message);
         throw;
     }
 }
コード例 #19
0
        /// <summary>
        /// Load collection of books from storage.
        /// </summary>
        /// <param name="storage">Storage to load.</param>
        public void LoadFromStorage(IBookStorage storage)
        {
            if (ReferenceEquals(storage, null))
            {
                throw new ArgumentException($"{nameof(storage)} is null.");
            }
            IEnumerable <Book> bookList = storage.ReadFromStorage();

            foreach (Book book in bookList)
            {
                this.AddBook(book);
            }
        }
コード例 #20
0
 public void SaveBooks(IBookStorage bs)
 {
     try
     {
         bs.Save(books);
     }
     catch (SerializationException e)
     {
         logger.Error("Can't save books." + e.Message);
         throw;
     }
     
 }
コード例 #21
0
        public static void FillContents(IBookStorage bookStorage, BookViewModel book)
        {
            var pages = PageFacade.FindByBookId(book.ID).OrderBy(p => p.PageIndex);

            bookStorage.AccessDispatcherObject(() => book.ClearContents());

            bookStorage.AccessDispatcherObject(() =>
            {
                foreach (var page in pages)
                {
                    book.AddPage(page);
                }
            });
        }
コード例 #22
0
        public void ViewBookAction(string book, IBookStorage catalog)
        {
            Book currentBook = catalog.GetByName(book);

            string[] viewString = { $"Book name:{currentBook.Name}",
                                    $"Book page:{currentBook.Pages}",
                                    $"Book Author:{currentBook.Author}",
                                    $"Book binding:{currentBook.Binding}",
                                    $"Book weight:{currentBook.Weight}",
                                    $"Book price:{currentBook.Price}",
                                    $"Book text:{currentBook.Text}",
                                    $"Book description:{currentBook.GetDescription()}" };
            _view.Show(viewString);
            _view.Show(new string[] { "Type 'Delete' for deleting book",
                                      "Type 'sell', to sell the book",
                                      "Type 'find' to find info from text in the book",
                                      "Type 'back' to return back" });
            string command = Console.ReadLine();

            switch (command)
            {
            case "Delete":
                catalog.DeleteBook(currentBook);
                _view.Show("Current book was deleted, press Enter to return back");
                break;

            case "find":
                _view.Show("Type word to search:");
                string word = Console.ReadLine();
                _view.Show(new string[] { currentBook.SearchInfo(word),
                                          "press Enter to return back" });
                break;

            case "sell":
                Sales sales = ModelStorage.GetSales();
                sales.AddBook(currentBook);
                catalog.DeleteBook(currentBook);
                _view.Show(new string[] { $"Book {currentBook.Name} was sold",
                                          "press Enter to return back" });
                break;

            default:
                break;
            }
            Console.ReadLine();
            Route nextController = _routes.FirstOrDefault(b => b.Id == "back");

            redirect(nextController.Action, nextController.Controller, null);
        }
コード例 #23
0
 public void Save(IBookStorage storage)
 {
     if (ReferenceEquals(storage, null))
     {
         throw new ArgumentNullException();
     }
     try
     {
         storage.SaveBooks(booksStorage);
     }
     catch (IOException ex)
     {
         throw new IOException("Can't save books", ex);
     }
 }
コード例 #24
0
 public void Load(IBookStorage storage)
 {
     if (ReferenceEquals(storage, null))
     {
         throw new ArgumentNullException();
     }
     try
     {
         booksStorage = new SortedSet <Book>(storage.LoadBooks());
     }
     catch (IOException ex)
     {
         throw new IOException("Can't load books", ex);
     }
 }
コード例 #25
0
        /// <summary>
        /// Creation of a service instance.
        /// </summary>
        /// <param name="bookStorage">Book storage.</param>
        /// <exception cref="ArgumentNullException">
        /// The exception that is thrown when a null argument <paramref name="bookStorage"/> is passed.
        /// </exception>
        public BookListService(IBookStorage bookStorage)
        {
            _bookStorage = bookStorage ?? throw new ArgumentNullException(nameof(bookStorage));
            _logger      = LoggerCreater.GetLogger(nameof(BookListService));

            try
            {
                _books.AddRange(_bookStorage.GetBooks().Select(bookDal => bookDal.ToBook()));
            }
            catch (BookStorageException e)
            {
                throw new BookServiceException("An error occurred while reading from the repository.", e);
            }

            _logger.Info("Service was created");
        }
コード例 #26
0
        /// <summary>
        /// Load books from file.
        /// </summary>
        /// <param name="bookStorage">has method for load books</param>
        public void LoadBooksFromFile(IBookStorage bookStorage)
        {
            if (bookStorage == null)
            {
                throw new ArgumentNullException(nameof(bookStorage));
            }

            try
            {
                Books = bookStorage.ReadBooks().ToList();
            }
            catch (Exception ex)
            {
                Logger.Error(string.Empty, ex);
                throw;
            }
        }
コード例 #27
0
        public BookMutation(IBookStorage bookStorage)
        {
            _bookStorage = bookStorage;

            FieldAsync <BookType?, Abstractions.Types.Book?>(
                "addBook",
                "Add book to the storage",
                new QueryArguments
            {
                new QueryArgument(typeof(NonNullGraphType <AddBookRequestType>))
                {
                    Name        = "request",
                    Description = "Request for adding book to storage"
                }
            },
                resolve: AddBookResolver);
        }
コード例 #28
0
        /// <summary>
        /// Write books to file.
        /// </summary>
        /// <param name="bookStorage">has method for save books</param>
        public void SaveBooksToFile(IBookStorage bookStorage)
        {
            if (bookStorage == null)
            {
                throw new ArgumentNullException(nameof(bookStorage));
            }

            try
            {
                bookStorage.WriteBooks(Books);
            }
            catch (Exception ex)
            {
                Logger.Error(string.Empty, ex);
                throw;
            }
        }
コード例 #29
0
        /// <summary>
        /// Implement BookListService.
        /// </summary>
        /// <param name="books"></param>
        /// <param name="filePathForStorage"></param>
        public BookListService(Book[] books, IBookStorage storage, string filePathForStorage = null)
        {
            logger.Trace("User initialized BookListService object");
            if (filePathForStorage == null)
            {
                logger.Warn("User didnt set filePathForStorage");
            }

            this.collection    = new List <Book>();
            this.booksToAdd    = new List <Book>();
            this.booksToRemove = new List <Book>();
            this.storage       = new BookListStorage(storage, filePathForStorage) ?? throw new ArgumentNullException("storage", "Try to set storage as null.");
            foreach (Book b in books)
            {
                this.AddBook(b);
            }
        }
コード例 #30
0
        public AuthorMutation(IBookStorage bookStorage)
        {
            _bookStorage = bookStorage;

            FieldAsync <AuthorType?, Abstractions.Types.Author?>(
                "addAuthor",
                "Add author to storage",
                new QueryArguments
            {
                new QueryArgument(typeof(AddAuthorRequestType))
                {
                    Name        = "request",
                    Description = "Add author request",
                },
            },
                resolve: AddAuthorResolver);
        }
コード例 #31
0
 /// <summary>
 /// save set to the repo
 /// </summary>
 public void SaveToRepo(IBookStorage storage)
 {
     try
     {
         if (storage == null)
         {
             throw new ArgumentNullException(nameof(storage), "storage cant be null");
         }
     }
     catch (ArgumentNullException exception)
     {
         logger.Info(exception.Message);
         logger.Trace(exception.StackTrace);
         throw;
     }
     storage.Save(bookSet);
 }
コード例 #32
0
 /// <summary>
 /// load set from repo
 /// </summary>
 /// <param name="storage"></param>
 public void LoadFromRepo(IBookStorage storage)
 {
     try
     {
         if (storage == null)
         {
             throw new ArgumentNullException(nameof(storage), "storage cant be null");
         }
     }
     catch (ArgumentNullException exception)
     {
         logger.Info(exception.Message);
         logger.Trace(exception.StackTrace);
         throw;
     }
     bookSet = new SortedSet <Book>(storage.Load());
 }
コード例 #33
0
ファイル: Book.cs プロジェクト: jorik041/BloomDesktop
        public Book(BookInfo info, IBookStorage storage, ITemplateFinder templateFinder,
		   CollectionSettings collectionSettings, HtmlThumbNailer thumbnailProvider,
			PageSelection pageSelection,
			PageListChangedEvent pageListChangedEvent,
			BookRefreshEvent bookRefreshEvent)
        {
            BookInfo = info;

            Guard.AgainstNull(storage,"storage");

            // This allows the _storage to
            storage.MetaData = info;

            _storage = storage;

            //this is a hack to keep these two in sync (in one direction)
            _storage.FolderPathChanged +=(x,y)=>BookInfo.FolderPath = _storage.FolderPath;

            _templateFinder = templateFinder;

            _collectionSettings = collectionSettings;

            _thumbnailProvider = thumbnailProvider;
            _pageSelection = pageSelection;
            _pageListChangedEvent = pageListChangedEvent;
            _bookRefreshEvent = bookRefreshEvent;
            _bookData = new BookData(OurHtmlDom,
                    _collectionSettings, UpdateImageMetadataAttributes);

            if (IsEditable && !HasFatalError)
            {
                _bookData.SynchronizeDataItemsThroughoutDOM();

                WriteLanguageDisplayStyleSheet(); //NB: if you try to do this on a file that's in program files, access will be denied
                OurHtmlDom.AddStyleSheet(@"languageDisplay.css");
            }

            FixBookIdAndLineageIfNeeded();
            _storage.Dom.RemoveExtraContentTypesMetas();
            Guard.Against(OurHtmlDom.RawDom.InnerXml=="","Bloom could not parse the xhtml of this document");
        }
コード例 #34
0
 Bloom.Book.Book BookFactory(BookInfo bookInfo, IBookStorage storage, bool editable)
 {
     return new Bloom.Book.Book(bookInfo,  storage, null, new CollectionSettings(new NewCollectionSettings() { PathToSettingsFile = CollectionSettings.GetPathForNewSettings(_folder.Path, "test"),  Language1Iso639Code = "xyz" }), null,
                                               new PageSelection(),
                                               new PageListChangedEvent(), new BookRefreshEvent());
 }
コード例 #35
0
ファイル: BookService.cs プロジェクト: robzhu/Library.WebApi
 public BookService( IBookStorage bookStorage, IAuthorRepository authorRepo, IISBNLookupService isbnLookupService )
 {
     BookStorage = bookStorage;
     AuthorRepository = authorRepo;
     ISBNService = isbnLookupService;
 }
コード例 #36
0
ファイル: Book.cs プロジェクト: BloomBooks/BloomDesktop
        public Book(BookInfo info, IBookStorage storage, ITemplateFinder templateFinder,
		   CollectionSettings collectionSettings,
			PageSelection pageSelection,
			PageListChangedEvent pageListChangedEvent,
			BookRefreshEvent bookRefreshEvent)
        {
            BookInfo = info;
            UserPrefs = UserPrefs.LoadOrMakeNew(Path.Combine(info.FolderPath, "book.userPrefs"));

            Guard.AgainstNull(storage,"storage");

            // This allows the _storage to
            storage.MetaData = info;

            _storage = storage;

            //this is a hack to keep these two in sync (in one direction)
            _storage.FolderPathChanged += _storage_FolderPathChanged;

            _templateFinder = templateFinder;

            _collectionSettings = collectionSettings;

            _pageSelection = pageSelection;
            _pageListChangedEvent = pageListChangedEvent;
            _bookRefreshEvent = bookRefreshEvent;
            _bookData = new BookData(OurHtmlDom,
                    _collectionSettings, UpdateImageMetadataAttributes);

            InjectStringListingActiveLanguagesOfBook();

            if (!HasFatalError && IsEditable)
            {
                _bookData.SynchronizeDataItemsThroughoutDOM();
            }

            //if we're showing the user a shell/template book, pick a color for it
            //If it is editable, then we don't want to change to the next color, we
            //want to use the color that we used for the sample shell/template we
            //showed them previously.
            if (!info.IsEditable)
            {
                Book.SelectNextCoverColor(); // we only increment when showing a template or shell
                InitCoverColor();
            }

            // If it doesn't already have a cover color give it one.
            if (OurHtmlDom.SafeSelectNodes("//head/style/text()[contains(., 'coverColor')]").Count == 0)
            {
                InitCoverColor(); // should use the same color as what they saw in the preview of the template/shell
            }
            FixBookIdAndLineageIfNeeded();
            _storage.Dom.RemoveExtraBookTitles();
            _storage.Dom.RemoveExtraContentTypesMetas();
            Guard.Against(OurHtmlDom.RawDom.InnerXml=="","Bloom could not parse the xhtml of this document");
        }