예제 #1
0
            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
            });
        }
예제 #3
0
        private async Task MoveCurrentTaskAsync()
        {
            ShowTaskProgressRing = true;

            var moveResponse = await _dataService
                               .TaskService
                               .MoveAsync(SelectedTaskList.TaskListID, CurrentTask.TaskID, null, null);

            if (!moveResponse.Succeed)
            {
                ShowTaskProgressRing = false;
                await _dialogService.ShowMessageDialogAsync(
                    $"An error occurred while trying to move the selected task from {_currentTaskList.Title} to {SelectedTaskList.Title}",
                    $"Error: {moveResponse.Message}.");

                return;
            }

            var movedTask = moveResponse.Result;

            if (movedTask != null &&
                TasksHelper.HasReminderId(movedTask.RemindOnGUID, out int id) &&
                TasksHelper.CanReAddReminder(movedTask.RemindOn.Value))
            {
                string notes = TasksHelper.GetNotesForNotification(movedTask.Notes);

                _notificationService.RemoveScheduledNotification(id);
                _notificationService.ScheduleNotification(new TaskReminderNotification
                {
                    Id            = id,
                    TaskListId    = SelectedTaskList.Id,
                    TaskId        = movedTask.ID,
                    TaskListTitle = SelectedTaskList.Title,
                    TaskTitle     = movedTask.Title,
                    TaskBody      = notes,
                    DeliveryOn    = movedTask.RemindOn.Value
                });
            }


            if (!CurrentTask.HasParentTask)
            {
                _messenger.Send(CurrentTask.TaskID, $"{MessageType.TASK_DELETED_FROM_PANE_FRAME}");
            }
            else
            {
                _messenger.Send(
                    new KeyValuePair <string, string>(CurrentTask.ParentTask, CurrentTask.TaskID),
                    $"{MessageType.SUBTASK_DELETED_FROM_PANE_FRAME}");
            }


            var subTasks = GetSubTasksToSave(false, true);

            subTasks.ForEach(st => st.ParentTask = moveResponse.Result.GoogleTaskID);

            ShowTaskProgressRing = false;

            await SaveSubTasksAsync(subTasks, false, true, Enumerable.Empty <TaskItemViewModel>().ToList());

            _changedProperties.Clear();

            _messenger.Send(false, $"{MessageType.OPEN_PANE}");

            _messenger.Send(
                $"Task sucessfully moved from: {_currentTaskList.Title} to: {SelectedTaskList.Title}",
                $"{MessageType.SHOW_IN_APP_NOTIFICATION}");
        }