Exemple #1
0
        /// <summary>
        /// Creates an array of links based on the post's body. Then walks through each link and attempts to send trackbacks/pingbacks
        /// </summary>
        public void CheckPost(object state)
        {
            List <string> links = GetLinks(_postBody, _baseUrl);

            foreach (string externalUrl in links)
            {
                if (string.IsNullOrEmpty(externalUrl))
                {
                    continue;
                }

                try
                {
                    WebHeaderCollection headers = null;
                    string pageText             = null;

                    using (HttpWebResponse response = GRequest.GetResponse(externalUrl, _postLink))
                    {
                        headers  = response.Headers;
                        pageText = GRequest.GetPageText(response);
                        response.Close();
                    }

                    if (!string.IsNullOrEmpty(pageText))
                    {
                        bool pingSent = false;

                        // First try to send a TrackBack if the required RDF info was embedded in the HTML
                        TrackBackSender trackBack = new TrackBackSender(pageText, externalUrl, _siteName, _postTitle, _postLink, _excerpt);
                        pingSent = trackBack.SendTrackBackPing();

                        // If the Trackback attempt failed, try to do a Pingback
                        // (if the required PingBack XML-RPC service URL exists in the HTTP Header or HTML Head)
                        if (!pingSent)
                        {
                            PingBackSender pingBack = new PingBackSender(headers, pageText, externalUrl, _postTitle, _postLink);
                            pingSent = pingBack.SendPingbackPing();
                        }
                    }
                }
                catch (System.Exception ex)
                {
                    string message = String.Format("Trackback/Pingback attempt to the url [{0}] failed for post {1} while retrieving the remote document. Error message returned was: {2}.", externalUrl, this._postTitle, ex.Message);
                    Log.Warn("Trackback/Pingback Error", message);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Creates an array of links based on the post's body. Then walks through each link and attempts to send trackbacks/pingbacks
        /// </summary>
        public void CheckPost(object state)
        {
            List<string> links = GetLinks(_postBody, _baseUrl);
            foreach (string externalUrl in links)
            {
                if (string.IsNullOrEmpty(externalUrl))
                    continue;

                try
                {
                    WebHeaderCollection headers = null;
                    string pageText = null;

                    using (HttpWebResponse response = GRequest.GetResponse(externalUrl, _postLink))
                    {
                        headers = response.Headers;
                        pageText = GRequest.GetPageText(response);
                        response.Close();
                    }

                    if (!string.IsNullOrEmpty(pageText))
                    {
                        bool pingSent = false;

                        // First try to send a TrackBack if the required RDF info was embedded in the HTML
                        TrackBackSender trackBack = new TrackBackSender(pageText, externalUrl, _siteName, _postTitle, _postLink, _excerpt);
                        pingSent = trackBack.SendTrackBackPing();

                        // If the Trackback attempt failed, try to do a Pingback
                        // (if the required PingBack XML-RPC service URL exists in the HTTP Header or HTML Head)
                        if (!pingSent)
                        {
                            PingBackSender pingBack = new PingBackSender(headers, pageText, externalUrl, _postTitle, _postLink);
                            pingSent = pingBack.SendPingbackPing();
                        }

                    }
                }
                catch (System.Exception ex)
                {
                    string message = String.Format("Trackback/Pingback attempt to the url [{0}] failed for post {1} while retrieving the remote document. Error message returned was: {2}.", externalUrl, this._postTitle, ex.Message);
                    Log.Warn("Trackback/Pingback Error", message);
                }
            }
        }