Esempio n. 1
0
 private void HttpImportButton_Click(object sender, EventArgs e)
 {
     try {
         string post_url = PathTextBox.Text;
         Dictionary <string, string> num_home = BlogsParser.NumberHomepageDic(post_url, BlogsParser.Options.FromBlogContent);
         List <blog> result = new List <blog>(num_home.Count);
         foreach (string key in num_home.Keys)
         {
             result.Add(new blog
             {
                 number   = key,
                 homepage = num_home[key]
             });
         }
         main_form_control.Invoke(main_form_control.my_delegate, result);
         if (MessageBox.Show(this, "导入成功,是否返回主界面", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
         {
             this.Close();
         }
     }
     catch (System.ArgumentException)
     {
         MessageBox.Show("博客路径不合法,请重新输入!");
     }
 }
Esempio n. 2
0
        private List <TaskInfo> DiffLinkAndPreTask()
        {
            task_set = new List <Task>();
            List <TaskInfo> tasks_info = new List <TaskInfo>();
            XmlDocument     xml_doc    = new XmlDocument();

            root_xml_doc = xml_doc;
            try
            {
                xml_doc.Load("../../lib/Configure.xml");
                string root_path = ConfigureForm.ReadXmlToPath();
                Dictionary <string, XmlNode> blogs = ConfigureForm.ReadXmlToBlogNode(xml_doc);
                foreach (string user_number in blogs.Keys)
                {
                    XmlNode user       = blogs[user_number];
                    string  store_path = root_path + "/" + user_number;
                    if (!Directory.Exists(store_path))
                    {
                        Directory.CreateDirectory(store_path);
                    }
                    Dictionary <string, string> now_link    = BlogsParser.UrlTitleDic(blogs[user_number].Attributes["home"].Value);
                    Dictionary <string, string> backup_link = ConfigureForm.ReadXmlToLink(blogs[user_number].Attributes["home"].Value);
                    foreach (string link_url in now_link.Keys)
                    {
                        // if the url has been backuped.
                        if (!backup_link.ContainsKey(link_url))
                        {
                            //add the task into the task_set
                            Task temp = PdfConvert.ConvertHtmlToPdfAsync(
                                new PdfDocument
                            {
                                Url          = link_url,
                                HeaderLeft   = link_url,
                                HeaderRight  = "[date] [time]",
                                FooterCenter = "Page [page] of [topage]"
                            }, new PdfOutput
                            {
                                // [title] +".pdf"
                                OutputFilePath = store_path + "/" + now_link[link_url] + ".pdf"
                            }, this);
                            //temp_task.Start();
                            tasks_info.Add(
                                new TaskInfo
                            {
                                user     = user,
                                xml_doc  = xml_doc,
                                link_url = link_url,
                                title    = now_link[link_url]
                            });
                            task_set.Add(temp);
                        }
                    }
                }
            }
            catch (System.IO.FileNotFoundException)
            {
                XmlNode node = xml_doc.CreateXmlDeclaration("1.0", "utf-8", "");
                xml_doc.AppendChild(node);
                XmlNode root_node = xml_doc.CreateElement("students");
                xml_doc.AppendChild(root_node);
                xml_doc.Save("../../lib/Configure.xml");
            }
            return(tasks_info);
        }