Notifications
The package provides event-based notifications for CRUD operations on media access control entries and download attempts using the standard Umbraco notification pattern (INotification / INotificationHandler).
MediaPublicAccessEntryDeletingNotification
Triggered before a media access control entry is deleted and allows the operation to be cancelled.
public class MediaPublicAccessEntryDeletingNotification : DeletingNotification<MediaPublicAccessEntry>
MediaPublicAccessEntryDeletedNotification
Triggered when a media access control entry is deleted.
public class MediaPublicAccessEntryDeletedNotification : DeletedNotification<MediaPublicAccessEntry>
MediaPublicAccessEntrySavingNotification
Triggered before a media access control entry is saved and allows the operation to be cancelled.
public class MediaPublicAccessEntrySavingNotification : SavingNotification<MediaPublicAccessEntry>
MediaPublicAccessEntrySavedNotification
Triggered when a media access control entry is saved.
public class MediaPublicAccessEntrySavedNotification : SavedNotification<MediaPublicAccessEntry>
ProtectedMediaItemRequested
Triggered when an attempt is made to access a media item and contains details of the status of the operation
public class MediaPublicAccessEntrySavedNotification : INotification
/// <summary>
/// The file that is being requested
/// </summary>
public string Filename { get; }
/// <summary>
/// The username (if any) of the member requesting the item
/// </summary>
public string? Username { get; }
/// <summary>
/// The status of the operation
/// </summary>
public PublicAccessStatus PublicAccessStatus { get; }
/// <summary>
/// The public access entry that controlls access to the requested media item
/// </summary>
public MediaPublicAccessEntry PublicAccessDetails { get; }
#Example Usage
A common scenario might be to track downloads of protected media items. First we must create a class to handle the notification e.g.
public class MyNotificationsHandler : INotificationHandler<ProtectedMediaItemRequested>
{
public void Handle(ProtectedMediaItemRequested notification)
{
System.Diagnostics.Debug.WriteLine($"ProtectedMediaItemRequested FileName {notification.Filename}");
//Code to record/track the download goes here!
}
}
and then the notification handler must be registered in your composer, e.g.
public class MyComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.AddNotificationHandler<ProtectedMediaItemRequested, MyNotificationsHandler>();
}
}