Example #1
0
        /// <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
            {
                this.httpClient = ServiceHelper.GetHttpClient(token);
                if (!taskFolderIds.ContainsKey(ToDoStrings.ToDo))
                {
                    var taskFolderId = await GetOrCreateTaskFolderAsync(ToDoStrings.ToDo);

                    taskFolderIds.Add(ToDoStrings.ToDo, taskFolderId);
                }

                if (!taskFolderIds.ContainsKey(ToDoStrings.Grocery))
                {
                    var taskFolderId = await GetOrCreateTaskFolderAsync(ToDoStrings.Grocery);

                    taskFolderIds.Add(ToDoStrings.Grocery, taskFolderId);
                }

                if (!taskFolderIds.ContainsKey(ToDoStrings.Shopping))
                {
                    var taskFolderId = await GetOrCreateTaskFolderAsync(ToDoStrings.Shopping);

                    taskFolderIds.Add(ToDoStrings.Shopping, taskFolderId);
                }

                this.taskFolderIds = taskFolderIds;
                return(this);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #2
0
        /// <summary>
        /// Initializes ToDoService using token.
        /// </summary>
        /// <param name="token">the token used for msgraph API call.</param>
        /// <param name="pageId">the page id.</param>
        /// <returns>To Do service itself.</returns>
        public async Task <IToDoService> Init(string token, string pageId)
        {
            try
            {
                this.httpClient = ServiceHelper.GetHttpClient(token);
                if (string.IsNullOrEmpty(pageId))
                {
                    var notebookId = await this.GetOrCreateNotebookAsync(OneNoteNotebookName);

                    var sectionId = await this.GetOrCreateSectionAsync(notebookId, OneNoteSectionName);

                    this.pageId = await this.GetOrCreatePageAsync(sectionId, OneNoteToPageName);
                }
                else
                {
                    this.pageId = pageId;
                }

                return(this);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #3
0
        /// <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>
        /// <returns>Outlook task service itself.</returns>
        public async Task <ITaskService> InitAsync(string token, Dictionary <string, string> taskFolderIds)
        {
            try
            {
                this.httpClient = ServiceHelper.GetHttpClient(token);
                if (!taskFolderIds.ContainsKey(ToDoTaskFolder))
                {
                    var taskFolderId = await GetOrCreateTaskFolderAsync(ToDoTaskFolder);

                    taskFolderIds.Add(ToDoTaskFolder, taskFolderId);
                }

                if (!taskFolderIds.ContainsKey(GroceryTaskFolder))
                {
                    var taskFolderId = await GetOrCreateTaskFolderAsync(GroceryTaskFolder);

                    taskFolderIds.Add(GroceryTaskFolder, taskFolderId);
                }

                if (!taskFolderIds.ContainsKey(ShoppingTaskFolder))
                {
                    var taskFolderId = await GetOrCreateTaskFolderAsync(ShoppingTaskFolder);

                    taskFolderIds.Add(ShoppingTaskFolder, taskFolderId);
                }

                this.taskFolderIds = taskFolderIds;
                return(this);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #4
0
        /// <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);
            }
        }
Example #5
0
 /// <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));
 }
Example #6
0
        /// <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);
            }
        }