Example #1
0
        /// <summary>
        /// バックグラウンドでの処理を行います。
        /// フィードの更新処理を行います。
        /// 設定パラメータは Hashtable で指定します。
        /// Hashtable["Url"]       ... フィードのURLを指定します。指定がない場合、全フィードの更新を行います。
        /// Hashtable["ExpandAll"] ... true の場合、読み込み後に全ツリーノードを開きます。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void backgroundWorkerUpdateFeed_DoWork(object sender, DoWorkEventArgs e)
        {
            var worker = (BackgroundWorker)sender;

            worker.ReportProgress(0);

            Hashtable args = (Hashtable)e.Argument;

            if (args == null)
            {
                args = new Hashtable();
            }

            Feed.FeedReader feedReader = new Feed.FeedReader();

            if (args.ContainsKey("Url"))
            {
                Uri           uri  = new Uri((string)args["Url"]);
                Feed.FeedInfo info = feedReader.Read(uri, settingsManager.Setting.DummyUserAgent);

                if (null == info)
                {
                    args["Error"] = true;
                }
                else
                {
                    if (false == this.feedTreeManager.UpdateFeed(info))
                    {
                        args["Error"] = true;
                    }
                }
            }
            else
            {
                foreach (var url in settingsManager.Setting.FeedUrls)
                {
                    var uri  = new Uri(url);
                    var feed = feedReader.Read(uri, settingsManager.Setting.DummyUserAgent);
                    this.feedTreeManager.UpdateFeed(feed);
                }
            }

            e.Result = args;
        }
Example #2
0
        /// <summary>
        /// フィードをツリーに追加、または既にあるノードを更新します。
        /// このメソッドは、バックグラウンドワーカーから呼び出されるため、UIの操作は避けています。
        /// </summary>
        /// <param name="feedInfo">追加、または更新するフィード</param>
        /// <returns></returns>
        public bool UpdateFeed(Feed.FeedInfo feedInfo)
        {
            if (null == feedInfo)
            {
                return(false);
            }

            FeedTreeNode parentNode = null;

            foreach (var node in this.parentNodeList)
            {
                if (node.Url.ToString() == feedInfo.Url.ToString())
                {
                    parentNode = node;
                    break;
                }
            }

            if (null == parentNode)
            {
                parentNode = new FeedTreeNode();
                this.parentNodeList.Add(parentNode);
            }

            parentNode.Title       = feedInfo.Title;
            parentNode.Description = feedInfo.Description;
            parentNode.Url         = feedInfo.Url;
            parentNode.ToolTipText = feedInfo.Description;
            parentNode.IconIndex   = GetFaviconIndex(feedInfo.Url);

            List <FeedTreeNode> childList;

            if (false == this.childNodeList.TryGetValue(parentNode, out childList))
            {
                this.childNodeList.Add(parentNode, new List <FeedTreeNode>());
            }

            foreach (var item in feedInfo.Items)
            {
                FeedTreeNode childNode = null;

                foreach (FeedTreeNode child in this.childNodeList[parentNode])
                {
                    if (child.Url.ToString() == item.Link.ToString())
                    {
                        childNode = child;
                        break;
                    }
                }

                if (null == childNode)
                {
                    childNode = new FeedTreeNode();
                    this.childNodeList[parentNode].Add(childNode);
                }

                childNode.Title     = item.Title;
                childNode.Content   = item.Content;
                childNode.Summary   = item.Summary;
                childNode.Url       = item.Link;
                childNode.Date      = item.Date;
                childNode.IconIndex = GetFaviconIndex(item.Link);
            }

            return(true);
        }
Example #3
0
        /// <summary>
        /// RSS 1.0の読み込みを行います。
        /// </summary>
        /// <param name="uri">フィードのURL</param>
        /// <returns>フィード</returns>
        private FeedInfo ReadRSS1(Uri uri)
        {
            FeedInfo info = new FeedInfo();
            info.Url = uri;

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(uri.ToString());

            List<FeedItem> ret = new List<FeedItem>();

            XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);
            nsmgr.AddNamespace("rss", "http://purl.org/rss/1.0/");
            nsmgr.AddNamespace("content", "http://purl.org/rss/1.0/modules/content/");
            nsmgr.AddNamespace("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
            nsmgr.AddNamespace("dc", "http://purl.org/dc/elements/1.1/");

            XmlNodeList linodes = xmlDoc.SelectNodes("/rdf:RDF/rss:channel/rss:items/rdf:Seq/rdf:li", nsmgr);

            foreach (XmlNode node in linodes)
            {
                string strResource = node.Attributes["resource", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"].Value;

                XmlNode aboutItem = xmlDoc.SelectSingleNode("/rdf:RDF/rss:item[@rdf:about='" + strResource + "']", nsmgr);

                if (aboutItem != null)
                {
                    XmlNode titleNode = aboutItem.SelectSingleNode("rss:title", nsmgr);
                    XmlNode contentNode = aboutItem.SelectSingleNode("content:encoded", nsmgr);
                    XmlNode linkUrkNode = aboutItem.SelectSingleNode("rss:link", nsmgr);
                    XmlNode dateNode = aboutItem.SelectSingleNode("dc:date", nsmgr);

                    string title = string.Empty;
                    string content = string.Empty;
                    string link = string.Empty;
                    string date = string.Empty;

                    if (titleNode != null)
                    {
                        title = titleNode.InnerText;
                    }
                    if (linkUrkNode != null)
                    {
                        link = linkUrkNode.InnerText;
                    }
                    if (contentNode != null)
                    {
                        content = contentNode.InnerText;
                    }
                    if (dateNode != null)
                    {
                        date = dateNode.InnerText;
                    }

                    FeedItem rssItem = new FeedItem();
                    rssItem.Title = title;
                    rssItem.Content = content;
                    rssItem.Date = stringToDateTime(date);
                    rssItem.Link = new Uri(link);
                    ret.Add(rssItem);
                }
            }
            info.Items = ret.ToArray();
            info.Title = xmlDoc.SelectSingleNode("/rdf:RDF/rss:channel/rss:title", nsmgr).InnerText;
            return info;
        }
Example #4
0
        /// <summary>
        /// RSS 1.0の読み込みを行います。
        /// </summary>
        /// <param name="uri">フィードのURL</param>
        /// <param name="rssXml">読み込み済みのXMLドキュメント</param>
        /// <returns>フィード</returns>
        private FeedInfo ReadRSS1(Uri uri, XmlDocument rssXml)
        {
            FeedInfo info = new FeedInfo();

            info.Url = uri;

            List <FeedItem> ret = new List <FeedItem>();

            XmlNamespaceManager nsmgr = new XmlNamespaceManager(rssXml.NameTable);

            nsmgr.AddNamespace("rss", "http://purl.org/rss/1.0/");
            nsmgr.AddNamespace("content", "http://purl.org/rss/1.0/modules/content/");
            nsmgr.AddNamespace("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
            nsmgr.AddNamespace("dc", "http://purl.org/dc/elements/1.1/");

            XmlNodeList linodes = rssXml.SelectNodes("/rdf:RDF/rss:channel/rss:items/rdf:Seq/rdf:li", nsmgr);

            foreach (XmlNode node in linodes)
            {
                string strResource = node.Attributes["resource", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"].Value;

                XmlNode aboutItem = rssXml.SelectSingleNode("/rdf:RDF/rss:item[@rdf:about='" + strResource + "']", nsmgr);

                if (aboutItem != null)
                {
                    XmlNode titleNode   = aboutItem.SelectSingleNode("rss:title", nsmgr);
                    XmlNode contentNode = aboutItem.SelectSingleNode("content:encoded", nsmgr);
                    XmlNode linkUrkNode = aboutItem.SelectSingleNode("rss:link", nsmgr);
                    XmlNode dateNode    = aboutItem.SelectSingleNode("dc:date", nsmgr);

                    string title   = string.Empty;
                    string content = string.Empty;
                    string link    = string.Empty;
                    string date    = string.Empty;

                    if (titleNode != null)
                    {
                        title = titleNode.InnerText;
                    }
                    if (linkUrkNode != null)
                    {
                        link = linkUrkNode.InnerText;
                    }
                    if (contentNode != null)
                    {
                        content = contentNode.InnerText;
                    }
                    if (dateNode != null)
                    {
                        date = dateNode.InnerText;
                    }

                    FeedItem rssItem = new FeedItem();
                    rssItem.Title   = title;
                    rssItem.Content = content;
                    rssItem.Date    = stringToDateTime(date);
                    rssItem.Link    = new Uri(link);
                    ret.Add(rssItem);
                }
            }
            info.Items = ret.ToArray();
            info.Title = rssXml.SelectSingleNode("/rdf:RDF/rss:channel/rss:title", nsmgr).InnerText;
            return(info);
        }