Exemple #1
0
 public Form1()
 {
     InitializeComponent();
     db = new db_adapter();
     if (db.check_connection() == true) label1.Text += "\nСоединение с БД есть. \n";
     else label1.Text += "\n Нет подключения к серверу БД. \n";
     ya = new ya_translate();
     if (ya.connected() == true) label1.Text += "\nСоединение с переводчиком есть. \n";
     else label1.Text += "\n Нет подключения к серверу API Яндекс.Переводчика. \n";
 }
Exemple #2
0
 private void handler(object sender, EventArgs e)
 {
     string title_ru = rf.Controls[1].Text;
     string title_en = rf.Controls[4].Text;
     string refs = rf.Controls[2].Text;
     refs = refs.Replace("\n", "<br>");
     db_adapter db = new db_adapter();
     db.send_trase_refs(title_ru, title_en, refs);
     rf.Close();
 }
Exemple #3
0
        public void parse()
        {
            FileInfo file = new FileInfo(@"result_temp.xml");
            FileStream fs = file.Create();
            string text = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n <issues> \n </issues>";
            fs.Close();
            FileStream fsw = file.OpenWrite();
            byte[] array_in = System.Text.Encoding.Default.GetBytes(text);
            fsw.Write(array_in, 0, array_in.Length);
            fsw.Close();
            ///////////////////////////////////////////////////////////////////////
            // Добавляем теги секций в статьи и разбирваем на файлы. 1 ф = 1 статья
            ///////////////////////////////////////////////////////////////////////

            XmlDocument xDoc = new XmlDocument();
            xDoc.Load(fc);
            XmlElement xRoot = xDoc.DocumentElement;
            XmlNodeList childnodes = xRoot.SelectNodes("issue/articles/*");

            string current_section = "";
            for (int i = 0; i < childnodes.Count; i++)
            {
                if (childnodes[i].Name == "section")
                {
                    current_section = childnodes[i].ChildNodes[0].InnerText;
                }
                else
                {
                    XmlElement cur_sec_node = xDoc.CreateElement("sect");
                    cur_sec_node.InnerText = current_section;
                    childnodes[i].AppendChild(cur_sec_node);
                }
            }

            childnodes = xRoot.SelectNodes("issue/articles/article");
            int y = 0;
            string u = ".xml";
            string coi = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n";
            foreach (XmlNode n in childnodes)
            {
                FileInfo file1 = new FileInfo(y.ToString() + u);
                FileStream fs1 = file1.Create();
                string text1 = coi + n.OuterXml;
                fs1.Close();
                FileStream fsw1 = file1.OpenWrite();
                byte[] array_in1 = System.Text.Encoding.UTF8.GetBytes(text1);
                fsw1.Write(array_in1, 0, array_in1.Length);
                fsw1.Close();
                y++;
            }
            ///////////////////////////////////////////////////////////////////////
            // Добавляем начальные данные в результирующий xml
            ///////////////////////////////////////////////////////////////////////
            string issue_name = f.Controls[2].Text;
            XDocument xdoc = XDocument.Load("result_temp.xml");
            XElement root = xdoc.Element("issues");
            root.Add(
                new XElement("issue",
                    new XAttribute("published", "true"),
                    new XAttribute("current", "true"),
                    new XAttribute("identification", "title"),
                        new XElement("title",
                                new XAttribute("locale", "ru_RU"),
                                issue_name),
                        new XElement("access_date", "01-01-2001"),
                        new XElement("volume", "0"),
                        new XElement("number", "5(33)"),
                        new XElement("year", "0"),
                        new XElement("date_published", "2015-12-07")
                ));

            xdoc.Save("result_temp.xml");
            ///////////////////////////////////////////////////////////////////////
            // Помещаем  данные в локальный объект.
            ///////////////////////////////////////////////////////////////////////
            amount = y;

            List<article> a = new List<article>();
            for (int k9 = 0; k9 < amount; k9++)
            {
                a.Add(new article());

            }

            string wws = "";
            y = 0;

            for (int i = 0; i < amount; i++)
            {

                XmlDocument xDoc1 = new XmlDocument();
                xDoc1.Load(y.ToString() + u);
                XmlElement xRoot1 = xDoc1.DocumentElement;
                XmlNodeList childnodes1;

                childnodes1 = xRoot1.SelectNodes("sect");
                wws = childnodes1.Item(0).InnerText;
                a[y].section = wws;

                try
                {
                    childnodes1 = xRoot1.SelectNodes("artTitles/artTitle[1]");
                    wws = childnodes1.Item(0).InnerText;
                    a[y].title_rus = wws;
                } catch(Exception e){
                    a[y].title_rus = "Для этой статьи нет заголовка";
                }

                try
                {
                    childnodes1 = xRoot1.SelectNodes("artTitles/artTitle[2]");
                    wws = childnodes1.Item(0).InnerText;
                    a[y].title_en = wws;
                }
                catch(Exception e){
                    a[y].title_en = "No title for this article";
                }

                childnodes1 = xRoot1.SelectNodes("abstracts/abstract[1]");
                if (childnodes1.Item(0) != null)
                {
                    wws = childnodes1.Item(0).InnerText;
                    a[y].abstract_rus = wws;
                }
                else a[y].abstract_rus = "";

                childnodes1 = xRoot1.SelectNodes("abstracts/abstract[2]");
                if (childnodes1.Item(0) != null) wws = childnodes1.Item(0).InnerText;
                a[y].abstract_en = wws;

                childnodes1 = xRoot1.SelectNodes("authors/author");
                int count = childnodes1.Count;
                string fullname = "";

                List<author> b = new List<author>();
                a[y].authors = new List<author>();
                for (int k3 = 0; k3 < count; k3++) { b.Add(new author()); }

                for (int mm = 0; mm < count; mm++)
                {
                    childnodes1 = xRoot1.SelectNodes("authors/author[" + (mm + 1).ToString() + "]/individInfo/surname");
                    wws = childnodes1.Item(0).InnerText;
                    string surname = wws;

                    childnodes1 = xRoot1.SelectNodes("authors/author[" + (mm + 1).ToString() + "]/individInfo/initials");
                    wws = childnodes1.Item(0).InnerText;
                    char[] ch = wws.ToCharArray();
                    string name = "";
                    string otchestvo = "";
                    bool flag = false;
                    for (int gh = 0; gh < ch.Length; gh++)
                    {
                        if (ch[gh] == ' ') flag = true;
                        if (flag) otchestvo += ch[gh]; else name += ch[gh];
                    }
                    name.Trim();
                    otchestvo.Trim();
                    fullname = name + " " + otchestvo + " " + surname;
                    b[mm].fullname_ru = fullname;
                    b[mm].firstname = name;
                    b[mm].middlename = otchestvo;
                    b[mm].lastname = surname + " " + ya.translit_toEn(name) + " " + ya.translit_toEn(otchestvo) + " " + ya.translit_toEn(surname);
                    b[mm].fullname_en = ya.translit_toEn(name) + " " + ya.translit_toEn(otchestvo) + " " + ya.translit_toEn(surname);

                    b[mm].country = "RU";

                    try
                    {

                        childnodes1 = xRoot1.SelectNodes("authors/author[" + (mm + 1).ToString() + "]/individInfo/email");
                        wws = childnodes1.Item(0).InnerText;
                        b[mm].email = wws;
                    }
                    catch (Exception e)
                    {
                        b[mm].email = "No e-mail";
                    }
                    childnodes1 = xRoot1.SelectNodes("authors/author[" + (mm + 1).ToString() + "]/individInfo/orgName");
                    wws = childnodes1.Item(0).InnerText;
                    b[mm].affiliation_ru = wws;
                    try
                    {
                        childnodes1 = xRoot1.SelectNodes("authors/author[" + (mm + 1).ToString() + "]/individInfo[@lang=\"ENG\"]/orgName");
                        wws = childnodes1.Item(0).InnerText;
                        b[mm].affiliation_en = wws;
                    }
                    catch (Exception e) { b[mm].affiliation_en = ya.translit_toEn(b[mm].affiliation_ru); }

                    try
                    {
                        childnodes1 = xRoot1.SelectNodes("authors/author[" + (mm + 1).ToString() + "]/individInfo/otherInfo");
                        wws = childnodes1.Item(0).InnerText;
                        b[mm].biography_ru = wws;
                    }
                    catch (Exception e) { b[mm].biography_ru = "No info"; }

                    try
                    {
                        childnodes1 = xRoot1.SelectNodes("authors/author[" + (mm + 1).ToString() + "]/individInfo[@lang=\"ENG\"]/otherInfo");
                        wws = childnodes1.Item(0).InnerText;
                        b[mm].biography_en = wws;
                    }
                    catch (Exception e) { b[mm].biography_en = "No info"; }

                }
                a[y].authors = b;

                childnodes1 = xRoot1.SelectNodes("pages");
                wws = childnodes1.Item(0).InnerText;
                a[y].pages = wws;

                if (xRoot1.SelectNodes("dates/dateReceived") == null)
                {
                    childnodes1 = xRoot1.SelectNodes("dates/dateReceived");
                    wws = childnodes1.Item(0).InnerText;
                    a[y].date_published = wws;
                }
                else a[y].date_published = "2015-12-07";

                a[y].copyright_holder = fullname;

                a[y].copyright_year = "2015";

                childnodes1 = xRoot1.SelectNodes("keywords/kwdGroup/keyword");
                count = childnodes1.Count;
                a[y].indexing_subject = new List<string>();
                for (int kl = 0; kl < count; kl++)
                {
                    childnodes1 = xRoot1.SelectNodes("keywords/kwdGroup/keyword[" + (kl + 1).ToString() + "]");
                    wws = childnodes1.Item(0).InnerText;
                    a[y].indexing_subject.Add(wws);
                }

                childnodes1 = xRoot1.SelectNodes("references/reference");
                count = childnodes1.Count;

                rf = new Form();
                rf.Size = new Size(1370, 600);

                Label l1 = new Label();
                l1.Location = new Point(20,50);
                l1.Size = new Size(620, 400);

                Label l2 = new Label();
                l2.Location = new Point(100, 5);
                l2.Size = new Size(400, 20);

                TextBox tb = new TextBox();
                tb.Multiline = true;
                tb.Size = new Size(650, 400);
                tb.Location = new Point(650, 50);

                Button sub = new Button();
                sub.Location = new Point(100, 450);
                sub.Text = "Готово -->";
                sub.Click += new System.EventHandler(this.handler);

                Label l3 = new Label();
                l3.Visible = false;

                rf.Controls.Add(l1);
                rf.Controls.Add(l2);
                rf.Controls.Add(tb);
                rf.Controls.Add(sub);
                rf.Controls.Add(l3);

                for (int kl = 0; kl < count; kl++)
                {
                    childnodes1 = xRoot1.SelectNodes("references/reference[" + (kl + 1).ToString() + "]");
                    wws = childnodes1.Item(0).InnerText;
                    a[y].citations_full += wws;
                    a[y].citations_full += "\n\n";
                }

                rf.Controls[1].Text = a[y].title_rus;
                rf.Controls[0].Text = a[y].citations_full;
                rf.Controls[4].Text = a[y].title_en;

                a[y].citations_full = a[y].citations_full.Replace("\n", "<br>");

                if ((f.Controls[0] as CheckBox).Checked)
                {
                    string src = "ojs.ru/files/pdfs/" + issue_name + "/" + a[y].pages + ".pdf";
                    string title_ru = a[y].title_rus;
                    string title_en = a[y].title_en;
                    string refs = ya.translit_toEn(a[y].citations_full);
                    db_adapter db2 = new db_adapter();
                    db2.send_trase_refs(title_ru, title_en, refs);
                    db2.send_trase_src(title_ru, src);
                    db2.send_trase_src(title_en, src);
                }
                else rf.ShowDialog();

                y++;
            }

            f.Controls[4].Text += "\n Парсинг окончен \n ";

            List<string> sect_list = new List<string>();
            string buff = a[0].section;
            for (int i = 1; i < a.Count; i++)
            {
                if (a[i].section != buff)
                {
                    sect_list.Add(buff);
                    buff = a[i].section;
                }
            }
            sect_list.Add(buff);
            // теперь удаляем все файлы
            for (int vf = 0; vf < amount; vf++)
            {
                FileInfo file2 = new FileInfo(vf.ToString() + ".xml");
                file2.Delete();
            }

            ///////////////////////////////////////////////////////////////////////
            // Из локального в таблицы БД trase_*.
            ///////////////////////////////////////////////////////////////////////

            db_adapter db = new db_adapter();
            int co = db.get_max_author_id();
            for (int i = 0; i < amount; i++) {
                for (int h = 0; h < a[i].authors.Count; h++) {
                    co++;
                    db.send_trase_title(a[i].title_rus, co);
                    db.send_trase_author(co, a[i].authors[h].fullname_ru, a[i].authors[h].biography_ru, a[i].authors[h].email, a[i].authors[h].affiliation_ru);
                    co++;
                    db.send_trase_title(a[i].title_en, co);
                    db.send_trase_author(co, a[i].authors[h].fullname_en, a[i].authors[h].biography_en, a[i].authors[h].email, a[i].authors[h].affiliation_en);
                }
            }

            ///////////////////////////////////////////////////////////////////////
            // Из локального в результирующий.
            ///////////////////////////////////////////////////////////////////////
            XDocument xd = XDocument.Load("result_temp.xml");
            XElement ro = xd.Element("issues").Element("issue");
            for (int i = 0; i < sect_list.Count; i++)
            {
                ro.Add(
                        new XElement("section",
                               new XElement("title",
                                   new XAttribute("locale", "ru_RU"), sect_list[i]),
                                new XElement("abbrev",
                                    new XAttribute("locale", "ru_RU"), ya.abbrev(sect_list[i]))
                            )
                    );
            }
            xd.Save("result_temp.xml");

            XElement current_article;
            for (int z = 0; z < amount; z++)
            {
                ya.buf = a[z].section;
                IEnumerable<XElement> sections = xd.Element("issues").Element("issue").Elements("section");
                Func<XElement, bool> rf = ya.fp;
                XElement true_sect = sections.First<XElement>(rf);

                true_sect.Add(
                        current_article = new XElement("article",
                            new XAttribute("locale", "ru_RU"),
                            new XAttribute("language", "ru"),
                            new XElement("title",
                                new XAttribute("locale", "ru_RU"), a[z].title_rus),
                            new XElement("title",
                                new XAttribute("locale", "en_US"), a[z].title_en),
                            new XElement("abstract",
                                new XAttribute("locale", "ru_RU"), a[z].abstract_rus),
                            new XElement("abstract",
                                new XAttribute("locale", "en_US"), a[z].abstract_en))
                      );
                xd.Save("result_temp.xml");

                for (int x = 0; x < a[z].authors.Count; x++)
                {
                    current_article.Add(
                            new XElement("author",
                                new XAttribute("primary_contact", "true"),
                                new XElement("firstname", a[z].authors[x].firstname),
                                new XElement("middlename", a[z].authors[x].middlename),
                                new XElement("lastname", a[z].authors[x].lastname),
                                new XElement("affiliation",
                                    new XAttribute("locale", "ru_RU"), a[z].authors[x].affiliation_ru),
                                new XElement("affiliation",
                                    new XAttribute("locale", "en_US"), a[z].authors[x].affiliation_en),
                                new XElement("country", a[z].authors[x].country),
                                new XElement("email", a[z].authors[x].email),
                                new XElement("biography", a[z].authors[x].biography_ru)
                                )
                        );
                }

                string keys_ru = "";
                string keys_en = "";
                for (int x = 0; x < a[z].indexing_subject.Count; x++)
                {
                    if (ya.is_eng(a[z].indexing_subject[x]))
                    {
                        keys_en += a[z].indexing_subject[x];
                        if (x != a[z].indexing_subject.Count - 1) keys_en += ", ";
                    }
                    else
                    {
                        keys_ru += a[z].indexing_subject[x];
                        if (x != a[z].indexing_subject.Count - 1) keys_ru += ", ";
                    }
                }

                current_article.Add(
                        new XElement("pages", a[z].pages),
                        new XElement("date_published", a[z].date_published),
                        new XElement("indexing",
                            new XElement("subject",
                                new XAttribute("locale", "en_US"), keys_en),
                            new XElement("subject",
                                new XAttribute("locale", "ru_RU"), keys_ru
                                )
                            )
                    );

                current_article.Add(
                        new XElement("permissions",
                            new XElement("copyright_holder",
                                new XAttribute("locale", "ru_RU"), a[z].copyright_holder),
                                new XElement("copyright_year", a[z].copyright_year)
                            )
                    );

                //string src = "Z:/home/ojs.ru/www/files/pdfs/" + issue_name + "/" + a[z].pages + ".pdf";
                ////string src = "ojs.ru/files/pdfs/" + issue_name + "/" + a[z].pages + ".pdf";
                //current_article.Add(
                //        new XElement("galley",
                //            new XAttribute("locale", "ru_RU"),
                //            new XElement("label", "PDF"),
                //            new XElement("file",
                //                new XElement("href",
                //                    new XAttribute("src", src),
                //                    new XAttribute("mime_type","application/pdf")
                //                )
                //            )
                //        )
                //    );
            }

            xd.Save("result_temp.xml");
            f.Controls[4].Text += "\n Создание нового документа окончено. Началась работа с БД \n ";
            ///////////////////////////////////////////////////////////////////////
            SaveFileDialog saveFD = new SaveFileDialog();
            saveFD.Filter = "OJS-Xml файл | *.xml";
            saveFD.ShowDialog();
            if (saveFD.FileName != "")
            {
                try
                {
                    file.MoveTo(saveFD.FileName);
                    f.Controls[4].Text += "Парсинг завершен. Файл перемещен в указанный путь. \n";
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                }
            }
            else
            {
                f.Controls[4].Text += "Ошибка! Отменено сохранение файла.\n Нужно обработать исходный файл снова! \n";
                FileInfo file3 = new FileInfo("result_xml.xml");
                file3.Delete();
            }
            MessageBox.Show("Импортируйте полученные данные в OJS и закройте это окно");
            for (int i = 0; i < amount; i++)
            {
                db.send_citations(a[i].title_rus, a[i].citations_full);
            }
            f.Controls[4].Text = "Успешно! \n";
        }