Example #1
0
        private async Task <int> ChangeTaskStatus(string taskId, string reason, string newStatus)
        {
            if (string.IsNullOrEmpty(taskId))
            {
                mLogger.LogError("No task id given");
                return(1);
            }

            WorkTaskResource workTaskResource = new WorkTaskResource
            {
                TaskId = taskId,
                Status = newStatus,
                Reason = reason
            };

            Uri taskUri = TaskerUris.WorkTasksUri.CombineRelative(taskId);

            using HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, taskUri)
                  {
                      Content = new StringContent(JsonConvert.SerializeObject(workTaskResource), Encoding.UTF8, PostMediaType)
                  };

            WorkTaskResource workTaskResourceResponse = await HttpMessageRequester.SendHttpRequestMessage <WorkTaskResource>(
                mHttpClient, httpRequestMessage, mLogger).ConfigureAwait(false);

            if (workTaskResourceResponse != null)
            {
                mLogger.LogInformation($"Changed status of task {workTaskResourceResponse.TaskId} " +
                                       $"{workTaskResourceResponse.Description} to {newStatus}");
            }

            return(0);
        }
Example #2
0
        private async Task <IEnumerable <WorkTaskResource> > GetAllTasks()
        {
            using HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, TaskerUris.WorkTasksUri);

            return(await HttpMessageRequester.SendHttpRequestMessage <IEnumerable <WorkTaskResource> >(
                       mHttpClient, httpRequestMessage, mLogger).ConfigureAwait(false));
        }
Example #3
0
        private async Task <int> CreateNewTask(string taskGroupName, string description)
        {
            if (string.IsNullOrWhiteSpace(description))
            {
                mLogger.LogError($"{nameof(description)} is null or empty");
                return(1);
            }

            WorkTaskResource workTaskResource = new WorkTaskResource
            {
                GroupName   = taskGroupName,
                Description = description
            };

            using HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Put, TaskerUris.WorkTasksUri)
                  {
                      Content = new StringContent(JsonConvert.SerializeObject(workTaskResource), Encoding.UTF8, PostMediaType)
                  };

            WorkTaskResource workTaskResponse = await HttpMessageRequester.SendHttpRequestMessage <WorkTaskResource>(
                mHttpClient, httpRequestMessage, mLogger).ConfigureAwait(false);

            if (workTaskResponse != null)
            {
                mLogger.LogInformation($"Created new task id {workTaskResponse.TaskId} '{workTaskResponse.Description}' at group {workTaskResponse.GroupName}");
            }

            return(0);
        }
Example #4
0
        private async Task <int> CreateNote(string noteId, string textToWrite)
        {
            if (string.IsNullOrWhiteSpace(noteId))
            {
                mLogger.LogError("No task id given to create note");
                return(1);
            }

            if (textToWrite == null)
            {
                textToWrite = string.Empty;
            }

            NoteResource noteResource = new NoteResource
            {
                NotePath      = noteId,
                Text          = textToWrite,
                PossibleNotes = null
            };

            using HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Put, TaskerUris.NotesUri)
                  {
                      Content = new StringContent(JsonConvert.SerializeObject(noteResource), Encoding.UTF8, PostMediaType)
                  };

            NoteResource noteResourceResponse = await HttpMessageRequester.SendHttpRequestMessage <NoteResource>(
                mHttpClient, httpRequestMessage, mLogger).ConfigureAwait(false);

            if (noteResourceResponse != null)
            {
                mLogger.LogInformation($"Created new note {noteResourceResponse.NotePath}");
            }

            return(0);
        }
Example #5
0
        private async Task <int> CreateNewTaskGroup(string taskGroupName)
        {
            if (string.IsNullOrWhiteSpace(taskGroupName))
            {
                mLogger.LogError($"{nameof(taskGroupName)} is null or empty");
                return(1);
            }

            TasksGroupResource tasksGroupResource = new TasksGroupResource
            {
                GroupName = taskGroupName
            };

            using HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Put, TaskerUris.TasksGroupUri)
                  {
                      Content = new StringContent(JsonConvert.SerializeObject(tasksGroupResource), Encoding.UTF8, PostMediaType)
                  };

            TasksGroupResource tasksGroupResponse = await HttpMessageRequester.SendHttpRequestMessage <TasksGroupResource>(
                mHttpClient, httpRequestMessage, mLogger).ConfigureAwait(false);

            if (tasksGroupResponse != null)
            {
                mLogger.LogInformation($"Created new group id {tasksGroupResponse.GroupId} '{tasksGroupResponse.GroupName}'");
            }

            return(0);
        }
Example #6
0
        private async Task <NoteNodeResource> GetAllNotesNames()
        {
            Uri privateNotesUri = TaskerUris.NotesUri.CombineRelative("private");

            using HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, privateNotesUri);

            return(await HttpMessageRequester.SendHttpRequestMessage <NoteNodeResource>(
                       mHttpClient, httpRequestMessage, mLogger).ConfigureAwait(false));
        }
Example #7
0
        public static async Task <NoteResource> GetNoteResource(HttpClient httpClient, string noteName, bool isPrivateNote, ILogger logger)
        {
            string escapedNoteName = Uri.EscapeDataString(noteName);

            string relativeNoteUri = isPrivateNote ? $"note/{escapedNoteName}" : escapedNoteName;

            Uri noteUri = TaskerUris.NotesUri.CombineRelative(relativeNoteUri);

            using HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, noteUri);

            return(await HttpMessageRequester.SendHttpRequestMessage <NoteResource>(
                       httpClient, httpRequestMessage, logger).ConfigureAwait(false));
        }
Example #8
0
        private async Task <IEnumerable <WorkTaskResource> > GetTasksByGroup(string taskGroup)
        {
            if (string.IsNullOrEmpty(taskGroup))
            {
                throw new ArgumentException($"{nameof(taskGroup)} is null or empty");
            }

            Uri tasksByGroupUri = TaskerUris.WorkTasksUri.CombineRelative(taskGroup);

            using HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, tasksByGroupUri);

            return(await HttpMessageRequester.SendHttpRequestMessage <IEnumerable <WorkTaskResource> >(
                       mHttpClient, httpRequestMessage, mLogger).ConfigureAwait(false));
        }
Example #9
0
        private async Task <int> GatAllTaskGroup(bool shouldPrintAll, bool isDetailed)
        {
            using HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, TaskerUris.TasksGroupUri);

            IEnumerable <TasksGroupResource> groupsToPrint =
                await HttpMessageRequester.SendHttpRequestMessage <IEnumerable <TasksGroupResource> >(
                    mHttpClient, httpRequestMessage, mLogger).ConfigureAwait(false);

            if (!shouldPrintAll)
            {
                groupsToPrint = groupsToPrint
                                .Where((TasksGroupResource group) => !group.Status.Equals(TaskerConsts.ClosedTaskStatus, StringComparison.InvariantCultureIgnoreCase));
            }

            mConsolePrinter.PrintTasksGroup(groupsToPrint, isDetailed);
            return(0);
        }
Example #10
0
        private async Task <int> RemoveTaskGroup(string taskGroup)
        {
            if (string.IsNullOrEmpty(taskGroup))
            {
                mLogger.LogError("No group name or group id given");
                return(1);
            }

            Uri groupUri = TaskerUris.TasksGroupUri.CombineRelative(taskGroup);

            using HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Delete, groupUri);

            TasksGroupResource tasksGroupResource = await HttpMessageRequester.SendHttpRequestMessage <TasksGroupResource>(
                mHttpClient, httpRequestMessage, mLogger).ConfigureAwait(false);

            if (tasksGroupResource != null)
            {
                mLogger.LogInformation($"Deleted group id {tasksGroupResource.GroupId} {tasksGroupResource.GroupName}");
            }

            return(0);
        }
Example #11
0
        private async Task <int> RemoveTask(string taskId)
        {
            if (string.IsNullOrEmpty(taskId))
            {
                mLogger.LogError("No task id given to remove");
                return(1);
            }

            Uri taskUri = TaskerUris.WorkTasksUri.CombineRelative(taskId);

            using HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Delete, taskUri);

            WorkTaskResource workTaskResource = await HttpMessageRequester.SendHttpRequestMessage <WorkTaskResource>(
                mHttpClient, httpRequestMessage, mLogger).ConfigureAwait(false);

            if (workTaskResource != null)
            {
                mLogger.LogInformation($"Delete task id {workTaskResource.TaskId}. Description: {workTaskResource.Description}");
            }

            return(0);
        }
Example #12
0
        private async Task <int> MoveTask(string taskId, string taskGroup)
        {
            if (string.IsNullOrEmpty(taskId))
            {
                mLogger.LogError("No task id given to move");
                return(1);
            }

            if (string.IsNullOrEmpty(taskGroup))
            {
                mLogger.LogError("No group name or group id given");
                return(1);
            }

            WorkTaskResource workTaskResource = new WorkTaskResource
            {
                TaskId    = taskId,
                GroupName = taskGroup
            };

            Uri taskUri = TaskerUris.WorkTasksUri.CombineRelative(taskId);

            using HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, taskUri)
                  {
                      Content = new StringContent(JsonConvert.SerializeObject(workTaskResource), Encoding.UTF8, PostMediaType)
                  };

            WorkTaskResource workTaskResourceResponse = await HttpMessageRequester.SendHttpRequestMessage <WorkTaskResource>(
                mHttpClient, httpRequestMessage, mLogger).ConfigureAwait(false);

            if (workTaskResourceResponse != null)
            {
                mLogger.LogInformation($"Moved task {workTaskResourceResponse.TaskId} {workTaskResourceResponse.Description}" +
                                       $"to group {taskGroup}");
            }

            return(0);
        }