public async Task DistributeAsync(Guid notificationId) { var notificationInfo = await _notificationStore.GetNotificationOrNullAsync(notificationId); if (notificationInfo == null) { Logger.Warn("NotificationDistributionJob can not continue since could not found notification by id: " + notificationId); return; } var users = await GetUsers(notificationInfo); var userNotifications = await SaveUserNotifications(users, notificationInfo); await _notificationStore.DeleteNotificationAsync(notificationInfo); try { await RealTimeNotifier.SendNotificationsAsync(userNotifications.ToArray()); } catch (Exception ex) { Logger.Warn(ex.ToString(), ex); } }
private async Task ExecuteAsync(NotificationDistributionJobArgs args) { var notification = await _notificationStore.GetNotificationOrNullAsync(args.NotificationId); if (notification == null) { Logger.Warn("NotificationDistributionJob can not continue since could not found notification by id: " + args.NotificationId); return; } long[] userIds; if (notification.UserIds.IsNullOrEmpty()) { userIds = await _notificationStore.GetSubscribedUserIdsAsync(notification); } else { userIds = notification.UserIds.Split(",").Select(uidAsStr => Convert.ToInt64(uidAsStr)).ToArray(); } var userNotifications = userIds.Select(userId => new UserNotificationInfo(userId, notification.Id)).ToList(); await SaveUserNotifications(userNotifications); await _realTimeNotifier.SendNotificationAsync(notification, userNotifications); }
public async Task DistributeAsync(Guid notificationId) { var notificationInfo = await _notificationStore.GetNotificationOrNullAsync(notificationId); if (notificationInfo == null) { Logger.Warn("NotificationDistributionJob can not continue since could not found notification by id: " + notificationId); return; } var users = await GetUsersAsync(notificationInfo); if (users.Any()) { var userNotifications = await SaveUserNotificationsAsync(users, notificationInfo); await _notificationStore.DeleteNotificationAsync(notificationInfo); await NotifyAsync(userNotifications.ToArray()); } else { // handle Shesha messages without recipients // todo: combine with subscriptions var notificationMessages = await SaveUserNotificationMessagesAsync(notificationInfo); await NotifyAsync(notificationMessages); } }
private async Task ExecuteAsync(NotificationDistributionJobArgs args) { var notificationInfo = await _notificationStore.GetNotificationOrNullAsync(args.NotificationId); if (notificationInfo == null) { Logger.Warn("NotificationDistributionJob can not continue since could not found notification by id: " + args.NotificationId); return; } Notification notification; try { notification = notificationInfo.ToNotification(); } catch (Exception) { Logger.Warn("NotificationDistributionJob can not continue since could not convert NotificationInfo to Notification for NotificationId: " + args.NotificationId); return; } long[] userIds; if (notificationInfo.UserIds.IsNullOrEmpty()) { userIds = (await _notificationStore.GetSubscriptionsAsync( notificationInfo.NotificationName, notificationInfo.EntityTypeName, notificationInfo.EntityId )) .Select(s => s.UserId) .ToArray(); } else { userIds = notificationInfo.UserIds.Split(",").Select(uidAsStr => Convert.ToInt64(uidAsStr)).ToArray(); } var userNotificationInfos = userIds.Select(userId => new UserNotificationInfo(userId, notificationInfo.Id)).ToList(); await SaveUserNotifications(userNotificationInfos); try { var userNotifications = userNotificationInfos.Select(uni => uni.ToUserNotification(notification)).ToArray(); await RealTimeNotifier.SendNotificationsAsync(userNotifications); } catch (Exception ex) { Logger.Warn(ex.ToString(), ex); } }
public async Task DistributeAsync(Guid notificationId) { var notificationInfo = await _notificationStore.GetNotificationOrNullAsync(notificationId); if (notificationInfo == null) { Logger.Warn("NotificationDistributionJob can not continue since could not found notification by id: " + notificationId); return; } var users = await GetUsersAsync(notificationInfo); var userNotifications = await SaveUserNotificationsAsync(users, notificationInfo); await _notificationStore.DeleteNotificationAsync(notificationInfo); await NotifyAsync(userNotifications.ToArray()); }
public async Task DistributeAsync(Guid notificationId) { var notificationInfo = await _notificationStore.GetNotificationOrNullAsync(notificationId); if (notificationInfo == null) { Logger.Warn("NotificationDistributionJob can not continue since could not found notification by id: " + notificationId); return; } Notification notification; try { notification = notificationInfo.ToNotification(); } catch (Exception) { Logger.Warn("NotificationDistributionJob can not continue since could not convert NotificationInfo to Notification for NotificationId: " + notificationId); return; } var userIds = await GetUserIds(notificationInfo); var userNotificationInfos = userIds .Select(userId => new UserNotificationInfo(userId, notificationInfo.Id)) .ToList(); await SaveUserNotifications(userNotificationInfos); try { var userNotifications = userNotificationInfos .Select(uni => uni.ToUserNotification(notification)) .ToArray(); await RealTimeNotifier.SendNotificationsAsync(userNotifications); } catch (Exception ex) { Logger.Warn(ex.ToString(), ex); } }
public async Task ProcessAsync(UserNotificationInfo userNotificationsInfo) { if (userNotificationsInfo == null) { return; } var notification = await _notificationStore.GetNotificationOrNullAsync(userNotificationsInfo.NotificationId); if (notification == null) { return; } var firebaseNotificationData = FirebaseNotificationData.FromJsonString(notification.Data); firebaseNotificationData.Notification.Badge = (await _notificationStore.GetUserNotificationCountAsync(userNotificationsInfo.UserId, UserNotificationState.Unread)).ToString(); var firebaseRegistrations = await _firebaseService.GetAllRegistrationAsync(userNotificationsInfo.UserId); if (firebaseRegistrations.IsNullOrEmpty()) { return; } firebaseNotificationData.RegistrationIds.AddRange(firebaseRegistrations.Select(x => x.RegistrationId)); var json = firebaseNotificationData.ToString(); var content = new StringContent(json, System.Text.Encoding.UTF8, "application/json"); var response = await _httpClient.PostAsync(_configuration.Url, content); if (response.IsSuccessStatusCode) { await ProcessResponseOk(response, firebaseNotificationData); } else { await ProcessReponseError(response, firebaseNotificationData); } }
public async Task DistributeAsync(Guid notificationId) { await _unitOfWorkManager.PerformAsyncUow(async() => { var notification = await _notificationStore.GetNotificationOrNullAsync(notificationId); if (notification == null) { _logger.LogWarning( "NotificationDistributerJob cannot continue since could not found notification by id: " + notificationId); return; } var users = await GetUsers(notification); var userNotifications = await SaveUserNotifications(users, notification); // await _notificationStore.DeleteNotificationAsync(notification); try { var notificationType = Type.GetType(notification.NotificationDataTypeAssemblyQualifiedName); foreach (var notificationChannel in _notificationChannels) { if (!notificationChannel.CanHandle(notificationType)) { continue; } foreach (var userNotificationInfo in userNotifications) { await notificationChannel.ProcessAsync(userNotificationInfo); } } } catch (Exception e) { _logger.LogWarning(e.ToString(), e); } }); }