Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Earvin 4 posts 34 karma points
    Apr 16, 2014 @ 06:16
    Earvin
    0

    Umbraco Events not firing??

    Hi,

    I have a Umbraco 7 project which I would like to start customizing business logic within the events. I have created a class and used the following code from the documentation to get started. When I add a breakpoint to the 'Application Started' or 'Document Before publish' it never seems to get hit. Is there any additional requirements that I need to set or something that I have missed?

     

    using Umbraco.Core;

    using umbraco.BusinessLogic;

    using umbraco.cms.businesslogic;

    using umbraco.cms.businesslogic.web;

     

    namespace Umbraco.Extensions.EventHandlers

    {

        public class RegisterEvents : ApplicationEventHandler

        {

            protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)

            {

                Document.BeforePublish += Document_BeforePublish;

            }

     

            private void Document_BeforePublish(Document sender, PublishEventArgs e)

            {

                //Do what you need to do. In this case logging to the Umbraco log

                Log.Add(LogTypes.Debug, sender.Id, "the document " + sender.Text + " is about to be published");

     

                //cancel the publishing if you want.

                e.Cancel = true;

            }

        }

    }

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Apr 16, 2014 @ 13:14
    Ismail Mayat
    100

    Earvin,

    In v7 you need to use content service to wire up events also in my code i am inheriting from IApplicationEventHandler see http://our.umbraco.org/documentation/Reference/Events-v6/ContentService-Events so you need:

    public class Events : IApplicationEventHandler
    {            
        public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
    
            ContentService.Publishing += ContentService_Publishing;           
        }
    
        void ContentService_Publishing(Umbraco.Core.Publishing.IPublishingStrategy sender, Umbraco.Core.Events.PublishEventArgs<Umbraco.Core.Models.IContent> e)
        {
            throw new NotImplementedException();
        }
    

    }

  • Earvin 4 posts 34 karma points
    Apr 17, 2014 @ 00:41
    Earvin
    0

    Thanks! That worked perfectly.

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Apr 17, 2014 @ 09:59
    Ismail Mayat
    0

    Earvin,

    Don't forget to mark as solution.

    Regards

    Ismail

Please Sign in or register to post replies

Write your reply to:

Draft