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 }
private void CheckReadyReminders(object state) { var readyToSendItems = _storage.GetList(ReminderItemStatus.Awaiting); foreach (var reminderItem in readyToSendItems) { try { _sender.Send(reminderItem.ContactId, reminderItem.Message); reminderItem.Status = ReminderItemStatus.SuccessfullySent; OnSendingSucceeded( this, new ActionSucceededEventArgs(reminderItem)); // Raise event SendingSucceeded; } catch (Exception exception) { reminderItem.Status = ReminderItemStatus.Failed; OnSendingFailed( this, new SendingFailedEventArgs(reminderItem, exception)); // Raise event SendingFailed; } _storage.Update(reminderItem);; } }
private void CheckAwaitingReminders(object _) //Подчеркивание "_" = не используем! { var readyItems = _storage.GetList(new[] { ReminderItemStatus.Awaiting }).Where(i => i.IsTimeToSend); foreach (var readyItem in readyItems) { readyItem.Status = ReminderItemStatus.ReadyToSend; _storage.Update(readyItem); } }
private void OnCreatedTimerTick(object _) { var filter = new ReminderItemFilter(DateTimeOffset.UtcNow, ReminderItemStatus.Created); var items = _storage.FindBy(filter); foreach (var item in items) { _storage.Update(item.ReadyToSend()); } }
private void OnCreatedItemTimerTick(object _) { var filter = ReminderItemFilter .ByStatus(ReminderItemStatus.Created) .At(DateTimeOffset.Now); var items = _storage.FindBy(filter); foreach (var item in items) { _storage.Update(item.ReadyToSend()); } }
private void CheckAwaitingReminders(object _) { var readyItems = _storage.GetList( new[] { ReminderItemStatus.Awaiting }) .Where(i => i.IsTimeToSend); foreach (var readyItem in readyItems) { readyItem.Status = ReminderItemStatus.ReadyToSent; _storage.Update(readyItem); } }
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); } } }
private void CheckAwaitingReminders(object dummy) { List <ReminderItem> awaitingItems = _storage.GetList(ReminderItemStatus.Awaiting); foreach (ReminderItem reminderItem in awaitingItems) { if (reminderItem.IsTimeToSend) { reminderItem.Status = ReminderItemStatus.ReadyToSend; _storage.Update(reminderItem); } } }
public IActionResult Update(Guid id, [FromBody] UpdateReminderItemViewModel model) { if (id == default || model == default) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var existsItem = _storage.FindById(id); if (existsItem == default) { return(NotFound()); } var item = new ReminderItem( id, model.ContactId, model.Message, model.DateTimeUtc, model.Status); _storage.Update(item); return(Ok()); }
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 }); } } }
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 }); } } }
public IActionResult Update(Guid id, [FromBody] UpdateReminderItemViewModel model) { var existsItem = _storage.FindById(id); var item = new ReminderItem( id, existsItem.ContactId, model.Message, DateTimeOffset.FromUnixTimeMilliseconds(model.DateTimeUtc), model.Status); _storage.Update(item); return(Ok()); }
private void OnCreatedItemTimerTick(object state) { var filter = new ReminderItemFilter() .At(DateTimeOffset.Now) .Created(); var items = _storage.FindBy(filter); foreach (var item in items) { _storage.Update(item.ReadyToSend()); } }
private void CheckAwatingReminders(object _) //not used { // List<ReminderItemStatus> statuses = new List<ReminderItemStatus>() // { // var items = _storage.GetList(statuses); // }; var readyItems = _storage.GetList(new[] { ReminderItemStatus.Awaiting }); //list.where i :=> i.IsTimeToSend; foreach (var readyItem in readyItems) { readyItem.Status = ReminderItemStatus.ReadyToSend; _storage.Update(readyItem); } }
public IActionResult Update(Guid id, [FromBody] ReminderItemUpdateModel model) { ReminderItem reminderItem = _reminderStorage.Get(id); if (reminderItem == null) { return(NotFound()); } if (model == null && !ModelState.IsValid) { return(BadRequest(ModelState)); } _reminderStorage.Update(id, model.Status); return(NoContent()); }
public IActionResult Update(Guid id, [FromBody] ReminderItemAddModel reminderItemAddModel) { ReminderItem reminderItem = _storage.Get(id); if (reminderItem == null) { return(NotFound()); } reminderItem.ContactId = reminderItemAddModel.ContactId; reminderItem.Date = reminderItemAddModel.Date; reminderItem.Message = reminderItemAddModel.Message; reminderItem.Status = reminderItemAddModel.Status; _storage.Update(reminderItem); return(Ok()); }
public IActionResult Update(Guid id, [FromBody] ReminderItemUpdateModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } ReminderItem reminderItem = _storage.Get(id); if (reminderItem == null) { return(NotFound()); } model.UpdateRemiderItem(reminderItem); _storage.Update(reminderItem); return(NoContent()); }
public IActionResult Update(Guid id, [FromBody] ReminderItemUpdateModel model) { _logger.LogInformation($"{nameof(Update)} called"); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var reminderItem = _storage.Get(id); if (reminderItem == null) { return(NotFound()); } model.UpdateReminderItem(reminderItem); _storage.Update(reminderItem); return(NoContent()); }