public async Task SchedulePendingNotifications() { try { _logger.Information($"Getting tasks with a reminder date..."); var taskResponse = await _dataService.TaskService .GetAsNoTrackingAsync( t => t.RemindOnGUID != null && t.RemindOn.HasValue, includeProperties : nameof(GoogleTask.TaskList)); if (!taskResponse.Succeed) { _logger.Warning( $"Could not get all the task with a reminder date. " + $"Error = {taskResponse.Message}"); return; } var tasks = taskResponse.Result; _logger.Information($"Scheduling notifications for {tasks.Count()} task(s)"); foreach (var task in tasks) { string notes = TasksHelper.GetNotesForNotification(task.Notes); int id = int.Parse(task.RemindOnGUID); _notificationService.ScheduleNotification(new TaskReminderNotification { Id = id, TaskListId = task.TaskList.ID, TaskId = task.ID, TaskListTitle = task.TaskList.Title, TaskTitle = task.Title, TaskBody = notes, DeliveryOn = task.RemindOn.Value }); } _logger.Information($"Process completed"); } catch (Exception e) { _logger?.Error(e, $"An unknown error occurred while trying " + $"to schedule pending notifications"); _telemetryService?.TrackError(e); } }
private void ReAddReminderDate( int notificationId, TaskListItemViewModel taskList, GoogleTask task) { if (!TasksHelper.CanReAddReminder(task.RemindOn.Value)) { return; } string notes = TasksHelper.GetNotesForNotification(task.Notes); _notificationService.RemoveScheduledNotification(notificationId); _notificationService.ScheduleNotification(new TaskReminderNotification { Id = notificationId, TaskListId = taskList.Id, TaskId = task.ID, TaskListTitle = taskList.Title, TaskTitle = task.Title, TaskBody = notes, DeliveryOn = task.RemindOn.Value }); }