/*============Private Function======*/

        private void AppendNewChapter(Chapter chapter)
        {
            if (BackgroundService.Instance.novelReaderForm != null && BackgroundService.Instance.novelReaderForm.InvokeRequired)
            {
                BackgroundService.Instance.novelReaderForm.BeginInvoke(new System.Windows.Forms.MethodInvoker(delegate
                {
                    _chapters.Add(chapter);
                }));
            }
            else
            {
                _chapters.Add(chapter);
            }
        }
 public Request(string voice, Chapter chapter, string replacementFile = null, string deletetionFile = null, int rate = 0, int priority = 0)
 {
     this._voice = voice;
     this._id = count++;
     this.chapter = chapter;
     this._replacementFile = replacementFile;
     this._deletetionFile = deletetionFile;
     this._rate = rate;
     this._priority = priority;
     this._progress = 0;
     this._takenBy = -1;
     
 }
        /*============Public Function=======*/

        public void Update()
        {
            SetUpdateProgress(0, 0, UpdateState.Checking);
            Source.Source s = SourceManager.GetSource(_novelTitle, 22590, SourceManager.Sources.web69);
            Tuple<string, string>[] menuItems = s.GetMenuURLs();
            int newlyAddedChapter = 0;



            
            for (int i = _chapters.Count; i < menuItems.Length; i++)
            {
                string chapterTitle = menuItems[i].Item1;
                string url = menuItems[i].Item2;

                Chapter newChapter = new Chapter(chapterTitle, _novelTitle, false, i);
                AppendNewChapter(newChapter);
                newlyAddedChapter++;
                SetUpdateProgress(i, menuItems.Length, UpdateState.Fetching);
                string[] novelContent = s.GetChapterContent(chapterTitle, url);
                string chapterLocation = newChapter.GetTextFileLocation();
                System.IO.File.WriteAllLines(chapterLocation, novelContent);
            }
            SetUpdateProgress(0, 0, UpdateState.UpToDate);
            if (BackgroundService.Instance.novelListController.InvokeRequired)
            {
                BackgroundService.Instance.novelListController.BeginInvoke(new System.Windows.Forms.MethodInvoker(delegate
                {
                    NewChapterCount = _newChapterCount + newlyAddedChapter;
                    NotifyPropertyChanged("ChapterCount");
                }));
            }
        }
 private void ReadChapter(Chapter chapter)
 {
     using (StreamReader sr = new StreamReader(chapter.GetTextFileLocation()))
     {
         string chapterText = sr.ReadToEnd();
         rtbChapterTextBox.Text = chapterText;
         chapter.Read = true;
     }
     currentChapter = chapter;
     currentChapterDirty = false;
 }