⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 blog.cs

📁 一个简单的Demo
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Net;
using System.IO;
using System.Globalization;

namespace Surance.DB4ODAL
{
    public class Blog : BaseItem
    {
        public Blog(Db4objects.Db4o.IObjectContainer db)
            : base(db)
        {

        }

        public Blog()
            : base()
        {
        }

        private string rSSAddress;

        public string RSSAddress
        {
            get { return rSSAddress; }
            set { rSSAddress = value; }
        }

        public int UpDateBlogs()
        {
           // string blogRss = "http://www.cnblogs.com/xxpyeippx/rss";
            string blogRss = rSSAddress;
            XmlDocument blogDoc = new XmlDocument();

            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(blogRss);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream stream = response.GetResponseStream();

            StreamReader reader = new StreamReader(stream);
            string xmlContent = reader.ReadToEnd();

           

            blogDoc.LoadXml(xmlContent);
            stream.Close();
            response.Close();
            


            string itemXpath = "//item";

            XmlNodeList nodeList = blogDoc.SelectNodes(itemXpath);
            
            string title="";
            string link="";
            DateTime pubDate = DateTime.MinValue;
            string content="";

            int count = nodeList.Count;
            for ( int  i = count; i >0;i-- )
            {
                XmlNode oneBlogNode = nodeList[i-1];
                if (this.Category == "CNBLOGS")
                {
                    title = oneBlogNode.ChildNodes[0].InnerText;
                    link = oneBlogNode.ChildNodes[1].InnerText;

                    CultureInfo culture = new System.Globalization.CultureInfo("en-US");
                    pubDate = DateTime.Parse(oneBlogNode.ChildNodes[4].InnerText, culture);
                    content = oneBlogNode.ChildNodes[11].InnerText;


                }
                if (this.Category == "CSDN")
                {
                    title = oneBlogNode.ChildNodes[1].InnerText;
                    link = oneBlogNode.ChildNodes[2].InnerText;

                    CultureInfo culture = new System.Globalization.CultureInfo("en-US");
                    pubDate = DateTime.Parse(oneBlogNode.ChildNodes[3].InnerText, culture);

                    content = oneBlogNode.ChildNodes[10].InnerText;


                }
                object oldBlog = GetOne(title);

                Blog toAdd =null;
                if (oldBlog == null)
                {
                    toAdd = new Blog();
                    setupNewblog(title, link, pubDate, content, toAdd);
                    toAdd.Add();

                }
                else
                {
                    toAdd = (Blog)oldBlog;
                    setupNewblog(title, link, pubDate, content, toAdd);

                    toAdd.Update();
                }
                    
            }

            return count;
        }

        private void setupNewblog(string title, string link, DateTime pubDate, string content, Blog toAdd)
        {
            toAdd.Category = this.Category;
            toAdd.Content = content;
            toAdd.CreateTime = pubDate;
            toAdd.Hit = 0;
            toAdd.RSSAddress = link;
            toAdd.Title = title;

            toAdd.Db = this.Db;
            
        }


        
       
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -