/// <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; } if (!pageIds.ContainsKey(ToDoStrings.ToDo) || !pageIds.ContainsKey(ToDoStrings.Grocery) || !pageIds.ContainsKey(ToDoStrings.Shopping)) { var notebookId = await GetOrCreateNotebookAsync(ToDoStrings.OneNoteBookName); var sectionId = await GetOrCreateSectionAsync(notebookId, ToDoStrings.OneNoteSectionName); if (!pageIds.ContainsKey(ToDoStrings.ToDo)) { var toDoPageId = await GetOrCreatePageAsync(sectionId, ToDoStrings.ToDo); pageIds.Add(ToDoStrings.ToDo, toDoPageId.Item1); IsListCreated = IsListCreated && toDoPageId.Item2; } if (!pageIds.ContainsKey(ToDoStrings.Grocery)) { var groceryPageId = await GetOrCreatePageAsync(sectionId, ToDoStrings.Grocery); pageIds.Add(ToDoStrings.Grocery, groceryPageId.Item1); IsListCreated = IsListCreated && groceryPageId.Item2; } if (!pageIds.ContainsKey(ToDoStrings.Shopping)) { var shoppingPageId = await GetOrCreatePageAsync(sectionId, ToDoStrings.Shopping); pageIds.Add(ToDoStrings.Shopping, shoppingPageId.Item1); IsListCreated = IsListCreated && shoppingPageId.Item2; } } this.pageIds = pageIds; return(this); } catch (ServiceException ex) { throw ServiceHelper.HandleGraphAPIException(ex); } }
/// <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); } }
/// <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); } }
/// <summary> /// Initializes a new instance of the <see cref="MailService"/> class. /// Init service use token. /// </summary> /// <param name="token">access token.</param> /// <returns>Mail service itself.</returns> public async Task <IMailService> InitAsync(string token) { httpClient = ServiceHelper.GetHttpClient(token); graphServiceClient = ServiceHelper.GetAuthenticatedClient(token); return(await Task.FromResult(this)); }