public static void ProcessNotificationItem(NotificationItem ni, string messageId, string body) { if (ni != null) { var _notificationService = Bootstrapper.GetKernel().Resolve <INotificationService>(); var _communicationService = Bootstrapper.GetKernel().Resolve <ICommunicationService>(); var _departmentsService = Bootstrapper.GetKernel().Resolve <IDepartmentsService>(); var _userProfileService = Bootstrapper.GetKernel().Resolve <IUserProfileService>(); var _departmentSettingsService = Bootstrapper.GetKernel().Resolve <IDepartmentSettingsService>(); var item = new ProcessedNotification(); if (ni.DepartmentId != 0) { item.DepartmentId = ni.DepartmentId; } else { item.DepartmentId = _notificationService.GetDepartmentIdForType(ni); } item.Type = (EventTypes)ni.Type; item.Value = ni.Value; item.MessageId = messageId; item.Data = body; item.ItemId = ni.ItemId; var queueItem = new NotificationQueueItem(); queueItem.Department = _departmentsService.GetDepartmentById(item.DepartmentId, false); queueItem.DepartmentTextNumber = _departmentSettingsService.GetTextToCallNumberForDepartment(item.DepartmentId); queueItem.NotificationSettings = _notificationService.GetNotificationsByDepartment(item.DepartmentId); queueItem.Profiles = _userProfileService.GetAllProfilesForDepartment(item.DepartmentId); queueItem.Notifications = new List <ProcessedNotification>(); queueItem.Notifications.Add(item); var notificaitons = _notificationService.ProcessNotifications(queueItem.Notifications, queueItem.NotificationSettings); if (notificaitons != null) { foreach (var notification in notificaitons) { var text = _notificationService.GetMessageForType(notification); if (!String.IsNullOrWhiteSpace(text)) { foreach (var user in notification.Users) { if (queueItem.Profiles.ContainsKey(user)) { _communicationService.SendNotification(user, notification.DepartmentId, text, queueItem.DepartmentTextNumber, "Notification", queueItem.Profiles[user]); } //else // _communicationService.SendNotification(user, notification.DepartmentId, text, queueItem.DepartmentTextNumber); } } } } _notificationService = null; _communicationService = null; _departmentsService = null; _userProfileService = null; _departmentSettingsService = null; } }
public async Task Insert(NotificationQueueItem item) { CloudQueueMessage message = new CloudQueueMessage(JsonConvert.SerializeObject(item)); await queue.AddMessageAsync(message); }
public static async Task <bool> ProcessNotificationItem(NotificationItem ni, string messageId, string body) { if (ni != null) { var _notificationService = Bootstrapper.GetKernel().Resolve <INotificationService>(); var _communicationService = Bootstrapper.GetKernel().Resolve <ICommunicationService>(); var _departmentsService = Bootstrapper.GetKernel().Resolve <IDepartmentsService>(); var _userProfileService = Bootstrapper.GetKernel().Resolve <IUserProfileService>(); var _departmentSettingsService = Bootstrapper.GetKernel().Resolve <IDepartmentSettingsService>(); var item = new ProcessedNotification(); if (ni.DepartmentId != 0) { item.DepartmentId = ni.DepartmentId; } else { item.DepartmentId = await _notificationService.GetDepartmentIdForTypeAsync(ni); } item.Type = (EventTypes)ni.Type; item.Value = ni.Value; item.MessageId = messageId; if (!String.IsNullOrWhiteSpace(body)) { item.Data = body; } else { item.Data = ObjectSerialization.Serialize(ni); } item.ItemId = ni.ItemId; var queueItem = new NotificationQueueItem(); queueItem.Department = await _departmentsService.GetDepartmentByIdAsync(item.DepartmentId, false); queueItem.DepartmentTextNumber = await _departmentSettingsService.GetTextToCallNumberForDepartmentAsync(item.DepartmentId); queueItem.NotificationSettings = await _notificationService.GetNotificationsByDepartmentAsync(item.DepartmentId); queueItem.Profiles = await _userProfileService.GetAllProfilesForDepartmentAsync(item.DepartmentId); queueItem.Notifications = new List <ProcessedNotification>(); queueItem.Notifications.Add(item); var notificaitons = await _notificationService.ProcessNotificationsAsync(queueItem.Notifications, queueItem.NotificationSettings); if (notificaitons != null) { foreach (var notification in notificaitons) { var text = await _notificationService.GetMessageForTypeAsync(notification); if (!String.IsNullOrWhiteSpace(text)) { foreach (var user in notification.Users) { if (queueItem.Profiles.ContainsKey(user)) { var profile = queueItem.Profiles[user]; if (!_notificationService.AllowToSendViaSms(notification.Type)) { profile.SendNotificationSms = false; } await _communicationService.SendNotificationAsync(user, notification.DepartmentId, text, queueItem.DepartmentTextNumber, "Notification", profile); } } } } } _notificationService = null; _communicationService = null; _departmentsService = null; _userProfileService = null; _departmentSettingsService = null; } return(true); }