/// <summary> /// Retrieve task by task uid /// </summary> /// <param name="uid">object uid</param> /// <param name="detailsLevel">details level</param> /// <param name="wait">wait</param> /// <returns>A Tuple with Task object and TaskStatus</returns> public async ValueTask <(JsonElement?TaskObject, TaskStatus?TaskStatusCode)> GetTaskWithTaskStatus(string uid, DetailsLevel detailsLevel = DetailsLevel.Standard, bool wait = true) { var queryParams = new Dictionary <string, string>() { { "task-id", uid }, { "details-level", detailsLevelParamStrings[detailsLevel] }, }; string queryRequestParamsJsonString = JsonSerializer.Serialize(queryParams); using var queryRequestParamsJsonDocument = JsonDocument.Parse(queryRequestParamsJsonString); var queryRequestParamsJsonElement = queryRequestParamsJsonDocument.RootElement; try { string status; var taskResult = CheckTaskResult(await GetTaskInternal(queryRequestParamsJsonElement), out status); while (wait && (status == taskStatusReturnStrings[TaskStatus.InProgress])) { await Task.Delay(5000); taskResult = CheckTaskResult(await GetTaskInternal(queryRequestParamsJsonElement), out status); } TaskStatus?taskStatusCode = null; foreach (var taskStatusKey in taskStatusReturnStrings.Keys) { if (status == taskStatusReturnStrings[taskStatusKey]) { taskStatusCode = taskStatusKey; break; } } await Done.InvokeAsync(); // Notify the subscriber return(taskResult, taskStatusCode); } catch (Exception error) { Console.Error.WriteLine("Failed to get task (" + uid + ") - " + error); return(null, null); } }