/// <summary> /// Init task service. /// </summary> /// <param name="token">Task service token.</param> /// <param name="pageIds">OneNote page name and id dictionary.</param> /// <param name="client">the httpclient for making the API request.</param> /// <returns>Task service itself.</returns> public async Task <ITaskService> InitAsync(string token, Dictionary <string, string> pageIds, HttpClient client = null) { try { IsListCreated = pageIds.Count == 0; if (client == null) { httpClient = ServiceHelper.GetHttpClient(token); } else { httpClient = client; } List <string> customizedListTypes = ServiceHelper.GetListTypes(this.Configuration); string notebookId = null; string sectionId = null; foreach (var customizedListType in customizedListTypes) { string pageTitle = customizedListType; if (!pageIds.ContainsKey(pageTitle)) { if (notebookId == null || sectionId == null) { notebookId = await GetOrCreateNotebookAsync(ToDoStrings.OneNoteBookName); sectionId = await GetOrCreateSectionAsync(notebookId, ToDoStrings.OneNoteSectionName); } var pageId = await GetOrCreatePageAsync(sectionId, pageTitle); pageIds.Add(pageTitle, pageId.Item1); IsListCreated = IsListCreated && pageId.Item2; } } this.pageIds = pageIds; return(this); } catch (ServiceException ex) { throw ServiceHelper.HandleGraphAPIException(ex); } }
/// <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; } List <string> customizedListTypes = ServiceHelper.GetListTypes(this.Configuration); foreach (string customizedListType in customizedListTypes) { string taskFolderName = customizedListType; if (!taskFolderIds.ContainsKey(taskFolderName)) { var taskFolderId = await GetOrCreateTaskFolderAsync(taskFolderName); taskFolderIds.Add(taskFolderName, 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[taskFolderName], taskFolderName); taskFolderIds[taskFolderName] = taskFolderId; } } this.taskFolderIds = taskFolderIds; return(this); } catch (ServiceException ex) { throw ServiceHelper.HandleGraphAPIException(ex); } }