Copied to clipboard

Flag this post as spam?

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


  • daniel 13 posts 83 karma points
    Mar 28, 2017 @ 21:43
    daniel
    0

    MediaService.Saved is not triggering when debugging

    I'm working with load balancing servers and making sure the content in Umbraco matches across both servers. I have no problems with saving my Views and Partials Views to both servers by using an Application Event Handler such as

    FileService.SavedTemplate += Template_Saved;
    
    private void Template_Saved(IFileService sender, SaveEventArgs<ITemplate> e)
            {
                foreach (var savedFile in e.SavedEntities)
                {
                    if (savedFile.VirtualPath == null) continue;
                    var virtualPathOfName =
                        GetVirtualPathOfName(savedFile);
                    if (string.Compare(savedFile.VirtualPath, virtualPathOfName, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        SaveToServers(savedFile.VirtualPath);
                    }
                    else
                    {
                        RenameInFolderAndCheckIn(savedFile.VirtualPath, savedFile.Name);
                    }
                }
            }
    

    However, it doesn't appear to work the same with when I save images using something like this

    MediaService.Saved += MediaServiceSaved;
    
    private void MediaServiceSaved(IMediaService sender, SaveEventArgs<IMedia> e)
            {
                foreach (var savedMedia in e.SavedEntities)
                {
                    var path = savedMedia.GetValue<string>("umbracoFile");
    
                    var filePath = ReturnFilePathFromJsonPath(path);
                    SaveToServers(filePath);
                    SaveToServers(filePath.Replace(".jpg", "_thumb.jpg"));
    
                }
            }
    

    When I set up a breakpoint at my TemplateSaved method, the breakpoint hits whenever I make a change to my template. From there I can walk through my code and make sure the template saves to both servers. However when I go to add an image or delete and remove one, it does not hit the MediaServiceSaved method as I had expected it to. Am i using the correct Event Handler for saving images?

    Thanks

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Mar 29, 2017 @ 09:06
    Jeavon Leopold
    0

    Hi Daniel,

    When in a load balanced configuration you need to use Cache events as these will be triggered on all servers unlike normal events (ContentService etc..) that will occur only on the publishing server.

    These are the most commonly used events (there are plenty of others) as they cover content changes:

            CacheRefresherBase<PageCacheRefresher>.CacheUpdated += this.CachePageEvents_CacheUpdated;
            CacheRefresherBase<DictionaryCacheRefresher>.CacheUpdated += this.CacheDictionaryEvents_CacheUpdated;
            CacheRefresherBase<MediaCacheRefresher>.CacheUpdated += this.CacheMediaEvents_CacheUpdated;
    

    Jeavon

  • daniel 13 posts 83 karma points
    Mar 29, 2017 @ 14:12
    daniel
    0

    This isn't on a load balanced server yet. This is just running locally. I'm looking to trigger the MediaServiceSaved event when running locally.

Please Sign in or register to post replies

Write your reply to:

Draft