Copied to clipboard

Flag this post as spam?

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


  • Lenni 6 posts 26 karma points
    Aug 20, 2010 @ 10:36
    Lenni
    0

    Working with events

    I would like to fire an event before deletion of my Data Types, any ideas how I can achieve that.

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Aug 20, 2010 @ 10:44
    Richard Soeteman
    0

    As far as I know there is no Event for that so the best you could do is create a ticket on Codeplex asking to implement this into Umbraco.

    Cheers,

    Richard

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Aug 20, 2010 @ 10:51
    Richard Soeteman
    0

    Oopsss, I'm sorry

    Try the umbraco.cms.businesslogic.datatype.DataTypeDefinition.Deleting event. For an overview of all events, check out http://our.umbraco.org/wiki/reference/api-cheatsheet/using-applicationbase-to-register-events/overview-of-all-events 

    Then you can use ApplicationBase to register your event in the constructor of your class. A tutorial can be foudn at http://our.umbraco.org/wiki/reference/api-cheatsheet/using-applicationbase-to-register-events 

    In your case the code would look similare to this:

     

    public class DataTypeDeleteSample : ApplicationBase

    {

     

    public DataTypeDeleteSample()

    {

    umbraco.cms.businesslogic.datatype.

    DataTypeDefinition.BeforeDelete += new EventHandler<umbraco.cms.businesslogic.DeleteEventArgs>(DataTypeDefinition_BeforeDelete);

    umbraco.cms.businesslogic.datatype.

    DataTypeDefinition.AfterDelete += new EventHandler<umbraco.cms.businesslogic.DeleteEventArgs>(DataTypeDefinition_AfterDelete);

    }

     

     

    void DataTypeDefinition_BeforeDelete(object sender, umbraco.cms.businesslogic.DeleteEventArgs e)

    {

     

    //Gets triggered before the delete of a DataType

    }

     

    void DataTypeDefinition_AfterDelete(object sender, umbraco.cms.businesslogic.DeleteEventArgs e)

    {

     

    //Gets triggered After the delete of a DataType

    }

    }

  • Lenni 6 posts 26 karma points
    Aug 20, 2010 @ 11:03
    Lenni
    0

    Thanks alot, I'm quite sure this will do the trick.. I do however need to catch the NodeID that fires the delete event, how would I do that?

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Aug 20, 2010 @ 11:07
    Richard Soeteman
    0

    I think that will be included in the sender parameter, you should set a breakpoint and see what happens.

  • Lenni 6 posts 26 karma points
    Aug 20, 2010 @ 11:18
    Lenni
    0

    Thanks again Richard, your awesome!

  • Lenni 6 posts 26 karma points
    Aug 20, 2010 @ 13:23
    Lenni
    0

    I'm not quite sure what's happening, but everytime the BeforeDelete event fires, the deleted entrie says Deleting.. and get's stuck there, with the page done loading. If I refresh the page, the Data Types tree no longer populates and I have to reinstall Umbraco. My code is simple and I can't see what's causing the problem.

    namespace NutsAndBolts.Tables
    {
        public class DataTypeDeleteEvents : ApplicationBase
        {
            public DataTypeDeleteEvents()
            {
                DataTypeDefinition.BeforeDelete
      += new EventHandler<umbraco.cms.businesslogic.DeleteEventArgs>
    (DataTypeDefinition_BeforeDelete);
            }

            void DataTypeDefinition_BeforeDelete
    (object sender, umbraco.cms.businesslogic.DeleteEventArgs e)
            {
                {
                    HttpContext.Current.Response.Write
    ("Sender ID: " + ((DataTypeDefinition)sender).Id);

                }
            }
        }
    }
  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Aug 20, 2010 @ 13:30
    Richard Soeteman
    0

    I think you kill the rendering using the line HttpContext.Current.Response.Write

     

  • Lenni 6 posts 26 karma points
    Aug 20, 2010 @ 13:40
    Lenni
    0

    Oh.. snap... How else would I go about debugging this code in this event, it seems that normal debugging kills the rendering as well and cause the same problem. That's why I tried to Response.Write information but I suppose I can't do that either.

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Aug 20, 2010 @ 13:58
    Richard Soeteman
    0

    You can attach your debuuger to the worker process and set a breakpoint. Check out this post from Tim how to do that.

  • Lenni 6 posts 26 karma points
    Aug 20, 2010 @ 14:10
    Lenni
    0

    That's what I did and it broke the rendering, so now I'm just using log entries to check my information.

    Thanks for all your assistance, you've been great.

Please Sign in or register to post replies

Write your reply to:

Draft