Ejemplo n.º 1
0
        private void BlogRollItem_Saved(object sender, SavedEventArgs e)
        {
            if (e.Action == SaveAction.Insert || e.Action == SaveAction.Update || e.Action == SaveAction.Delete)
            {
                if (e.Action == SaveAction.Insert)
                {
                    AddBlog((BlogRollItem)sender);
                }
                else if (e.Action == SaveAction.Delete)
                {
                    blogRequest affected = null;
                    foreach (blogRequest req in _Items)
                    {
                        if (req.RollItem.Equals(sender))
                        {
                            affected = req;
                            break;
                        }
                    }
                    _Items.Remove(affected);
                }

                if (_Items.Count > 0)
                {
                    // Re-sort _Items collection in case sorting of blogroll items was changed.
                    _Items.Sort(delegate(blogRequest br1, blogRequest br2) { return(br1.RollItem.CompareTo(br2.RollItem)); });
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the request and processes the response.
        /// </summary>
        private static void ProcessRespose(IAsyncResult async)
        {
            blogRequest blogReq = (blogRequest)async.AsyncState;

            try
            {
                using (HttpWebResponse response = (HttpWebResponse)blogReq.Request.EndGetResponse(async))
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(response.GetResponseStream());

                    XmlNodeList nodes = doc.SelectNodes("rss/channel/item");
                    foreach (XmlNode node in nodes)
                    {
                        string   title = node.SelectSingleNode("title").InnerText;
                        string   link  = node.SelectSingleNode("link").InnerText;
                        DateTime date  = DateTime.Now;
                        if (node.SelectSingleNode("pubDate") != null)
                        {
                            date = DateTime.Parse(node.SelectSingleNode("pubDate").InnerText);
                        }

                        blogReq.ItemTitles.Add(title);
                        blogReq.ItemLinks.Add(link);
                    }
                }
            }
            catch
            { }
        }
Ejemplo n.º 3
0
        private void AddRssChildItems(blogRequest item, HtmlGenericControl li)
        {
            if (item.ItemTitles.Count > 0 && BlogSettings.Instance.BlogrollVisiblePosts > 0)
            {
                HtmlGenericControl div = new HtmlGenericControl("ul");
                for (int i = 0; i < item.ItemTitles.Count; i++)
                {
                    if (i >= BlogSettings.Instance.BlogrollVisiblePosts)
                    {
                        break;
                    }

                    HtmlGenericControl subLi = new HtmlGenericControl("li");
                    HtmlAnchor         a     = new HtmlAnchor();
                    a.HRef      = item.ItemLinks[i];
                    a.Title     = HttpUtility.HtmlEncode(item.ItemTitles[i]);
                    a.InnerHtml = EnsureLength(item.ItemTitles[i]);

                    subLi.Controls.Add(a);
                    div.Controls.Add(subLi);
                }

                li.Controls.Add(div);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Adds a blog to the item collection and start retrieving the blogs.
        /// </summary>
        private static void AddBlog(BlogEngine.Core.BlogRollItem br)
        {
            blogRequest affected = null;
            foreach (blogRequest req in _Items)
            {
                if (req.RollItem.Equals(br))
                {
                    affected = req;
                    break;
                }
            }
            if (affected == null)
            {
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(br.FeedUrl);
                req.Credentials = CredentialCache.DefaultNetworkCredentials;

                blogRequest bReq = new blogRequest(br, req);
                _Items.Add(bReq);
                req.BeginGetResponse(ProcessRespose, bReq);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Adds a blog to the item collection and start retrieving the blogs.
        /// </summary>
        private static void AddBlog(BlogEngine.Core.BlogRollItem br)
        {
            blogRequest affected = null;

            foreach (blogRequest req in _Items)
            {
                if (req.RollItem.Equals(br))
                {
                    affected = req;
                    break;
                }
            }
            if (affected == null)
            {
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(br.FeedUrl);
                req.Credentials = CredentialCache.DefaultNetworkCredentials;

                blogRequest bReq = new blogRequest(br, req);
                _Items.Add(bReq);
                req.BeginGetResponse(ProcessRespose, bReq);
            }
        }
Ejemplo n.º 6
0
        private void AddRssChildItems(blogRequest item, HtmlGenericControl li)
        {
            if (item.ItemTitles.Count > 0 && BlogSettings.Instance.BlogrollVisiblePosts > 0)
            {
                HtmlGenericControl div = new HtmlGenericControl("ul");
                for (int i = 0; i < item.ItemTitles.Count; i++)
                {
                    if (i >= BlogSettings.Instance.BlogrollVisiblePosts) break;

                    HtmlGenericControl subLi = new HtmlGenericControl("li");
                    HtmlAnchor a = new HtmlAnchor();
                    a.HRef = item.ItemLinks[i];
                    a.Title = HttpUtility.HtmlEncode(item.ItemTitles[i]);
                    a.InnerHtml = EnsureLength(item.ItemTitles[i]);

                    subLi.Controls.Add(a);
                    div.Controls.Add(subLi);
                }

                li.Controls.Add(div);
            }
        }