Пример #1
0
        private void SendReadyReminders(object state)
        {
            //ищем записи
            var readyReminders = _storage.Get(ReminderItemStatus.Ready);

            foreach (var readyReminder in readyReminders)
            {
                try
                {
                    SendReminder(readyReminder);
                    _storage.Update(readyReminder.Id, ReminderItemStatus.Sent);
                    SendingSucceeded?.Invoke(this, new SendingSucceeededEventArgs
                    {
                        SendingItem = readyReminder
                    });
                }
                catch (Exception e)
                {
                    _storage.Update(readyReminder.Id, ReminderItemStatus.Failed);

                    SendingFailed?.Invoke(
                        this,
                        new SendingFailedEventArgs
                    {
                        SendingItem      = readyReminder,
                        SendingException = e
                    });
                }
            }

            //отправляем

            //Если ок  то в статус send, иначе failed
        }
Пример #2
0
        public void CheckAwaitingReminders(object dummy)
        {
            var ids = _storage
                      .Get(ReminderItemStatus.Awaiting)
                      .Where(r => r.IsTimeToSend)
                      .Select(r => r.Id);

            _storage.UpdateStatus(ids, ReminderItemStatus.Ready);
        }
        public IActionResult Get(Guid id)
        {
            ReminderItem reminderItem = _storage.Get(id);

            if (reminderItem == null)
            {
                return(NotFound());
            }

            return(Ok(new ReminderItemGetModel(reminderItem)));
        }
Пример #4
0
        private void CheckAwaitingReminders(object state)
        {
            var awaitingReminders = _storage.Get(ReminderItemStatus.Awaiting);

            foreach (var awaitingReminder in awaitingReminders)
            {
                if (awaitingReminder.IsReadyToSend)
                {
                    _storage.Update(awaitingReminder.Id, ReminderItemStatus.Ready);
                }
            }
        }
        public IActionResult Get(Guid id)
        {
            var reminderItem = _reminderStorage.Get(id);

            if (reminderItem == null)
            {
                return(BadRequest(ModelState));
            }


            return(Ok(new ReminderItemGetModel(reminderItem)));
        }
        public IActionResult Get(Guid id)
        {
            _logger.LogInformation($"{nameof(Get)} called");
            var reminderItem = _storage.Get(id);

            if (reminderItem == null)
            {
                return(NotFound());
            }

            var model = new ReminderItemGetModel(reminderItem);

            return(Ok(model));
        }
Пример #7
0
        private void CheckAwaitingReminders(object dummy)
        {
            var ids = _storage
                      .Get(ReminderItemStatus.Awaiting)
                      .Where(r => r.IsTimeToSend)
                      .Select(r => r.Id)
                      .ToList();

            if (ids.Count > 0)
            {
                _storage.UpdateStatus(
                    ids,
                    ReminderItemStatus.Ready);
            }
        }
Пример #8
0
        private void SendReadyReminders(object state)
        {
            // find ready reminders
            // try "send"
            // if success update status to Sent
            // else update status to Failed

            var readyReminders = _storage.Get(ReminderItemStatus.Ready);

            foreach (var readyReminder in readyReminders)
            {
                try
                {
                    // try "send"
                    SendReminder(readyReminder);

                    // update status to Sent
                    _storage.Update(
                        readyReminder.Id,
                        ReminderItemStatus.Sent);

                    // send event
                    SendingSucceeded?.Invoke(
                        this,
                        new SendingSucceededEventArgs
                    {
                        SendingItem = readyReminder
                    });
                }
                catch (Exception e)
                {
                    // update status to Failed
                    _storage.Update(
                        readyReminder.Id,
                        ReminderItemStatus.Failed);

                    // send event
                    SendingFailed?.Invoke(
                        this,
                        new SendingFailedEventArgs
                    {
                        SendingItem      = readyReminder,
                        SendingException = e
                    });
                }
            }
        }
Пример #9
0
        private void SendReadyReminders(object state)
        {
            //отправка
            //находим что отправлять
            //отправляем
            //если ок  то статус в set
            //инача статус в failed

            var readyReminders = _storage.Get(ReminderItemStatus.Ready);

            foreach (var readyReminder in readyReminders)
            {
                try
                {
                    //отправляем, используем делегат
                    SendReminder(readyReminder);
                    //статус в sent
                    _storage.Update(
                        readyReminder.Id,
                        ReminderItemStatus.Sent);

                    //запускаем событие об успешной отправке
                    SendingSuccedded?.Invoke(
                        this,
                        new SendingSucceededEventArgs
                    {
                        SendingItem = readyReminder
                    });
                }
                catch (Exception e)
                {
                    //статус в fault
                    _storage.Update(
                        readyReminder.Id,
                        ReminderItemStatus.Failed);

                    //запускаем событие о сбое отправки
                    SendingFailed?.Invoke(
                        this,
                        new SendingFailedEventArgs
                    {
                        SendingItem      = readyReminder,
                        SendingException = e
                    });
                }
            }
        }
Пример #10
0
        public IActionResult Get(Guid id)
        {
            //if (id == default(Guid))
            //{
            //    ModelState.AddModelError("id", "ID должен быть GUID");
            //    return BadRequest(ModelState);
            //}

            ReminderItem reminderItem = _reminderStorage.Get(id);

            if (reminderItem == null)
            {
                return(NotFound());
            }

            return(Ok(new ReminderItemGetModel(reminderItem)));
        }
Пример #11
0
        public void CheckAwaitingReminders()
        {
            var ids = storage.Get(ReminderStatus.Awaiting, 0, 0).Where(r => r.IsTimeToAlarm).Select(r => r.Id);

            storage.UpdateStatus(ids, ReminderStatus.ReadyToSend);
        }