private static async Task <string> TestGoogleTaskConnection(ICurrentOptions currentOptions, StringBuilder errorMessageBuilder, OlItemType outlookFolderType, string url) { var service = await GoogleHttpClientFactory.LoginToGoogleTasksService(currentOptions.EmailAddress, currentOptions.GetProxyIfConfigured()); string connectionTestUrl; if (string.IsNullOrEmpty(url)) { TaskLists taskLists = await service.Tasklists.List().ExecuteAsync(); if (taskLists.Items.Any()) { var selectedTaskList = SelectTaskList(taskLists.Items.Select(i => new TaskListData(i.Id, i.Title)).ToArray()); if (selectedTaskList != null) { connectionTestUrl = selectedTaskList.Id; } else { return(url); } } else { connectionTestUrl = url; } } else { connectionTestUrl = url; } try { await service.Tasklists.Get(connectionTestUrl).ExecuteAsync(); } catch (Exception x) { s_logger.Error(null, x); errorMessageBuilder.AppendFormat("The tasklist with id '{0}' is invalid.", connectionTestUrl); MessageBox.Show(errorMessageBuilder.ToString(), "The tasklist is invalid", MessageBoxButtons.OK, MessageBoxIcon.Error); return(url); } TestResult result = new TestResult(ResourceType.TaskList, CalendarProperties.None, AddressBookProperties.None); DisplayTestReport( result, currentOptions.SynchronizationMode, currentOptions.SynchronizationModeDisplayName, outlookFolderType); return(connectionTestUrl); }
private static async Task <string> TestGoogleContactsConnection(ICurrentOptions currentOptions, OlItemType outlookFolderType, string url) { var service = await GoogleHttpClientFactory.LoginToContactsService(currentOptions.EmailAddress, currentOptions.GetProxyIfConfigured()); try { await Task.Run(() => service.GetGroups()); } catch (Exception x) { s_logger.Error(null, x); MessageBox.Show(x.Message, ConnectionTestCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); return(url); } TestResult result = new TestResult( ResourceType.AddressBook, CalendarProperties.None, AddressBookProperties.AddressBookAccessSupported | AddressBookProperties.IsWriteable); DisplayTestReport( result, currentOptions.SynchronizationMode, currentOptions.SynchronizationModeDisplayName, outlookFolderType); return(string.Empty); }
private static async Task TestGoogleTaskConnection(ICurrentOptions currentOptions, StringBuilder errorMessageBuilder, OlItemType outlookFolderType) { var service = await GoogleHttpClientFactory.LoginToGoogleTasksService(currentOptions.EmailAddress, currentOptions.GetProxyIfConfigured()); if (string.IsNullOrEmpty(currentOptions.ServerUrl)) { TaskLists taskLists = await service.Tasklists.List().ExecuteAsync(); if (taskLists.Items.Any()) { using (SelectResourceForm listCalendarsForm = new SelectResourceForm( new Tuple <Uri, string, ArgbColor?>[] { }, new Tuple <Uri, string>[] { }, taskLists.Items.Select(i => Tuple.Create(i.Id, i.Title)).ToArray(), ResourceType.TaskList)) { if (listCalendarsForm.ShowDialog() == DialogResult.OK) { currentOptions.ServerUrl = listCalendarsForm.SelectedUrl; } else { return; } } } } try { await service.Tasklists.Get(currentOptions.ServerUrl).ExecuteAsync(); } catch (Exception) { errorMessageBuilder.AppendFormat("The tasklist with id '{0}' is invalid.", currentOptions.ServerUrl); MessageBox.Show(errorMessageBuilder.ToString(), "The tasklist is invalid", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } TestResult result = new TestResult(ResourceType.TaskList, CalendarProperties.None, AddressBookProperties.None); DisplayTestReport( result, currentOptions.SynchronizationMode, currentOptions.SynchronizationModeDisplayName, outlookFolderType); }