Beispiel #1
0
    /// <summary>
    /// Handles the Saved event of the Post control.
    /// 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>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="BlogEngine.Core.SavedEventArgs"/> instance containing the event data.</param>
    private static void PostSaved(object sender, SavedEventArgs e)
    {
        if (!ExtensionManager.ExtensionEnabled("SendPings"))
            return;

        if (e.Action == SaveAction.None || e.Action == SaveAction.Delete)
            return;

        var item = (IPublishable)sender;
        if (!item.IsVisibleToPublic)
            return;

        var url = item.AbsoluteLink;

        // Need blogSettings to pass to Ping since the current blog instance won't
        // be detectable once in a BG thread.
        Guid blogId = Blog.CurrentInstance.Id;
        ThreadPool.QueueUserWorkItem(state =>
            {
                // because HttpContext is not available within this BG thread
                // needed to determine the current blog instance,
                // set override value here.
                Blog.InstanceIdOverride = blogId;

                Ping(item, url);
            });
    }
Beispiel #2
0
 static void Post_Saved(object sender, SavedEventArgs e)
 {
     // invalidate cache whenever a post is modified
     lock (_SyncRoot)
     {
         HttpRuntime.Cache.Remove(CacheKey);
     }
 }
Beispiel #3
0
    /// <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 static void Post_Saved(object sender, SavedEventArgs e)
    {
        if (e.Action == SaveAction.None || e.Action == SaveAction.Delete)
            return;

        IPublishable item = (IPublishable)sender;

        if ((HttpContext.Current == null || !HttpContext.Current.Request.IsLocal) && item.IsVisible)
        {
            Uri url = item.AbsoluteLink;
            ThreadPool.QueueUserWorkItem(delegate { Ping(item, url); });
        }
    }
Beispiel #4
0
    /// <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 static void Post_Saved(object sender, SavedEventArgs e)
    {
        if (e.Action == SaveAction.None || e.Action == SaveAction.Delete)
            return;

        IPublishable item = (IPublishable)sender;

        if (item.IsVisibleToPublic)
        {
            Uri url = item.AbsoluteLink;
            ThreadPool.QueueUserWorkItem(delegate { Ping(item, url); });
        }
    }
Beispiel #5
0
 private static void Page_Saved(object sender, SavedEventArgs e)
 {
     lock (_SyncRoot)
     {
         if (e.Action == SaveAction.Insert)
         {
             AddItem(sender as Page);
         }
         else
         {
             BuildCatalog();
         }
     }
 }
Beispiel #6
0
 /// <summary>
 /// Handles the Saved event of the Post control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="BlogEngine.Core.SavedEventArgs"/> instance containing the event data.</param>
 private static void Post_Saved(object sender, SavedEventArgs e)
 {
     lock (_syncRoot)
     {
         if (e.Action == SaveAction.Insert)
         {
             AddItem(sender as Post);
         }
         else
         {
             BuildEntries();
         }
     }
 }
    /// <summary>
    /// Handles the Saved event of the Post control.
    /// 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>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="BlogEngine.Core.SavedEventArgs"/> instance containing the event data.</param>
    private static void PostSaved(object sender, SavedEventArgs e)
    {
        if (e.Action == SaveAction.None || e.Action == SaveAction.Delete)
        {
            return;
        }

        var item = (IPublishable)sender;
        if (!item.IsVisibleToPublic)
        {
            return;
        }
        
        var url = item.AbsoluteLink;
        ThreadPool.QueueUserWorkItem(state => Ping(item, url));
    }
        /// <summary>
        /// Handles the Saved event of the BlogRollItem control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="BlogEngine.Core.SavedEventArgs"/> instance containing the event data.</param>
        private static void BlogRollItemSaved(object sender, SavedEventArgs e)
        {
            switch (e.Action)
            {
                case SaveAction.Insert:
                    AddBlog((BlogRollItem)sender);
                    break;
                case SaveAction.Delete:
                    var affected = items.FirstOrDefault(req => req.RollItem.Equals(sender));
                    items.Remove(affected);
                    break;
            }

            if (((e.Action == SaveAction.Insert || e.Action == SaveAction.Delete) || e.Action == SaveAction.Update) &&
                items.Count > 0)
            {
                // Re-sort _Items collection in case sorting of blogroll items was changed.
                items.Sort((br1, br2) => br1.RollItem.CompareTo(br2.RollItem));
            }
        }
Beispiel #9
0
        /// <summary>
        /// Handles the Saving event of the Publishable.
        /// </summary>
        /// <param name="sender">
        /// The source of the event.
        /// </param>
        /// <param name="e">
        /// The <see cref="BlogEngine.Core.SavedEventArgs"/> instance containing the event data.
        /// </param>
        private static void PublishableSaving(object sender, SavedEventArgs e)
        {
            // Set SendNewsletterEmails to true whenever a publishable is changing from an unpublished
            // state to a published state.  To check the published state of this publishable before
            // it was changed, it's necessary to retrieve the publishable from the datastore since the
            // publishable in memory (via Post.GetPost() or Page.GetPage()) will already have the
            // updated values about to be saved.

            var publishable = (IPublishable)sender;

            SetSendNewsletterEmails(publishable.Id, false); // default to not sending

            if (publishable is Post && !SendEmailsForPosts)
                return;
            else if (publishable is BlogEngine.Core.Page && !SendEmailsForPages)
                return;

            if (e.Action == SaveAction.Insert && publishable.IsVisibleToPublic)
            {
                SetSendNewsletterEmails(publishable.Id, true);
            }
            else if (e.Action == SaveAction.Update && publishable.IsVisibleToPublic)
            {
                var preUpdatePublishable = (IPublishable)null;

                if (publishable is Post)
                    preUpdatePublishable = (IPublishable)BlogService.SelectPost(publishable.Id);
                else
                    preUpdatePublishable = (IPublishable)BlogService.SelectPage(publishable.Id);

                if (preUpdatePublishable != null && !preUpdatePublishable.IsVisibleToPublic)
                {
                    // Note, use publishable.Id below instead of preUpdatePublishable.Id because
                    // when directly calling BlogService.SelectPage or BlogService.SelectPost,
                    // the Guid ID is not set, and so will be a random, non-matching Guid ID.

                    SetSendNewsletterEmails(publishable.Id, true);
                }
            }
        }
Beispiel #10
0
        /// <summary>
        /// Handles the Saved event of the Publishable.
        /// </summary>
        /// <param name="sender">
        /// The source of the event.
        /// </param>
        /// <param name="e">
        /// The <see cref="BlogEngine.Core.SavedEventArgs"/> instance containing the event data.
        /// </param>
        private static void PublishableSaved(object sender, SavedEventArgs e)
        {
            var publishable = (IPublishable)sender;

            if (!GetSendSendNewsletterEmails(publishable.Id))
            {
                return;
            }

            XmlNodeList emails = null;
            lock (syncRoot)
            {
                LoadEmails();

                emails = docs[Blog.CurrentInstance.Id].SelectNodes("emails/email");
            }

            if (emails == null) { return; }

            List<MailMessage> messages = new List<MailMessage>();
            foreach (XmlNode node in emails)
            {
                string address = node.InnerText.Trim();

                if (!Utils.StringIsNullOrWhitespace(address) && Utils.IsEmailValid(address))
                {
                    MailMessage message = CreateEmail(publishable);
                    message.To.Add(address);
                    messages.Add(message);
                }
            }
            if (messages.Count == 0) { return; }

            // retrieve the blogId before entering the BG thread.
            Guid blogId = Blog.CurrentInstance.Id;

            ThreadPool.QueueUserWorkItem(state =>
            {
                Thread.Sleep(3000);

                // because HttpContext is not available within this BG thread
                // needed to determine the current blog instance,
                // set override value here.
                Blog.InstanceIdOverride = blogId;

                foreach (MailMessage message in messages)
                {
                    Utils.SendMailMessage(message);
                }
            });
        }
Beispiel #11
0
        /// <summary>
        /// Handles the Saved event of the Post control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="BlogEngine.Core.SavedEventArgs"/> instance containing the event data.</param>
        private static void PostSaved(object sender, SavedEventArgs e)
        {
            if (e.Action != SaveAction.Update)
            {
                return;
            }

            var post = (Post)sender;
            if (RelatedPostsCache.ContainsKey(post.Id))
            {
                RelatedPostsCache.Remove(post.Id);
            }
        }
Beispiel #12
0
 static void Post_Saved(object sender, SavedEventArgs e)
 {
     if (e.Action != SaveAction.Update)
     BuildPostList();
 }
        /// <summary>
        /// Handles the Saved event of the Post control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="BlogEngine.Core.SavedEventArgs"/> instance containing the event data.</param>
        private static void PostSaved(object sender, SavedEventArgs e)
        {
            if (e.Action == SaveAction.Update)
            {
                return;
            }

            ClearCache(null, new EventArgs());
        }
        /// <summary>
        /// Handles the Saving event of the Post control.
        /// </summary>
        /// <param name="sender">
        /// The source of the event.
        /// </param>
        /// <param name="e">
        /// The <see cref="BlogEngine.Core.SavedEventArgs"/> instance containing the event data.
        /// </param>
        private static void PostSaving(object sender, SavedEventArgs e)
        {
            // Set SendNewsletterEmails to true whenever a post is changing from an unpublished
            // state to a published state.  To check the published state of this Post before
            // it was changed, it's necessary to retrieve the post from the datastore since the
            // post in memory (via Post.GetPost()) will already have the updated values about
            // to be saved.
            var post = (Post)sender;

            SetSendNewsletterEmails(post.Id, false); // default to not sending

            if (e.Action == SaveAction.Insert && post.IsVisibleToPublic)
            {
                SetSendNewsletterEmails(post.Id, true);
            }
            else if (e.Action == SaveAction.Update && post.IsVisibleToPublic)
            {
                var preUpdatePost = BlogService.SelectPost(post.Id);
                if (preUpdatePost != null && !preUpdatePost.IsVisibleToPublic)
                {
                    SetSendNewsletterEmails(post.Id, true);
                }
            }
        }
Beispiel #15
0
        private void BlogRollItem_Saved(object sender, SavedEventArgs e)
        {
            if (e.Action == SaveAction.Insert || e.Action == SaveAction.Update || e.Action == SaveAction.Delete)
            {
                if (e.Action == SaveAction.Insert)
                {
                    AddBlog((BlogRollItem)sender);
                }
                else if (e.Action == SaveAction.Delete)
                {
                    blogRequest affected = null;
                    foreach (blogRequest req in _Items)
                    {
                        if (req.RollItem.Equals(sender))
                        {
                            affected = req;
                            break;
                        }
                    }
                    _Items.Remove(affected);
                }

                if (_Items.Count > 0)
                {
                    // Re-sort _Items collection in case sorting of blogroll items was changed.
                    _Items.Sort(delegate(blogRequest br1, blogRequest br2) { return br1.RollItem.CompareTo(br2.RollItem); });
                }
            }
        }
Beispiel #16
0
        /// <summary>
        /// Handles the Saved event of the Post control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="BlogEngine.Core.SavedEventArgs"/> instance containing the event data.</param>
        private static void PostSaved(object sender, SavedEventArgs e)
        {
            if (e.Action == SaveAction.Update)
            {
                return;
            }

            BindComments();
        }
Beispiel #17
0
 static void Post_Saved(object sender, SavedEventArgs e)
 {
     if (e.Action == SaveAction.Update)
     {
         Post post = (Post)sender;
         if (_Cache.ContainsKey(post.Id))
             _Cache.Remove(post.Id);
     }
 }
Beispiel #18
0
        /// <summary>
        /// Handles the Saved event of the Post control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="BlogEngine.Core.SavedEventArgs"/> instance containing the event data.</param>
        private static void PostSaved(object sender, SavedEventArgs e)
        {
            if (e.Action == SaveAction.Update)
            {
                return;
            }

            BuildPostList();
        }
Beispiel #19
0
 static void Post_Saved(object sender, SavedEventArgs e)
 {
     if (e.Action != SaveAction.Update)
         BindComments();
 }
Beispiel #20
0
 static void Post_Saved(object sender, SavedEventArgs e)
 {
     Post post = (Post)sender;
     if (e.Action == SaveAction.Insert && post.IsPublished)
     {
         LoadEmails();
         foreach (XmlNode node in _Doc.SelectNodes("emails/email"))
         {
             MailMessage mail = CreateEmail(post);
             mail.To.Add(node.InnerText);
             Utils.SendMailMessageAsync(mail);
         }
     }
 }
	private void Post_Saving(object sender, SavedEventArgs e)
	{
		//### executing here will only run the code once per post, but will modify the post itself
		//InsertCopyCodeLink(e);
	}
        /// <summary>
        /// Handles the Saved event of the Post control.
        /// </summary>
        /// <param name="sender">
        /// The source of the event.
        /// </param>
        /// <param name="e">
        /// The <see cref="BlogEngine.Core.SavedEventArgs"/> instance containing the event data.
        /// </param>
        private static void PostSaved(object sender, SavedEventArgs e)
        {
            var post = (Post)sender;

            if (!GetSendSendNewsletterEmails(post.Id))
            {
                return;
            }

            LoadEmails();
            var emails = doc.SelectNodes("emails/email");
            if (emails == null)
            {
                return;
            }

            foreach (XmlNode node in emails)
            {
                var mail = CreateEmail(post);
                mail.To.Add(node.InnerText);
                Utils.SendMailMessageAsync(mail);
            }
        }