예제 #1
0
 public PageCompositor(BookModel book, int fontSize, Size pageSize, IList<BookImage> images)
 {
     _book = book;
     _book.Type = "fb2";
     _fontSize = fontSize;
     _pageSize = pageSize;
     _images = images;
 }
예제 #2
0
 public ReadController(IBookView page, BookModel book, string bookId, int offset = 0)
 {
     var data = new BookData(bookId);
     _bookView = page;
     _offset = offset;
     _bookModel = book;
     _images = data.LoadImages().ToList();
     _pageLoader = new PageCompositor(_bookModel, (AppSettings.Default.FontSettings.FontSize), new Size(page.GetSize().Width - AppSettings.Default.Margin.Left - AppSettings.Default.Margin.Right, page.GetSize().Height - AppSettings.Default.Margin.Top - AppSettings.Default.Margin.Bottom), _images);
     BookId = bookId;
 }
예제 #3
0
 public Stream GetOriginalBook(BookModel book)
 {
     var destinationStream = new MemoryStream();
     using (var file = FileStorage.Instance.GetFile(book.GetBookPath()))
     {
         using (file.Lock())
         {
             file.Reader.BaseStream.CopyTo(destinationStream);
         }
     }
     destinationStream.Seek(0, SeekOrigin.Begin);
     return destinationStream;
 }
예제 #4
0
        public Task<List<BookSearchResult>> Search(BookModel book, string query, int count)
        {
            if (string.IsNullOrEmpty(query) || book == null)
                return Task<List<BookSearchResult>>.Factory.StartNew(() => new List<BookSearchResult>());

            _bookTokenIterator?.Dispose();

            _book = book;
            _bookTokenIterator = new BookTokenIterator(_book.GetTokensPath(), TokensTool.GetTokens(_book.BookID));

            _query = PrepareQuery(query);

            return Task<List<BookSearchResult>>
                .Factory.StartNew(() => Load(_bookTokenIterator, _query, count));
        }
예제 #5
0
        public static void SaveTokens(BookModel book, IBookSummaryParser parser)
        {
            var tokens = parser.GetTokenParser().GetTokens().ToList();
            var positions = SaveTokensWithPosition(book.GetTokensPath(), tokens);

            SaveTokenPosition(book.GetTokensRefPath(), positions);

            book.TokenCount = positions.Count;
            book.WordCount = tokens.Count(t => t is TextToken);
            book.CurrentTokenID = Math.Min(tokens.Count - 1, book.CurrentTokenID);

            parser.BuildChapters();

            SaveAnchors(book.BookID, book.GetAnchorsPath(), parser.Anchors, tokens);

            SaveChapters(book.BookID, book.GetChaptersPath(), parser.Chapters, tokens);
           
            SaveInfo(book.GetFolderPath(), book.TokenCount, book.WordCount);
        }
예제 #6
0
        public string GetLastParagraphByToken(BookModel book, int tokenOffset, out string pointer)
        {
            var result = new List<string>();

            using (var tokenIterator = new BookTokenIterator(book.GetTokensPath(), TokensTool.GetTokens(book.BookID)))
            {                
                var token = FindNewToken(tokenOffset, tokenIterator);
                pointer = token.Pointer;
                var tokenId = token.ID;
                tokenIterator.MoveTo(tokenId);
                while (tokenIterator.MoveNext())
                {
                    if (tokenIterator.Current is TagOpenToken && result.Count > 0)
                        break;

                    var textToken = tokenIterator.Current as TextToken;
                    if (textToken == null)
                        continue;                    
                    result.Add(textToken.Text);                    
                }
            }
            return string.Join(" ", result);
        }
예제 #7
0
        public string GetText(BookModel book, int tokenOffset, int wordsCount, out int lastTokenId)
        {
            lastTokenId = -1;
            var result = new List<string>();
            
            using (var tokenIterator = new BookTokenIterator(book.GetTokensPath(), TokensTool.GetTokens(book.BookID)))
            {
                int words = 0;
                tokenIterator.MoveTo(tokenOffset);
                while (tokenIterator.MoveNext() && words < wordsCount)
                {
                    if (tokenIterator.Current is NewPageToken && result.Count > 0)
                        break;

                    var textToken = tokenIterator.Current as TextToken;
                    if (textToken == null)
                        continue;
                    lastTokenId = textToken.ID;
                    result.Add(textToken.Text);
                    words++;
                }
            }
            return string.Join(" ", result);
        }
예제 #8
0
        private static BookModel CreateBook(Book item, BookSummary bookSummary)
        {
            var trial = !(item.IsFreeBook || item.IsMyBook);
            var book = new BookModel
            {
                BookID = item.Id.ToString(),
                Title = bookSummary.Title.SafeSubstring(1024),
                Author = bookSummary.AuthorName.SafeSubstring(1024),
                Type = item.Type,
                Hidden = trial,
                Trial = trial,
                Deleted = false,
                CreatedDate = DateTime.Now.ToFileTimeUtc(),
                UniqueID = bookSummary.UniqueId.SafeSubstring(1024),
                Description = bookSummary.Description,
                Language = bookSummary.Language,
                Url = item.Url,
               // CatalogItemId = item.CatalogItemId
            };

            return book;
        }
예제 #9
0
 private void ReplaceBookInSettings(BookModel book)
 {
     var tmpBook = AppSettings.Default.CurrentBook;
     AppSettings.Default.CurrentBook = book;
     if (tmpBook != null && tmpBook.BookID != book.BookID)
         AppSettings.Default.CurrentTokenOffset = 0;
 }
예제 #10
0
 public BookSearch(BookModel book)
 {
     _book = book;
     _bookTokenIterator = new BookTokenIterator(book.GetTokensPath(), TokensTool.GetTokens(book.BookID));
 }