Я использую DNN 9 и хочу отправить уведомление с вложенным файлом, но кажется, что DNN не позволяет это сделать.
Есть ли способ (или обходной путь) сделать это?
Вот код DNN NotificationsController
и вот мой код, который вызывает код DNN
//...
Notification dnnNotification = new Notification
{
NotificationTypeID = notification.NotificationTypeId,
From = notification.From,
Subject = notification.Subject,
Body = notification.Body
};
NotificationsController.Instance.SendNotification(dnnNotification, portalId, dnnRoles, dnnUsers);
Вы не можете прикрепить файл к уведомлению в DNN. НО, вы можете добавить настраиваемые действия уведомления к типу уведомления. Эти действия приводят к добавлению ссылок под уведомлением (например, действие по умолчанию «Отклонить», чтобы пометить уведомление как «прочитанное»).
Чтобы отправить уведомление, вам нужно создать NotificationType, чтобы связать его. Действие NotificationTypeAction добавляется к типу. Поэтому всякий раз, когда вы отправляете уведомление определенного типа, действия выполняются вместе с ним.
Вы можете создать действие NotificationTypeAction и назвать его «Загрузить вложение». Когда пользователь нажимает на ссылку, он вызывает специальную службу API. Этот сервис может обслуживать файл.
Вот пример кода, в котором я создаю настраиваемый тип с 1 настраиваемым действием:
public void AddNotificationType()
{
var actions = new List<NotificationTypeAction>();
var deskModuleId = DesktopModuleController.GetDesktopModuleByFriendlyName(Constants.DESKTOPMODULE_FRIENDLYNAME).DesktopModuleID;
var objNotificationType = new NotificationType
{
Name = Constants.NOTIFICATION_FILEDOWNLOAD,
Description = "Get File Attachment",
DesktopModuleId = deskModuleId
};
if (NotificationsController.Instance.GetNotificationType(objNotificationType.Name) == null)
{
var objAction = new NotificationTypeAction
{
NameResourceKey = "DownloadAttachment",
DescriptionResourceKey = "DownloadAttachment_Desc",
APICall = "DesktopModules/MyCustomModule/API/mynotification/downloadfile",
Order = 1
};
actions.Add(objAction);
NotificationsController.Instance.CreateNotificationType(objNotificationType);
NotificationsController.Instance.SetNotificationTypeActions(actions, objNotificationType.NotificationTypeId);
}
}
Затем используйте следующий код для отправки уведомления:
public void SendNotification(UserInfo userToReceive)
{
// Get the notification type; if it doesn't exist, create it
ModuleController mCtrl = new ModuleController();
var itemAddedNType = NotificationsController.Instance.GetNotificationType(Constants.NOTIFICATION_FILEDOWNLOAD);
if (itemAddedNType == null)
{
AddNotificationType();
itemAddedNType = NotificationsController.Instance.GetNotificationType(Constants.NOTIFICATION_FILEDOWNLOAD);
}
if (itemAddedNType != null)
{
Notification msg = new Notification
{
NotificationTypeID = itemAddedNType.NotificationTypeId,
Subject = "A file is ready to download.",
Body = alertBody,
ExpirationDate = DateTime.MaxValue,
IncludeDismissAction = true,
};
List<UserInfo> sendUsers = new List<UserInfo>();
sendUsers.Add(userToReceive);
NotificationsController.Instance.SendNotification(msg, itemModule.PortalID, null, sendUsers);
}
}
Чтобы получить полное руководство по уведомлениям DNN, я настоятельно рекомендую подписаться на DNNHero.com и посмотреть эту серию из трех частей, в которую входит пример кода.
https://www.dnnhero.com/Premium/Tutorial/ArticleID/265/DNN-Notifications-Introduction-Part-1-3