IMediaContentDownloadedEvent problems

Posted by Community Admin on 04-Aug-2018 13:17

IMediaContentDownloadedEvent problems

All Replies

Posted by Community Admin on 02-Apr-2013 00:00

I'm noticing that if I visit /Sitefinity/Content/Documents the IMediaContentDownloadedEvent is triggering about 20 times (after the webservice callback completes)...the only data it's giving me are userid and the Url of the documents.

This should be a bug...nobody is downloading anything just browsing that page to see the documents...

Posted by Community Admin on 02-Apr-2013 00:00

...also...the event triggers twice when downloading an item from the backend?

Like
- Click Actions->Download
- Downloading->Downloaded
- Downloading->Downloaded
(same data in the event object)

Why would that be?

Also what's the diff between the IMediaContentDownloadingEvent, IMediaContentDownloadedEvent, and IMediaContentDownloadEvent...they all seem the same (the event object anyway)?

Posted by Community Admin on 05-Apr-2013 00:00

Hi,

IMediaContentDownloadingEvent is raised before a media content item (e.g. image) is downloaded and IMediaContentDownloadedEvent is raised after the operation has completed. Both inherits from IMediaContentDownloadEvent.

We will investigate if this is a bug, however please note that it is possible to have problems using these events because they are in development and there is still no documentation how to use them.

Regards,
Stefani Tacheva
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 05-Apr-2013 00:00

Actually they are documented, rather extensively...in fact the code I'm using is FROM that document :)

http://www.sitefinity.com/documentation/documentationarticles/developers-guide/deep-dive/sitefinity-event-system/list-of-events/libraries-events

Posted by Community Admin on 10-Apr-2013 00:00

Hello Steve,

Please excuse us for the introduced confusion, I believe what Stefani was trying to communicate is that the specification for how the events behave could be subject to change, as we're trying to address any usability issues we discover.

As for the difference between them, it's mainly when we subscribe to the particular event handler. In LibraryHttphandler we have:

if (outputItem != null)
               
                   var downloadingEvent = factory.CreateMediaContentDownloadingEvent(outputItem, request, url);
                   EventHub.Raise(downloadingEvent, true);
 
                   this.SendCachedResponse(request, response, outputItem);
 
                   var downloadedEvent = factory.CreateMediaContentDownloadedEvent(outputItem, request, url);
                   EventHub.Raise(downloadedEvent, false);
               
and SendCachedResponse is actually the place where we write the item data to Response.OutputStream, so in practice there is a clear distinction between the events. The object is the same, yes, as it's the same item we're accessing.

By the way, isn't the order you're observing
Actions ->Download ->2xIMediaContentDownloadingEvent -> Save as... window appears ->2xIMediaContentDownloadedEvent

If that's not the case, then could it be that you've replaced the Telerik.Sitefinity.Modules.Libraries.Web.LibraryHttpHandler by any chance, as the above should be the default behavior? We just need to confirm why the 2x loading of the event handler - something I'm going to get back to you with by the end of the business day today.

Regards,
Boyan Barnev
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 10-Apr-2013 00:00

This is the line I used in the event to debug

public static void LibrariesEventHandler(IMediaContentDownloadEvent  eventInfo, DownloadType type)
        
            Debug.WriteLine(DateTime.Now + " " + type.ToString() + " " + eventInfo.Title);

...and this is the result
4/10/2013 10:48:51 AM Downloading CaseStudy_Eventboard-Falafel
4/10/2013 10:48:51 AM Downloading CaseStudy_Eventboard-Falafel
4/10/2013 10:48:51 AM Downloaded CaseStudy_Eventboard-Falafel
4/10/2013 10:48:51 AM Downloaded CaseStudy_Eventboard-Falafel

Sorry should also say, I clicked a PDF in FF (On a download widget list), and it loaded into the viewer in the browser, no save-as popup

Posted by Community Admin on 10-Apr-2013 00:00

Hello Steve,

Thnak you for the additional input.

No , that makes perfect sense, I was initially surprised as I interpreted:

Click Actions->Download
- Downloading->Downloaded
- Downloading->Downloaded

 as Download ->Downloading->Downloaded->Downloading->Downloaded, which was definitely an incorrect behavior.

Regarding the double firing in first place, can you please let me know where exactly in your Global.asax you're subscribing to the Events?

Please ntoe that if you're doing it in Bootstrapper_Initialized you need to make a check whether the command for which this handler fires is "Bootstrapped", otherwise it would pass twice through your handler subscription, and consecutively execute the handlers twice,a s it registers tow handlers.

Long story short doing:

protected void Application_Start(object sender, EventArgs e)
        
            Bootstrapper.Initialized += Bootstrapper_Initialized;
        
 
        void Bootstrapper_Initialized(object sender, Telerik.Sitefinity.Data.ExecutedEventArgs e)
        
            if (e.CommandName == "Bootstrapped")
            
                EventHub.Subscribe<IMediaContentDownloadingEvent>(evt => LibrariesEventHandler(evt));
                EventHub.Subscribe<IMediaContentDownloadedEvent>(evt => LibrariesEventHandler(evt));
              
        


Should result in

Download -> Downloading-> Downloaded

Regards,
Boyan Barnev
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 10-Apr-2013 00:00
This thread is closed