private async Task <string> TestGoogleContactsConnection(OptionsModel options, OlItemType outlookFolderType, string url) { var service = await GoogleHttpClientFactory.LoginToContactsService(options.EmailAddress, options.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, AccessPrivileges.All, false, null); DisplayTestReport( result, options.SynchronizationMode, _enumDisplayNameProvider.Get(options.SynchronizationMode), outlookFolderType); return(string.Empty); }
private async Task <string> TestGoogleTaskConnection(OptionsModel options, StringBuilder errorMessageBuilder, OlItemType outlookFolderType, string url) { var service = await GoogleHttpClientFactory.LoginToGoogleTasksService(options.EmailAddress, options.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, AccessPrivileges.All)).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(Strings.Get($"The tasklist with id '{connectionTestUrl}' is invalid.")); MessageBox.Show(errorMessageBuilder.ToString(), Strings.Get($"The tasklist is invalid"), MessageBoxButtons.OK, MessageBoxIcon.Error); return(url); } TestResult result = new TestResult(ResourceType.TaskList, CalendarProperties.None, AddressBookProperties.None, AccessPrivileges.None, false, null); DisplayTestReport( result, options.SynchronizationMode, _enumDisplayNameProvider.Get(options.SynchronizationMode), outlookFolderType); return(connectionTestUrl); }
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); }
public async Task <ServerResources> GetServerResources(NetworkSettingsViewModel networkSettings, GeneralOptions generalOptions) { var trimmedUrl = CalenderUrl.Trim(); var url = new Uri(trimmedUrl.EndsWith("/") ? trimmedUrl : trimmedUrl + "/"); var webDavClient = CreateWebDavClient(networkSettings, generalOptions); var calDavDataAccess = new CalDavDataAccess(url, webDavClient); var foundResources = await calDavDataAccess.GetUserResourcesNoThrow(false); var foundAddressBooks = new[] { new AddressBookData(new Uri("googleApi://defaultAddressBook"), "Default AddressBook") }; var service = await GoogleHttpClientFactory.LoginToGoogleTasksService(EmailAddress, SynchronizerFactory.CreateProxy(networkSettings.CreateProxyOptions())); var taskLists = await service.Tasklists.List().ExecuteAsync(); var taskListsData = taskLists?.Items.Select(i => new TaskListData(i.Id, i.Title)).ToArray() ?? new TaskListData[] { }; return(new ServerResources(foundResources.CalendarResources, foundAddressBooks, taskListsData)); }
public async Task <ServerResources> GetServerResources() { var trimmedUrl = CalenderUrl.Trim(); var url = new Uri(trimmedUrl.EndsWith("/") ? trimmedUrl : trimmedUrl + "/"); var webDavClient = _prototypeModel.CreateWebDavClient(); var calDavDataAccess = new CalDavDataAccess(url, webDavClient); var foundResources = await calDavDataAccess.GetUserResourcesIncludingCalendarProxies(false); var foundAddressBooks = new[] { new AddressBookData(new Uri("googleApi://defaultAddressBook"), "Default AddressBook", AccessPrivileges.All) }; var service = await GoogleHttpClientFactory.LoginToGoogleTasksService(EmailAddress, SynchronizerFactory.CreateProxy(_prototypeModel.CreateProxyOptions())); var taskLists = await service.Tasklists.List().ExecuteAsync(); var taskListsData = taskLists?.Items.Select(i => new TaskListData(i.Id, i.Title, AccessPrivileges.All)).ToArray() ?? new TaskListData[] { }; return(new ServerResources(foundResources.CalendarResources, foundAddressBooks, taskListsData)); }