Copied to clipboard

Flag this post as spam?

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


  • Simon steed 376 posts 688 karma points
    Mar 21, 2011 @ 18:02
    Simon steed
    0

    Cannot debug custom event handlers i.e. BaseTree_BeforeNodeRender from class libray

    Hi,

    I've got a multilingual project i'm working upon that I want to set the parent node icon of the relevant site to either German or English flag.

    Searched around, found a couple of posts that sort of did what I wanted so modified to suit but the problem is the content tree shows no nodes at all and even though I attach the debugger (VS2010 with Umbraco 4.5.2), the break point is not being hit at all.

    The way the project it setup is a separate class libray which I use for my other custom code (no event handlers though), i've added the following code as a new class, recompiled which adds it to the bin folder as a compiled dll and ran the site.

    If I comment out everthing within the node.NoteType == "content" section, the nodes show in the content tree - seems when it hits List<Domains> etc, it bombs out but no error shown.

    Anyone got any suggestions - Debug mode is set to on in the web.config file btw :-)

    p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.5px Consolas} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.5px Consolas; min-height: 11.0px} p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.5px Consolas; color: #30a1ba} p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.5px Consolas; color: #919191} p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.5px Consolas; color: #008d20} span.s1 {color: #003ffa} span.s2 {color: #000000} span.s3 {color: #30a1ba} span.s4 {color: #008d20} span.s5 {color: #919191} span.s6 {color: #b42626}

    using System;

    using umbraco.BusinessLogic;

    using umbraco.cms.presentation.Trees;

    using umbraco.interfaces;

    using umbraco.cms.businesslogic.web;

    using System.Collections.Generic;

     

    namespace SimonAntony

    {

        public class UmbracoSpecials : ApplicationBase

        {

     

            public UmbracoSpecials()

            {

                BaseContentTree.BeforeNodeRender += new BaseTree.BeforeNodeRenderEventHandler(BaseTree_BeforeNodeRender);

            }

     

            /// <summary>

            /// Change the icon of the parent node based upon the domain

            /// </summary>

            private void BaseTree_BeforeNodeRender(ref XmlTree sender, ref XmlTreeNode node, EventArgs e)

            {

                if (node.Menu != null)

                {

                    if (node.NodeType == "content")

                    {

                        List<Domain> domains = Domain.GetDomains();

     

                        if (domains != null && domains.Count > 0)

                        {

                            foreach (Domain domain in domains)

                            {

                                if (domain.RootNodeId.ToString() == node.NodeID)

                                {

                                    node.Icon = String.Concat("/umbraco/images/umbraco/", domain.Language.CultureAlias, ".png");

                                }

                            }

                        }

                    }

                }

     

            }

     

        }

    }

    Si

  • Eran Meir 401 posts 543 karma points
    Mar 21, 2011 @ 18:28
    Eran Meir
    0

    did you copy the pdb file to the bin directory?

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Mar 21, 2011 @ 18:36
    Lee Kelleher
    0

    Hi Simon,

    Just to clarify, putting the debugging to the side, are you saying that with your code, the content node tree isn't appearing?

    Does it appear without your code? (remove/comment-out).   To me, your code appears fine - can't see any gotchas!

    As for debugging... like Eran suggested, .pdb files.  Also double check which worker-process that you are attaching to (caught me out many times).

    Cheers, Lee.

  • Simon steed 376 posts 688 karma points
    Mar 21, 2011 @ 18:41
    Simon steed
    0

    Sorted the debugging issue - thanks for the pdb tip, Wierd thing is i'm also handling Document.AfterSave and that debugged fine doh!!! 

    Code still baulks out, wondering if an internal bug - if I remove List etc still debugs through, if I leave it in doesnt so going to find another way to achieve the same thing.

    Lee - basically if I include the file as above, the content tree only shows Content and nothing underneath it. If I comment out, the nodes load fine.

    Will post the final solution once it's done, at least someone else will be able to make use :-)

    Si

     

  • Simon steed 376 posts 688 karma points
    Mar 21, 2011 @ 18:47
    Simon steed
    0

    This is just bloody wierd!! The following code allows me to debug but the second block doesnt debug at all! What the hell is going on here? Maybe i'll just backup the site/db and upgrade it all to 4.7 and see if that resolves it:

    private void BaseTree_BeforeNodeRender(ref XmlTree sender, ref XmlTreeNode node, EventArgs e)

            {

                if (node.Menu != null)

                {

                    if (node.NodeType == "content") // breakpoint here fires fine

                    {

                        

                    }

                }

     

            }

    private void BaseTree_BeforeNodeRender(ref XmlTree sender, ref XmlTreeNode node, EventArgs e)

            {

                if (node.Menu != null)

                {

                    if (node.NodeType == "content") // breakpoint here never fires when the following line is present - delete it and it works!

                    {

                        int iDomain = Domain.GetDomains().Count;

                        

                    }

                }

     

            }

     

  • Simon steed 376 posts 688 karma points
    Mar 23, 2011 @ 17:27
    Simon steed
    0

    Update time - finally got upgraded to 4.7 and now allows me to debug into the above posted code, however now i'm getting errors of another kind....

     

    Attempt by method 'UserControls.UmbracoSpecials.BaseTree_BeforeNodeRender(umbraco.cms.presentation.Trees.XmlTree ByRef, umbraco.cms.presentation.Trees.XmlTreeNode ByRef, System.EventArgs)' to access method 'umbraco.cms.businesslogic.web.Domain.GetDomains()' failed.

    It fails at the line  List<Domain> domains = Domain.GetDomains();

     

    So why is Domain.GetDomains() being disallowed access? Is there another method I should be using in 4.7?

    Pondering....

    Si

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 23, 2011 @ 17:46
    Tom Fulton
    0

    You could try umbraco.library.GetCurrentDomains(int NodeId)

  • Simon steed 376 posts 688 karma points
    Mar 23, 2011 @ 19:29
    Simon steed
    0

    Cheers

    In the end I just needed to get it nailed and quickly, spent too much time debugging this so done it based upon the node title rather than the proper way - yes it's a hack but it works and I can finish the site now

    Will look at GetCurrentDomains when I get a spare 5

    Si

Please Sign in or register to post replies

Write your reply to:

Draft