Ejemplo n.º 1
0
        public static ProgressSpine SpineFromProgress(WordCountItem wordsCount, float position)
        {
            float totalWordCount        = wordsCount.Sum(x => x.Count);
            int   wp                    = (int)(position * totalWordCount / 1000);
            WordCountItemElement result = null;

            foreach (var currentWordsCount in wordsCount)
            {
                if (result == null)
                {
                    result = currentWordsCount;
                }
                else if (result.Count >= wp)
                {
                    break;
                }
                else
                {
                    result = new WordCountItemElement {
                        SpineItemRef = currentWordsCount.SpineItemRef, Count = result.Count + currentWordsCount.Count
                    }
                };
            }

            return(new ProgressSpine {
                TotalWordCount = totalWordCount, Result = result, WordPosition = wp
            });
        }
Ejemplo n.º 2
0
        public static WordCountItem CountWords(EpubBook epubBook, string fileName, string password)
        {
            var countSpines = new WordCountItem();
            var spin        = epubBook.Spine();

            if (spin == null)
            {
                return(countSpines);
            }

            var models = spin.Spines(epubBook.Format.Opf.Manifest);
            var counts = CountHtmlWords(fileName, password).ToDictionary(t => t.Item1, t => t.Item2);

            var result = models.Select(x =>
            {
                var packageDir = Path.GetDirectoryName(epubBook.Format.Ocf.RootFilePath);
                var fullPath   = "/" + FileHelper.FormatPath(packageDir, x.IdRef);
                if (counts.ContainsKey(fullPath))
                {
                    return new WordCountItemElement {
                        SpineItemRef = x, Count = counts[fullPath]
                    }
                }
                ;
                return(new WordCountItemElement {
                    SpineItemRef = x, Count = 0
                });
            });
            var wordCountItem = new WordCountItem();

            wordCountItem.AddRange(result);
            return(wordCountItem);
        }
Ejemplo n.º 3
0
 public ReadingState(int spineCount, int spinePageCount, int pageIndex, int spineIndex, WordCountItem wordCount, bool prePaginated)
 {
     SpineCount = spineCount; SpinePageCount = spinePageCount; PageIndex = pageIndex; SpineIndex = spineIndex; WordCount = wordCount; PrePaginated = prePaginated;
 }