BlogEngine.Core/Ping/Manager.cs

(开头部分) 3KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

#region Using

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Net;

#endregion

namespace BlogEngine.Core.Ping
{
    /// <summary>
    /// Manages to send out trackbacks and then pingbacks if trackbacks aren't supported by the linked site.
    /// </summary>
    public static class Manager
    {
        /// <summary>
        /// Sends the trackback or pingback message.
        /// <remarks>
        /// It will try to send a trackback message first, and if the refered web page
        /// doesn't support trackbacks, a pingback is sent.
        /// </remarks>
        /// </summary>
        public static void Send(IPublishable item, Uri itemUrl)
        {
            foreach (Uri url in GetUrlsFromContent(item.Content))
            {
                string pageContent = ReadFromWeb(url);
                Uri trackbackUrl = GetTrackBackUrlFromPage(pageContent);
                bool isTrackbackSent = false;

                if (trackbackUrl != null)
                {
                    TrackbackMessage message = new TrackbackMessage(item, trackbackUrl, itemUrl);
                    isTrackbackSent = Trackback.Send(message);
                }

                if (!isTrackbackSent)
                {
                    Pingback.Send(itemUrl, url);
                }
            }
        }

        #region "RegEx Methods"

        /// <summary>
        /// Regex used to find all hyperlinks.
        /// </summary>
        //private static readonly Regex urlsRegex = new Regex(@"\<a\s+href=""(http://.*?)"".*\>.+\<\/a\>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
        private static readonly Regex urlsRegex = new Regex(@"<a[^(href)]?href=""([^""]+)""[^>]?>([^<]+)</a>", RegexOptions.IgnoreCase | RegexOptions.Compiled);

        /// <summary>
        /// Regex used to find the trackback link on a remote web page.
        /// </summary>
        private static readonly Regex trackbackLinkRegex = new Regex("trackback:ping=\"([^\"]+)\"", RegexOptions.IgnoreCase | RegexOptions.Compiled);

        /// <summary>
        /// Gets all the URLs from the specified string.
后面还有 48 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。