Copied to clipboard

Flag this post as spam?

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


  • Darren Ferguson 1022 posts 3259 karma points MVP c-trib
    Jun 11, 2009 @ 11:42
    Darren Ferguson
    0

    Getting events working in v4?

    All,

    Delving into v4 events and can't seem to get them working!
    Here is my code, I'm expecting to see some log entries but am not getting any...

    [code]
    using System;
    using umbraco.cms.businesslogic.media;
    using umbraco.cms.businesslogic.web;
    using umbraco.cms.businesslogic;
    using umbraco.BusinessLogic;

    namespace FergusonMoriyama.xxx
    {
    class xxx: umbraco.BusinessLogic.ApplicationBase
    {

    public xxx()
    {
    Media.New += new Media.NewEventHandler(mediaAfterNew);
    Document.New += new Document.NewEventHandler(documentnew);
    }

    void mediaAfterNew(Media sender, NewEventArgs e)
    {
    Log.Add(LogTypes.Debug, sender.Id, "Hello world");
    }

    void documentnew(Document sender, NewEventArgs e)
    {
    Log.Add(LogTypes.Debug, sender.Id, "Hello world");
    }
    }



    }
    [/code]


    Are there any additional steps beyond placing my DLL in the bin directory that need to be considered?

    Thanks!

  • Richard Soeteman 4049 posts 12922 karma points MVP 2x
    Jun 11, 2009 @ 11:58
    Richard Soeteman
    0

    Hi Darren,

    No it should be working (at least in v4.0.1). And Haven't tried the events you are using. What I always try first is setting a breakpoint on the event handlers to see if they get hit. Maybe an exception is thrown and you won't see that.

    Hope it helps you,

    Richard

  • Darren Ferguson 1022 posts 3259 karma points MVP c-trib
    Jun 11, 2009 @ 12:47
    Darren Ferguson
    0

    sorry, silly mistake.

    my constructor wasn't marked public!

  • Kim Løwert 130 posts 116 karma points
    Jul 30, 2010 @ 16:35
    Kim Løwert
    0

    Hi Darren,

    Have you testet your code in umbraco 4.5? I'm having a similar issue after having upgraded from 4.0 (.Net 2.0) to 4.5 (.Net 4.0). My code is the following which worked well in 4.0:

    using System;

    using umbraco;

    using umbraco.BusinessLogic;

    using umbraco.cms.businesslogic.web;

     

    /// <summary>

    /// UmbracoNewsHandler handles events that are related to the Umbraco News

    /// </summary>

    /// 

    namespace umbraco.appstract

    {

        public class UmbracoNewsItemHandler : ApplicationBase

        {

            public UmbracoNewsItemHandler()

            {

                Document.New += new Document.NewEventHandler(Document_New);

                //umbraco.cms.businesslogic.web.Document.New += new umbraco.cms.businesslogic.web.Document.NewEventHandler(Document_New);

     

                umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Debug, -1, "The eventhandlers are attached");

            }

     

            /// <summary>

            /// Event handler for new news pages

            /// </summary>

            /// <param name="sender">The newly created document</param>

            /// <param name="e"></param>

            public void Document_New(umbraco.cms.businesslogic.web.Document sender, umbraco.cms.businesslogic.NewEventArgs e)

            {

                umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Debug, -1, "The eventhandler Document_new is fired");

            }

            

        }

    }

    I wanted to upgrade my package for umbraco so that it works with 4.5
    Thanks a lot in advance :)
    Kim

  • Simon Justesen 436 posts 203 karma points
    Aug 02, 2010 @ 03:10
    Simon Justesen
    0

    I've encountered these issues as well (4.5 & 4.5.1) 
    Tried subscribing to Member_New, Member_AfterNew and Member_Delete .. none of them seems to fire. The constructor in the document inheriting from ApplicationBase does not seem to be executed either.


    /Simon

  • Kim Løwert 130 posts 116 karma points
    Aug 03, 2010 @ 16:01
    Kim Løwert
    0

    Hi Simon,

     

    That is the exact same issue I'm experiencing. The constructor in the class inheriting from ApplicationBase does not seem to get executed. And this is only an issue with the code in v4.5.

    Are anybody experiencing the same issues?

    /Kim

  • Simon Justesen 436 posts 203 karma points
    Aug 11, 2010 @ 01:39
    Simon Justesen
    0

    Hi Kim,

    Good to hear I'm not the only one experiencing this. Has anyone reported this issue on codeplex? (otherwise I'll do it :))
    It's quite a showstopper for the project I'm working on.

    / Simon

  • Kim Løwert 130 posts 116 karma points
    Aug 11, 2010 @ 13:06
    Kim Løwert
    0

    Hi Simon,

    Well I'm glad too to hear that I'm not the only one with the issue either, as I just cannot see what I'm doing wrong! I have reported the issue to Tim who is looking into my specific issue but I haven't reported it on codeplex. But please do so :) It is a show stopper for me as well and I would like to update my News package for others to use in v4.5

    /Kim

  • Kim Løwert 130 posts 116 karma points
    Aug 11, 2010 @ 13:37
    Kim Løwert
    0

    Hi Simon,

    I have created the CP issue. I'll update if I find a solution before that.

    /Kim

  • Simon Justesen 436 posts 203 karma points
    Aug 12, 2010 @ 16:48
    Simon Justesen
    0

    Okay, I created a similar issue yesterday. ;)

    http://umbraco.codeplex.com/workitem/28514

  • Kim Løwert 130 posts 116 karma points
    Aug 24, 2010 @ 16:38
    Kim Løwert
    1

    Hi Simon

    I have tried to add the eventhandler in a Class Library, compiled it and added it to the project (/bin) which resulted in the events being hooked up correctly.

    So the error only affects ActionHandlers written directly in the App_Code folder - not precompiled Class Libraries.

    This should solve your issue as well I hope :)

    Cheers,

    Kim

  • Simon Justesen 436 posts 203 karma points
    Sep 17, 2010 @ 18:50
    Simon Justesen
    0

    Hi Kim,

    Yes it did - Niels also mentioned the same solution on twitter, but I forgot all about posting the solution in here,  but thanks for testing it out!

    Have a great weekend :)

  • Robert Hughes 87 posts 110 karma points
    May 30, 2012 @ 22:52
    Robert Hughes
    0

    I am just new to this but I found my events fired but I could not debug them until I put them in a separate project. Probably a better architecture anyway perhaps?

Please Sign in or register to post replies

Write your reply to:

Draft