⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sendpings.cs

📁 个人博客系统
💻 CS
字号:
#region using

using System;
using System.Web;
using BlogEngine.Core.Web.Controls;
using BlogEngine.Core;
using System.Net.Mail;
using System.Threading;

#endregion

/// <summary>
/// Pings all the ping services specified on the 
/// PingServices admin page and send track- and pingbacks
/// </summary>
[Extension("Pings all the ping services specified on the PingServices admin page and send track- and pingbacks", "1.1", "BlogEngine.NET")]
public class SendPings
{

  /// <summary>
  /// Hooks up an event handler to the Post.Saved event.
  /// </summary>
  public SendPings()
  {
    Post.Saved += new EventHandler<SavedEventArgs>(Post_Saved);
  }

  /// <summary>
  /// Sends the pings in a new thread.
  /// <remarks>
  /// It opens a new thread and executes the pings from there,
  /// because it takes some time to complete.
  /// </remarks>
  /// </summary>
  private void Post_Saved(object sender, SavedEventArgs e)
  {
    Post post = (Post)sender;
    if (!HttpContext.Current.Request.IsLocal && post.IsPublished)
    {
      ThreadStart threadStart = delegate { Ping(post); };
      Thread thread = new Thread(threadStart);
      thread.IsBackground = true;
      thread.Start();
    }
  }

  /// <summary>
  /// Executes the pings from the new thread.
  /// </summary>
  private void Ping(object stateInfo)
  {
    System.Threading.Thread.Sleep(2000);
    Post post = (Post)stateInfo;

    // Ping the specified ping services.
    BlogEngine.Core.Ping.PingService.Send();

    // Send trackbacks and pingbacks.
    if (post.Content.ToLowerInvariant().Contains("http"))
      BlogEngine.Core.Ping.Manager.Send(post);
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -