/// <summary> /// Initializes Outlook task service using token. /// </summary> /// <param name="token">The token used for msgraph API call.</param> /// <param name="taskFolderIds">Task folder ids.</param> /// <param name="client">The http client to call API.</param> /// <returns>Outlook task service itself.</returns> public async Task <ITaskService> InitAsync(string token, Dictionary <string, string> taskFolderIds, HttpClient client = null) { try { IsListCreated = taskFolderIds.Count == 0; if (client == null) { this.httpClient = ServiceHelper.GetHttpClient(token); } else { this.httpClient = client; } if (!taskFolderIds.ContainsKey(ToDoStrings.ToDo)) { var taskFolderId = await GetOrCreateTaskFolderAsync(ToDoStrings.ToDo); taskFolderIds.Add(ToDoStrings.ToDo, taskFolderId.Item1); IsListCreated = IsListCreated && taskFolderId.Item2; } else { // This is used for the scenario of task folder being deleted. // If a task folder is deleted, will create a new one. var taskFolderId = await GetOrCreateTaskFolderByIdAsync(taskFolderIds[ToDoStrings.ToDo], ToDoStrings.ToDo); taskFolderIds[ToDoStrings.ToDo] = taskFolderId; } if (!taskFolderIds.ContainsKey(ToDoStrings.Grocery)) { var taskFolderId = await GetOrCreateTaskFolderAsync(ToDoStrings.Grocery); taskFolderIds.Add(ToDoStrings.Grocery, taskFolderId.Item1); IsListCreated = IsListCreated && taskFolderId.Item2; } else { var taskFolderId = await GetOrCreateTaskFolderByIdAsync(taskFolderIds[ToDoStrings.Grocery], ToDoStrings.Grocery); taskFolderIds[ToDoStrings.Grocery] = taskFolderId; } if (!taskFolderIds.ContainsKey(ToDoStrings.Shopping)) { var taskFolderId = await GetOrCreateTaskFolderAsync(ToDoStrings.Shopping); taskFolderIds.Add(ToDoStrings.Shopping, taskFolderId.Item1); IsListCreated = IsListCreated && taskFolderId.Item2; } else { var taskFolderId = await GetOrCreateTaskFolderByIdAsync(taskFolderIds[ToDoStrings.Shopping], ToDoStrings.Shopping); taskFolderIds[ToDoStrings.Shopping] = taskFolderId; } this.taskFolderIds = taskFolderIds; return(this); } catch (ServiceException ex) { throw ServiceHelper.HandleGraphAPIException(ex); } }