Exemplo n.º 1
0
        /// <summary>
        /// Adds a blog to the item collection and start retrieving the blogs.
        /// </summary>
        /// <param name="br">
        /// The blogroll item.
        /// </param>
        private static void AddBlog(BlogRollItem br)
        {
            var affected = Items.FirstOrDefault(r => r.RollItem.Equals(br));

            if (affected != null)
            {
                return;
            }

            var req = (HttpWebRequest)WebRequest.Create(br.FeedUrl);

            req.Credentials = CredentialCache.DefaultNetworkCredentials;

            var blogRequest = new BlogRequest(br, req);

            Items.Add(blogRequest);

            GetRequestData data = new GetRequestData()
            {
                BlogInstanceId = Blog.CurrentInstance.Id,
                BlogRequest    = blogRequest
            };

            req.BeginGetResponse(ProcessResponse, data);
        }
        /// <summary>
        /// Ends the get response.
        /// </summary>
        /// <param name="result">
        /// The result.
        /// </param>
        private static void EndGetResponse(IAsyncResult result)
        {
            try
            {
                GetRequestData data = (GetRequestData)result.AsyncState;
                Blog.InstanceIdOverride = data.BlogInstanceId;

                using (var response = (HttpWebResponse)data.HttpWebRequest.GetResponse())
                {
                    var doc            = new XmlDocument();
                    var responseStream = response.GetResponseStream();
                    if (responseStream != null)
                    {
                        doc.Load(responseStream);
                    }

                    Blog.CurrentInstance.Cache[TwitterFeedsCacheKey] = doc.OuterXml;
                    SaveLastFeed(doc);
                }
            }
            catch (Exception ex)
            {
                var msg = "Error retrieving Twitter feed.";
                msg += string.Format(" {0}", ex.Message);
                Utils.Log(msg);
            }
        }
Exemplo n.º 3
0
 public override void InitGetData(HttpRequestMessage req)
 {
     _getRequestDataObject = new GetRequestData
     {
         UserId    = GetParameter(req, "userId"),
         StartTime = new DateTime(long.Parse(GetParameter(req, "startTime"))),
         EndTime   = new DateTime(long.Parse(GetParameter(req, "endTime")))
     };
 }
Exemplo n.º 4
0
        /// <summary>
        /// Gets the request and processes the response.
        /// </summary>
        /// <param name="async">
        /// The async result.
        /// </param>
        private static void ProcessResponse(IAsyncResult asyncResult)
        {
            GetRequestData data = (GetRequestData)asyncResult.AsyncState;

            Blog.InstanceIdOverride = data.BlogInstanceId;
            var blogReq = data.BlogRequest;

            try
            {
                using (var response = (HttpWebResponse)blogReq.Request.EndGetResponse(asyncResult))
                {
                    var doc            = new XmlDocument();
                    var responseStream = response.GetResponseStream();
                    if (responseStream != null)
                    {
                        doc.Load(responseStream);
                    }

                    var nodes = doc.SelectNodes("rss/channel/item");
                    if (nodes != null)
                    {
                        foreach (XmlNode node in nodes)
                        {
                            var titleNode = node.SelectSingleNode("title");
                            var linkNode  = node.SelectSingleNode("link");
                            if (titleNode == null || linkNode == null)
                            {
                                continue;
                            }

                            var title = titleNode.InnerText;
                            var link  = linkNode.InnerText;

                            // var date = DateTime.Now;
                            // if (node.SelectSingleNode("pubDate") != null)
                            // {
                            //     date = DateTime.Parse(node.SelectSingleNode("pubDate").InnerText);
                            // }
                            blogReq.ItemTitles.Add(title);
                            blogReq.ItemLinks.Add(link);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Utils.Log("App_Code.Controls.Blogroll.ProcessRequest", ex);
            }
        }
        /// <summary>
        /// Begins the get feed.
        /// </summary>
        /// <param name="url">The URL to get.</param>
        private static void BeginGetFeed(Uri url)
        {
            try
            {
                var request = (HttpWebRequest)WebRequest.Create(url);
                request.Credentials = CredentialCache.DefaultNetworkCredentials;

                GetRequestData data = new GetRequestData()
                {
                    BlogInstanceId = Blog.CurrentInstance.Id,
                    HttpWebRequest = request
                };

                request.BeginGetResponse(EndGetResponse, data);
            }
            catch (Exception ex)
            {
                var msg = "Error requesting Twitter feed.";
                msg += string.Format(" {0}", ex.Message);

                Utils.Log(msg);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Adds a blog to the item collection and start retrieving the blogs.
        /// </summary>
        /// <param name="br">
        /// The blogroll item.
        /// </param>
        private static void AddBlog(BlogRollItem br)
        {
            var affected = Items.FirstOrDefault(r => r.RollItem.Equals(br));
            if (affected != null)
            {
                return;
            }

            var req = (HttpWebRequest)WebRequest.Create(br.FeedUrl);
            req.Credentials = CredentialCache.DefaultNetworkCredentials;

            var blogRequest = new BlogRequest(br, req);
            Items.Add(blogRequest);

            GetRequestData data = new GetRequestData()
            {
                BlogInstanceId = Blog.CurrentInstance.Id,
                BlogRequest = blogRequest
            };

            req.BeginGetResponse(ProcessResponse, data);
        }