Exemple #1
0
        public override void DeleteFeedItems(ISession session)
        {
            XmlNodeList FeedXmlItems = XmlFeed.SelectNodes("/atom:feed/atom:entry", AtomNamespaceManager);

            foreach (XmlNode XmlNodeItem in FeedXmlItems)
            {
                XmlNode xmlLink = XmlNodeItem.SelectSingleNode("atom:link[@rel='service.edit']", AtomNamespaceManager);

                if (xmlLink == null)
                {
                    throw new Exception("Missing /feed/entry/link[@rel='service.edit' in '" + AtomNamespace + "'.");
                }

                XmlAttribute xmlHref = xmlLink.Attributes["href"];

                if (xmlHref == null)
                {
                    throw new Exception("Element /feed/entry/link[@rel='service.edit'] is missing an href attribute.");
                }

                HttpWebRequest DeleteRequest = (HttpWebRequest)WebRequest.Create(xmlHref.InnerText);
                if (!string.IsNullOrEmpty(mFeed.Username))
                {
                    DeleteRequest.Credentials = new NetworkCredential(mFeed.Username, mFeed.Password, null);
                }

                DeleteRequest.Method    = "DELETE";
                DeleteRequest.UserAgent = "DBlog.NET/1.0";

                string rx = new StreamReader(DeleteRequest.GetResponse().GetResponseStream()).ReadToEnd();
            }
        }
Exemple #2
0
        protected override int UpdateFeedItems(ISession session)
        {
            int result = 0;

            if (!string.IsNullOrEmpty(mFeed.Xsl))
            {
                StringBuilder        TransformedString = new StringBuilder();
                XslCompiledTransform FeedXsl           = new XslCompiledTransform();
                FeedXsl.Load(new XmlTextReader(new StringReader(mFeed.Xsl)), null, null);
                StringWriter  StringWriter = new StringWriter(TransformedString);
                XmlTextWriter TextWriter   = new XmlTextWriter(StringWriter);
                FeedXsl.Transform(new XmlNodeReader(XmlFeed.DocumentElement), TextWriter);
                XmlFeed.LoadXml(TransformedString.ToString());
            }

            XmlNodeList FeedXmlItems = XmlFeed.SelectNodes("descendant::channel/item");

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

            foreach (XmlNode XmlNodeItem in FeedXmlItems)
            {
                XmlNode xmlLink = XmlNodeItem.SelectSingleNode("link");
                string  link    = (xmlLink != null) ? xmlLink.InnerText : null;

                FeedItem current = null;

                if (!string.IsNullOrEmpty(link))
                {
                    for (int i = 0; i < mFeed.FeedItems.Count; i++)
                    {
                        FeedItem item = (FeedItem)mFeed.FeedItems[i];
                        if (item.Link == link)
                        {
                            current = item;
                            updated.Add(item);
                            mFeed.FeedItems.RemoveAt(i);
                            break;
                        }
                    }
                }

                if (current == null)
                {
                    result++;
                    current      = new FeedItem();
                    current.Feed = mFeed;
                    current.Link = link;
                }

                XmlNode xmlDescription = XmlNodeItem.SelectSingleNode("description");
                current.Description = (xmlDescription != null) ? xmlDescription.InnerText : null;

                XmlNode xmlTitle = XmlNodeItem.SelectSingleNode("title");
                current.Title = (xmlTitle != null) ? xmlTitle.InnerText : null;

                session.Save(current);
            }

            foreach (FeedItem item in mFeed.FeedItems)
            {
                session.Delete(item);
            }

            mFeed.FeedItems = updated;
            return(result);
        }