论坛首页 编程语言技术论坛

有谁写过Windows 服务的?

浏览 2187 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-11-11   最后修改:2008-11-11
我前些天做了个WINDOWS 服务。
抓取一个RSS列表的数据存到自己的数据库。
但是不知道为什么,总是有部分数据的部分字段存不进去。
我可以肯定是都取出来了的。
 public void GetData()
        {
            try
            {
                XmlDocument myXml = new XmlDocument();
                myXml.Load(this.XmlUrl);
                if(Directory.Exists(Config.rsspath))
                {
                    Directory.CreateDirectory(Config.rsspath);
                }
                myXml.Save(Config.rsspath + RssId + ".xml");
                XmlDocument xml = new XmlDocument();
                xml.Load(Config.rsspath + RssId + ".xml");
                foreach (XmlNode node in xml.GetElementsByTagName("item"))
                {
                    ModelRssArticle model = new ModelRssArticle();
                    try
                    {
                        foreach (XmlNode linode in node.ChildNodes)
                        {
                            if (linode.Name == "title")
                            {
                                model.ArticleTitle = linode.InnerText.Trim();
                            }
                            else if (linode.Name == "pubDate")
                            {
                                try
                                {
                                    model.ArticleTime = Convert.ToDateTime(linode.InnerText.Trim());
                                }
                                catch
                                {
                                    string str = linode.InnerText.Trim();
                                    if (str.IndexOf("GMT") > -1)
                                    {
                                        model.ArticleTime = Convert.ToDateTime(str.Substring(0, str.IndexOf("GMT")));
                                    }
                                    else
                                    {
                                        model.ArticleTime = System.DateTime.Now;
                                    }
                                }
                            }
                            else if (linode.Name == "link")
                            {
                                model.ArticleLink = linode.InnerText.Trim();
                            }
                            else if (linode.Name == "author")
                            {
                                model.ArticleAuthor = linode.InnerText.Trim();
                            }
                            else if (linode.Name == "category")
                            {
                                model.ArticleCate = linode.InnerText.Trim();
                            }
                            else if (linode.Name == "tags")
                            {
                                model.ArticleTag = linode.InnerText.Trim();
                            }
                            else if (linode.Name == "description")
                            {
                                string description = System.Web.HttpUtility.HtmlDecode(linode.InnerText.Trim());
                                model.ArticleDescription = description;
                            }
                        }
                    }
                    catch(Exception ec)
                    {
                        Logger.Debug("\n==============文章解析出错:" + model.ArticleTitle + "\n地址为:" + model.ArticleLink);
                        Logger.Debug("\n=" + ec.ToString());
                        continue;
                    }
                    model.RssId = this.RssId;

                    BLLRssArticle bll = new BLLRssArticle();
                    if (bll.IsExist(model))
                    {
                        Logger.Debug("-------------------------ID为:" + model.RssId + "没有新文章!-------------------------------------------------\n");
                        break;
                    }
                    else
                    {
                        bll.Add(model);
                        Logger.Debug("数据库添加完一篇文章,标题为" + model.ArticleTitle + "\n地址为:" + model.ArticleLink + "\n+++++描述为+++:" + model.ArticleDescription);
                    }
                }

            }
            catch (Exception e)
            {
                Logger.Bug("路径:"+this.XmlUrl+"读取出错。\n出错时间:"+System.DateTime.Now.ToString()+"\n出错Id:"+this.RssId.ToString()+"\n\n\n");
                Logger.Bug(e.ToString());
                throw e;

            }
        }


我在这一句
Logger.Debug("数据库添加完一篇文章,标题为" + model.ArticleTitle + "\n地址为:" + model.ArticleLink + "\n+++++描述为+++:" + model.ArticleDescription);  

里面能把所有的ArticleDescription 都打印出来。
但是,在数据库中,有部分记录的ArticleDescription 为空。
论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics