Example #1
0
        private IList <XmlNode> makeAuthorNode(Enums.AuthorEnum AuthorType, ref FictionBook fb2, ListView lv)
        {
            FB2DescriptionCorrector fB2Corrector = new FB2DescriptionCorrector(fb2);
            IList <XmlNode>         Authors      = null;
            XmlNode xmlAuthor = null;

            if (lv.Items.Count > 0)
            {
                Authors = new List <XmlNode>(lv.Items.Count);
                foreach (ListViewItem item in lv.Items)
                {
                    string         HPs     = StringProcessing.trimLastTemplateSymbol(item.SubItems[4].Text.Trim(), new Char [] { ',', ';' });
                    IList <string> lHPs    = HPs.Split(new Char [] { ',', ';' });
                    string         Emails  = StringProcessing.trimLastTemplateSymbol(item.SubItems[5].Text.Trim(), new Char [] { ',', ';' });
                    IList <string> lEmails = Emails.Split(new Char [] { ',', ';' });
                    xmlAuthor = fB2Corrector.makeAuthorNode(
                        AuthorType,
                        item.SubItems[1].Text, item.SubItems[2].Text, item.Text, item.SubItems[3].Text,
                        lHPs, lEmails, item.SubItems[6].Text
                        );
                    Authors.Add(xmlAuthor);
                }
            }
            else
            {
                if (AuthorType == Enums.AuthorEnum.AuthorOfBook)
                {
                    Authors   = new List <XmlNode>();
                    xmlAuthor = fB2Corrector.makeAuthorNode(AuthorType, null, null, null, null, null, null, null);
                    Authors.Add(xmlAuthor);
                }
            }
            return(Authors);
        }
        private IList <XmlNode> makeGenreNode(ref FictionBook fb2, ListView lv)
        {
            IList <XmlNode> Genres   = null;
            XmlNode         xmlGenre = null;

            if (lv.Items.Count > 0)
            {
                Genres = new List <XmlNode>(lv.Items.Count);
                FB2DescriptionCorrector fB2Corrector = new FB2DescriptionCorrector(fb2);
                if (lv.Items.Count > 0)
                {
                    foreach (ListViewItem item in lv.Items)
                    {
                        string code = item.Text.Substring(item.Text.IndexOf('(') + 1);
                        xmlGenre = fB2Corrector.makeGenreNode(code.Substring(0, code.Length - 1), item.SubItems[1].Text);
                        Genres.Add(xmlGenre);
                    }
                }
                else
                {
                    xmlGenre = fB2Corrector.makeGenreNode("other", null);
                    Genres.Add(xmlGenre);
                }
            }
            return(Genres);
        }
        private void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            FB2DescriptionCorrector fB2Corrector = null;

            foreach (FB2ItemInfo Info in m_KeywordsFB2InfoList)
            {
                FictionBook fb2 = Info.FictionBook;
                if (fb2 != null)
                {
                    fB2Corrector = new FB2DescriptionCorrector(fb2);
                    fB2Corrector.recoveryDescriptionNode();

                    XmlNode xmlTI = fb2.getTitleInfoNode(TitleInfoEnum.TitleInfo);
                    if (xmlTI != null)
                    {
                        string kw    = string.Empty;
                        string kwOld = fb2.getKeywordsNode(TitleInfoEnum.TitleInfo).InnerText;
                        if (AddRadioButton.Checked)
                        {
                            // добавить новые ключевые слова к существующим
                            kw = !string.IsNullOrWhiteSpace(kwOld) ?
                                 (kwOld + "," + KeywordsTextBox.Text.Trim())
                                                        : KeywordsTextBox.Text.Trim();
                        }
                        else
                        {
                            // заменить существующие ключевые слова на новые
                            kw = KeywordsTextBox.Text.Trim();
                        }
                        xmlTI.ReplaceChild(
                            fB2Corrector.makeKeywordsNode(kw),
                            fb2.getKeywordsNode(TitleInfoEnum.TitleInfo)
                            );

                        // сохранение fb2 файла
                        if (!Directory.Exists(m_TempDir))
                        {
                            Directory.CreateDirectory(m_TempDir);
                        }
                        string NewPath = Info.IsFromZip ? Info.FilePathIfFromZip : Info.FilePathSource;
                        fb2.saveToFB2File(NewPath, false);
                        if (Info.IsFromZip)
                        {
                            WorksWithBooks.zipMoveTempFB2FileTo(m_sharpZipLib, NewPath, Info.FilePathSource);
                        }
                        if (Info.IsFromZip && File.Exists(NewPath))
                        {
                            File.Delete(NewPath);
                        }
                    }
                }
                m_bw.ReportProgress(1);
                ProgressBar.Update();
            }
            Cursor.Current = Cursors.Default;
        }
Example #4
0
        private void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            FB2DescriptionCorrector fB2Corrector = null;

            foreach (FB2ItemInfo Info in m_SequencesFB2InfoList)
            {
                FictionBook fb2 = Info.FictionBook;
                if (fb2 != null)
                {
                    fB2Corrector = new FB2DescriptionCorrector(fb2);
                    fB2Corrector.recoveryDescriptionNode();

                    XmlNode xmlTI = fb2.getTitleInfoNode(TitleInfoEnum.TitleInfo);
                    if (xmlTI != null)
                    {
                        if (RemoveRadioButton.Checked || ReplaceRadioButton.Checked)
                        {
                            // удаление всех Серий
                            foreach (XmlNode node in fb2.getSequencesNode(TitleInfoEnum.TitleInfo))
                            {
                                xmlTI.RemoveChild(node);
                            }
                        }
                        if (AddRadioButton.Checked || ReplaceRadioButton.Checked)
                        {
                            // добавление новой Серии
                            xmlTI.AppendChild(
                                fB2Corrector.makeSequenceNode(SequencesTextBox.Text.Trim(), NumberTextBox.Text.Trim())
                                );
                        }
                        // сохранение fb2 файла
                        if (!Directory.Exists(m_TempDir))
                        {
                            Directory.CreateDirectory(m_TempDir);
                        }
                        string NewPath = Info.IsFromZip ? Info.FilePathIfFromZip : Info.FilePathSource;
                        fb2.saveToFB2File(NewPath, false);
                        if (Info.IsFromZip)
                        {
                            WorksWithBooks.zipMoveTempFB2FileTo(m_sharpZipLib, NewPath, Info.FilePathSource);
                        }
                        if (Info.IsFromZip && File.Exists(NewPath))
                        {
                            File.Delete(NewPath);
                        }
                    }
                }
                m_bw.ReportProgress(1);
                ProgressBar.Update();
            }
            Cursor.Current = Cursors.Default;
        }
Example #5
0
        private void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            FB2DescriptionCorrector fB2Corrector = null;

            foreach (FB2ItemInfo Info in m_LangFB2InfoList)
            {
                FictionBook fb2 = Info.FictionBook;
                if (fb2 != null)
                {
                    fB2Corrector = new FB2DescriptionCorrector(fb2);
                    fB2Corrector.recoveryDescriptionNode();

                    XmlNode xmlTI = fb2.getTitleInfoNode(TitleInfoEnum.TitleInfo);
                    if (xmlTI != null)
                    {
                        xmlTI.ReplaceChild(
                            fB2Corrector.makeLangNode(LangComboBox.Text.Substring(LangComboBox.Text.IndexOf('(') + 1, 2)),
                            fb2.getLangNode(TitleInfoEnum.TitleInfo)
                            );

                        // сохранение fb2 файла
                        if (!Directory.Exists(m_TempDir))
                        {
                            Directory.CreateDirectory(m_TempDir);
                        }
                        string NewPath = Info.IsFromZip ? Info.FilePathIfFromZip : Info.FilePathSource;
                        fb2.saveToFB2File(NewPath, false);
                        if (Info.IsFromZip)
                        {
                            WorksWithBooks.zipMoveTempFB2FileTo(m_sharpZipLib, NewPath, Info.FilePathSource);
                        }
                        if (Info.IsFromZip && File.Exists(NewPath))
                        {
                            File.Delete(NewPath);
                        }
                    }
                }
                m_bw.ReportProgress(1);
                ProgressBar.Update();
            }
            Cursor.Current = Cursors.Default;
        }
Example #6
0
        private void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            FB2DescriptionCorrector fB2Corrector = null;

            foreach (FB2ItemInfo Info in m_AuthorFB2InfoList)
            {
                FictionBook fb2 = Info.FictionBook;
                if (fb2 != null)
                {
                    // восстанавление раздела description до структуры с необходимыми элементами для валидности
                    fB2Corrector = new FB2DescriptionCorrector(fb2);
                    fB2Corrector.recoveryDescriptionNode();

                    IList <XmlNode> xmlNewAuthors = makeAuthorNode(Enums.AuthorEnum.AuthorOfBook, ref fb2, AuthorsListView);
                    if (xmlNewAuthors != null)
                    {
                        XmlNodeList xmlAuthorList = fb2.getAuthorNodes(TitleInfoEnum.TitleInfo);
                        if (xmlAuthorList != null)
                        {
                            XmlNode xmlBookTitleNode = fb2.getBookTitleNode(TitleInfoEnum.TitleInfo);
                            if (xmlBookTitleNode != null)
                            {
                                XmlNode xmlTINode = fb2.getTitleInfoNode(TitleInfoEnum.TitleInfo);
                                if (xmlTINode != null)
                                {
                                    // удаление старых данных Авторов
                                    foreach (XmlNode Author in xmlAuthorList)
                                    {
                                        xmlTINode.RemoveChild(Author);
                                    }
                                    // добавление новых данных Авторов
                                    foreach (XmlNode Author in xmlNewAuthors)
                                    {
                                        xmlTINode.InsertBefore(Author, xmlBookTitleNode);
                                    }

                                    // сохранение fb2 файла
                                    if (!Directory.Exists(m_TempDir))
                                    {
                                        Directory.CreateDirectory(m_TempDir);
                                    }
                                    string NewPath = Info.IsFromZip ? Info.FilePathIfFromZip : Info.FilePathSource;
                                    fb2.saveToFB2File(NewPath, false);
                                    if (Info.IsFromZip)
                                    {
                                        WorksWithBooks.zipMoveTempFB2FileTo(m_sharpZipLib, NewPath, Info.FilePathSource);
                                    }
                                    if (Info.IsFromZip && File.Exists(NewPath))
                                    {
                                        File.Delete(NewPath);
                                    }
                                }
                            }
                        }
                    }
                }
                m_bw.ReportProgress(1);
                ProgressBar.Update();
            }
            Cursor.Current = Cursors.Default;
        }