예제 #1
0
 internal TrackbackJob(TrackbackInfo info, Entry entry)
 {
     this.info = info;
     this.entry = entry;
 }
예제 #2
0
        protected void PingbackWorker(object argument)
        {
            PingbackJob job = argument as PingbackJob;

            if (job.entry.Content != null &&
                job.entry.Content.Length > 0)
            {

                foreach (Match match in anchors.Matches(job.entry.Content))
                {
                    string url = match.Groups["url"].Value;

                    if (url.StartsWith("http"))
                    { // don't pass in a url withouth http into Uri constructor
                        try
                        {
                            Uri externalUri = new Uri(url);

                            if (externalUri.Scheme == Uri.UriSchemeHttp)
                            {
                                // we're auto-detecting pingbacks and while we do that
                                // we send a trackback in hope that the server may understand
                                // that already. We're appending to the target URL and 
                                // therefore shouldn't interfere with the server logic in case 
                                // the identifiers collide with those the server is using.

                                HttpWebRequest webRequest = WebRequest.Create(externalUri) as HttpWebRequest;
                                webRequest.Method = "GET";
                                webRequest.UserAgent = this.UserAgent;

                                HttpWebResponse response = webRequest.GetResponse() as HttpWebResponse;

                                // now we want to get the page contents of the target body
                                string requestBody = null;
                                using (StreamReader requestReader = new StreamReader(response.GetResponseStream()))
                                {
                                    requestBody = requestReader.ReadToEnd();
                                }
                                response.Close();

                                // we will try a trackback first before a pingback
                                // we need to auto discover the trackback url
                                // http://www.movabletype.org/docs/mttrackback.html

                                string trackbackUrl = GetTrackbackLink(requestBody, externalUri.AbsoluteUri);
                                if (trackbackUrl != null)
                                {
                                    TrackbackInfo info = new TrackbackInfo(trackbackUrl, job.info.SourceUrl, job.info.SourceTitle, job.info.SourceExcerpt, job.info.SourceBlogName);
                                    TrackbackWorker(new TrackbackJob(info, job.entry));
                                }

                                // first we try and get the X-Pingback HTTP header
                                // http://www.hixie.ch/specs/pingback/pingback
                                string pingbackService = response.GetResponseHeader("X-Pingback");

                                // if we don't get the header
                                // try and autodetect the auto pingback info
                                if (pingbackService == null || pingbackService.Length == 0)
                                {
                                    string[] split = pingbackRegex.Split(requestBody);

                                    if (split.Length == 1)
                                        pingbackService = split[0];
                                }

                                if (pingbackService != null && pingbackService.Length > 0)
                                {
                                    Pingback(job.info.SourceUrl, pingbackService, url, job.entry.Title);
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            ErrorTrace.Trace(TraceLevel.Error, e);
                            if (loggingService != null)
                            {
                                loggingService.AddEvent(
                                    new EventDataItem(EventCodes.Error,
                                    e.ToString().Replace("\n", "<br />"),
                                    "PingbackWorker, auto-discovery of: " + url));
                            }
                        }
                    }
                }
            }
        }