示例#1
0
        public async Task <DateTime?> GetLastDeliveryTimestampAsync(NotificationTransport notificationTransport)
        {
            var lastNotification = await db.NotificationDeliveries.Where(d => d.NotificationTransportId == notificationTransport.Id)
                                   .OrderByDescending(d => d.CreateTime)
                                   .FirstOrDefaultAsync();

            return(lastNotification?.CreateTime);
        }
示例#2
0
        public DateTime?GetLastDeliveryTimestamp(NotificationTransport notificationTransport)
        {
            var lastNotification = db.NotificationDeliveries.Where(d => d.NotificationTransportId == notificationTransport.Id)
                                   .OrderByDescending(d => d.CreateTime)
                                   .FirstOrDefault();

            return(lastNotification?.CreateTime);
        }
示例#3
0
        public async Task AddNotificationTransport(NotificationTransport transport)
        {
            DeleteOldNotificationTransports(transport.GetType(), transport.UserId);

            transport.IsDeleted = false;
            db.NotificationTransports.Add(transport);

            await db.SaveChangesAsync();
        }
示例#4
0
        public async Task AddNotificationTransport(NotificationTransport transport)
        {
            using (var transaction = db.Database.BeginTransaction())
            {
                await DeleteOldNotificationTransports(transport.GetType(), transport.UserId);

                transport.IsDeleted = false;
                db.NotificationTransports.Add(transport);

                await db.SaveChangesAsync();

                await transaction.CommitAsync();
            }
        }
示例#5
0
        public async Task SendDeliveriesOfOneType(NotificationTransport transport, NotificationType notificationType, List <NotificationDelivery> deliveries)
        {
            if (deliveries.Count == 0)
            {
                return;
            }

            if (deliveries.Count == 1)
            {
                var delivery = deliveries[0];
                var course   = courseManager.FindCourse(delivery.Notification.CourseId);
                if (course == null)
                {
                    log.Warn($"Can't find course {delivery.Notification.CourseId}");
                    await notificationsRepo.MarkDeliveryAsFailed(delivery);

                    return;
                }

                try
                {
                    await notificationSender.SendAsync(delivery);

                    await notificationsRepo.MarkDeliveryAsSent(delivery.Id);
                }
                catch (Exception e)
                {
                    log.Warn($"Can\'t send notification {delivery.NotificationId} to {delivery.NotificationTransport}: {e}. Will try later");
                    await notificationsRepo.MarkDeliveryAsFailed(delivery);
                }
            }
            else
            {
                try
                {
                    await notificationSender.SendAsync(deliveries);

                    await notificationsRepo.MarkDeliveriesAsSent(deliveries.Select(d => d.Id).ToList());
                }
                catch (Exception e)
                {
                    log.Warn($"Can\'t send multiple notifications [{string.Join(", ", deliveries.Select(d => d.NotificationId))}] to {deliveries[0].NotificationTransport}: {e}. Will try later");
                    await notificationsRepo.MarkDeliveriesAsFailed(deliveries);
                }
            }
        }
示例#6
0
        public async Task AddNotificationTransport(NotificationTransport transport)
        {
            using (var transaction = db.Database.BeginTransaction())
            {
                DeleteOldNotificationTransports(transport.GetType(), transport.UserId);

                /*
                 * if (transport is MailNotificationTransport)
                 *      DeleteOldNotificationTransports<MailNotificationTransport>(transport.UserId);
                 * if (transport is TelegramNotificationTransport)
                 *      DeleteOldNotificationTransports<TelegramNotificationTransport>(transport.UserId);
                 */

                transport.IsDeleted = false;
                db.NotificationTransports.Add(transport);

                await db.SaveChangesAsync().ConfigureAwait(false);

                transaction.Commit();
            }
        }
示例#7
0
 public IQueryable <NotificationDelivery> GetTransportDeliveries(NotificationTransport notificationTransport, DateTime from)
 {
     return(db.NotificationDeliveries.Where(d => d.NotificationTransportId == notificationTransport.Id && d.CreateTime > from));
 }