Copied to clipboard

Flag this post as spam?

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


  • wgaddis 8 posts 78 karma points
    Jan 10, 2019 @ 21:05
    wgaddis
    0

    FileService event handlers

    Hello, I've been trying to implement an event handler for the FileService event SavedTemplate (to make a log of template modifications). I'm following the documentation as closely as I can, but when I try to add my handler to the savedTemplate property of the FileService class, I get a

    No overload for "my_handler" matches delegate TypedEventHandler

    using System.Web.UI;
    using Umbraco.Core;
    using Umbraco.Core.Services;
    
    
    namespace Infrastructure.Events
    {
        public class UmbracoTemplateSavedHandler : ApplicationEventHandler
        {
            protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            {
                FileService.SavingTemplate += FileService_SavedTemplate;
                base.ApplicationStarted(umbracoApplication, applicationContext);
            }
    
            private void FileService_SavedTemplate(IFileService sender, Umbraco.Core.Events.SaveEventArgs<ITemplate> e)
            {
                //Log template here
            }
        }
    }
    

    I don't really see anything in the docs that point to anything more concrete for what my method signature should look like. What am I missing here?

  • Kevin Jump 2342 posts 14889 karma points MVP 8x c-trib
    Jan 10, 2019 @ 22:23
    Kevin Jump
    0

    Hi,

    not 100% sure what you have (the forums have messed the code up a bit).

    but your register event should look like this.

    FileService.SavedTemplate += FileService_SavedTemplate;
    

    with you're handler function looking like this :

        private void FileService_SavedTemplate(IFileService sender, Umbraco.Core.Events.SaveEventArgs<ITemplate> e)
        {
            /// do stuff here
        }
    

    You can see this in how uSync tracks template changes here : https://github.com/KevinJump/uSync/blob/v4_master/Jumoo.uSync.BackOffice/Handlers/TemplateHandler.cs#L108

  • wgaddis 8 posts 78 karma points
    Jan 16, 2019 @ 21:34
    wgaddis
    0

    I found a naming collision (Umbraco.Core.Events wasn't working due to a namespace *.Umbraco.Template in my solution), but I fixed it and I'm still getting the delegate matching error when trying to assign the custom handler.

  • wgaddis 8 posts 78 karma points
    Jan 16, 2019 @ 15:05
    wgaddis
    0

    Yeah, that's identical to what I have (only difference is not fully qualifying the namespace for SaveEventArgs, which intellisense says it's getting the correct one).

    Still getting the "no overload matches the delete" error on the FileService.SavedTemplate assignment when I'm calling it in an override for ApplicationStarted.

  • wgaddis 8 posts 78 karma points
    Jan 21, 2019 @ 16:50
    wgaddis
    0

    Updated the OP with a better code example.

Please Sign in or register to post replies

Write your reply to:

Draft