Ejemplo n.º 1
0
        private void BtnOpen(object sender, RoutedEventArgs e)
        {
            var fileDialog = new OpenFileDialog
            {
                RestoreDirectory = true,
                CheckFileExists  = true,
                Multiselect      = false,
                Filter           = "(" + ConfigSevice.ImportBookExt + ")|" + ConfigSevice.ImportBookExt
            };

            if (fileDialog.ShowDialog() != true)
            {
                return;
            }
            SaveCurrentBook();
            LsCatalog.ItemsSource = null;
            TbContent.Text        = "";
            _bookInfo             = null;
            _currentChapter       = null;
            _regexChanged         = false;
            _autoLoad             = false;
            _file = fileDialog.FileName;
            //TbFile.Text = FileHelper.GetFileExtNonePoint(_file);
            new Thread(GetChapters).Start();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// paralell parse chapters info
        /// </summary>
        /// <param name="threadsNumber">how many threads is running at the same time</param>
        /// <param name="match">add ChapterInfo to list if ShortChapterInfo match</param>
        protected void ParseChaptersInfo(Predicate <ShortChapterInfo> match, int threadsNumber)
        {
            IChapterJsonParser jsonParser = new ChapterJsonParser();

            Thread[] threads      = new Thread[threadsNumber];
            int      threadsIndex = 0;

            foreach (var chapter in MangaInfo.ShortChaptersInfo)
            {
                // check if it s match the request
                if (match(chapter))
                {
                    // we use post increament so we just compare this values
                    if (threadsIndex == threadsNumber)
                    {
                        threadsIndex = 0;
                        // start threads
                        foreach (var thread in threads)
                        {
                            thread.Start();
                        }
                        //// wait for thread's work complete
                        //foreach (var thread in threads)
                        //{
                        //    thread.Join();
                        //}
                    }
                    // parse json func
                    ThreadStart parseFunc = () =>
                    {
                        // wait for calling thread wait for end of the parsing


                        // parse data from site
                        var          chapterLocal = chapter;
                        int          id           = Convert.ToInt32(chapterLocal.Id);
                        IChapterInfo info         = jsonParser.GetChapterInfo(id);
                        ChaptersInfo.Add(info);
                    };
                    threads[threadsIndex++] = new Thread(parseFunc);
                }
            }
            // if something left in threads array and yeah there only matched chapters
            if (threadsIndex > 0)
            {
                // threadsIndex is size of the array with useful parseFuncs
                // start threads
                for (int i = 0; i < threadsIndex; i++)
                {
                    threads[i].Start();
                }
                // wait for thread's work complete
                for (int i = 0; i < threadsIndex; i++)
                {
                    threads[i].Join();
                }
            }
        }
Ejemplo n.º 3
0
 private void BtnDel(object sender, RoutedEventArgs e)
 {
     LsCatalog.ItemsSource = null;
     TbContent.Text        = "";
     TbBookName.Text       = "";
     TbChapter.Text        = "";
     _file = "";
     _chapters.Clear();
     _currentChapter = null;
     if (_bookInfo != null && !string.IsNullOrEmpty(_bookInfo.BookId))
     {
         ConfigSevice.DelBook(_bookInfo.BookId);
     }
     _bookInfo = null;
 }
Ejemplo n.º 4
0
        private void LsCatalog_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var item = LsCatalog.SelectedItem as ChaptersInfo;

            if (item != null)
            {
                Chapterpbar.Value = 0;
                _currentChapter   = item;
                var index = _chapters.IndexOf(item);
                try
                {
                    if (index < (_chapters.Count - 1))
                    {
                        var item2 = _chapters[index + 1];
                        TbContent.Text = GetChapterContent(item.LineNum, item2.LineNum - 1);
                    }
                    else
                    {
                        TbContent.Text = GetChapterContent(item.LineNum, -1);
                    }
                }
                catch
                {
                    ReloadBook();
                    return;
                }
                if (_autoLoad)
                {
                    UpdateLayout();
                    var c = _bookInfo.ChapterOffset + TbContent.ViewportHeight;
                    Chapterpbar.Value = c / TbContent.ExtentHeight * 100;
                    TbContent.ScrollToVerticalOffset(c);
                }
                else
                {
                    TbContent.ScrollToHome();
                }
                TbChapter.Text = item.Content;
            }
            TotalCpbar.PercentValue = (LsCatalog.SelectedIndex + 1) / (double)_chapters.Count * 100;
            _autoLoad = false;
            if (LsCatalog.Visibility == Visibility.Visible)
            {
                LsCatalog.Visibility      = Visibility.Collapsed;
                CbCatalogVisble.IsChecked = false;
            }
        }
Ejemplo n.º 5
0
        private void BookOnClick(object sender, MouseButtonEventArgs e)
        {
            var book = (sender as Border).DataContext as BookInfo;

            if (book != null)
            {
                if (_bookInfo == null || _bookInfo.BookId != book.BookId)
                {
                    SaveCurrentBook();
                    _file                 = book.FilePath;
                    _currentChapter       = null;
                    LsCatalog.ItemsSource = null;
                    _bookInfo             = book;
                    _regexChanged         = false;
                    _autoLoad             = true;
                    GetChapters();
                }
            }
            BdBookShelf.Visibility = Visibility.Collapsed;
        }
Ejemplo n.º 6
0
        private void BookOnDel(object sender, MouseButtonEventArgs e)
        {
            var book = (sender as Border).DataContext as BookInfo;

            if (book == null || string.IsNullOrEmpty(book.BookId))
            {
                return;
            }
            ConfigSevice.DelBook(book.BookId);
            if (_bookInfo != null && book.BookId == _bookInfo.BookId)
            {
                _bookInfo             = null;
                LsCatalog.ItemsSource = null;
                TbContent.Text        = "";
                TbBookName.Text       = "";
                TbChapter.Text        = "";
                _file = "";
                _chapters.Clear();
                _currentChapter = null;
            }
            LoadBookShelft();
            e.Handled = true;
        }