Пример #1
0
        public void SendReadyRemiders()
        {
            var reminders = storage.Get(ReminderStatus.ReadyToSend, 0, 0).Where(r => r.IsTimeToAlarm).ToList();

            foreach (ReminderItem r_item in reminders)
            {
                SendReminderItemModel sendModel = new SendReminderItemModel()
                {
                    Id        = r_item.Id,
                    ContactId = r_item.ContactId,
                    Message   = r_item.Message
                };

                try
                {
                    SendReminder?.Invoke(sendModel);
                    storage.UpdateStatus(sendModel.Id, ReminderStatus.Sended);
                    OnSuccesSend?.Invoke(this, new SendSuccesEventArgs(r_item));
                }
                catch (Exception e)
                {
                    storage.UpdateStatus(sendModel.Id, ReminderStatus.Failed);
                    OnFailedSend?.Invoke(this, new SendFailedEventArgs(e, r_item));
                }
            }
        }
Пример #2
0
        public async Task SendReadyRemiders()
        {
            var reminders = storage.Get(ReminderStatus.ReadyToSend, 0, 0).Where(r => r.IStimeToAlarm).ToList();

            foreach (ReminderItem r_item in reminders)
            {
                SendReminderItemModel sendModel = new SendReminderItemModel()
                {
                    id        = r_item.Id,
                    contactId = r_item.contactId,
                    Message   = r_item.Message
                };

                try
                {
                    storage.UpdateStatus(sendModel.id, ReminderStatus.Sended);
                    await sender.Send(sendModel.contactId, sendModel.Message);

                    OnSuccesSend?.Invoke(this, new SendSuccesEventArgs(r_item));
                }
                catch (Exception e)
                {
                    storage.UpdateStatus(sendModel.id, ReminderStatus.Failed);
                    OnFailedSend?.Invoke(this, new SendFailedEventArgs(e, r_item));
                }
            }
        }