public static async Task <AutoDiscoveryResult> DoAutoDiscovery(Uri autoDiscoveryUri, IWebDavClient webDavClient, bool useWellKnownCalDav, bool useWellKnownCardDav, OlItemType?selectedOutlookFolderType) { var calDavDataAccess = new CalDavDataAccess(autoDiscoveryUri, webDavClient); var foundCaldendars = await calDavDataAccess.GetUserCalendarsNoThrow(useWellKnownCalDav); var cardDavDataAccess = new CardDavDataAccess(autoDiscoveryUri, webDavClient); IReadOnlyList <Tuple <Uri, string> > foundAddressBooks = await cardDavDataAccess.GetUserAddressBooksNoThrow(useWellKnownCardDav); if (foundCaldendars.Count > 0 || foundAddressBooks.Count > 0) { using (SelectResourceForm listCalendarsForm = new SelectResourceForm( foundCaldendars, foundAddressBooks, new Tuple <string, string> [0], selectedOutlookFolderType == OlItemType.olContactItem ? ResourceType.AddressBook : ResourceType.Calendar)) { if (listCalendarsForm.ShowDialog() == DialogResult.OK) { return(new AutoDiscoveryResult(new Uri(autoDiscoveryUri.GetLeftPart(UriPartial.Authority) + listCalendarsForm.SelectedUrl), false, listCalendarsForm.ResourceType)); } else { return(new AutoDiscoveryResult(null, true, ResourceType.None)); } } } else { return(new AutoDiscoveryResult(null, false, ResourceType.None)); } }
static TaskListData SelectTaskList(IReadOnlyList <TaskListData> items) { using (SelectResourceForm selectResourceForm = SelectResourceForm.CreateForResourceSelection(ResourceType.TaskList, null, null, items.Select(d => new TaskListDataViewModel(d)).ToArray())) { if (selectResourceForm.ShowDialog() == DialogResult.OK) { return(((TaskListDataViewModel)selectResourceForm.SelectedObject).Model); } else { return(null); } } }
static AddressBookData SelectAddressBook(IReadOnlyList <AddressBookData> items) { using (SelectResourceForm selectResourceForm = SelectResourceForm.CreateForResourceSelection(ResourceType.AddressBook, null, items.Select(d => new AddressBookDataViewModel(d)).ToArray())) { if (selectResourceForm.ShowDialog() == DialogResult.OK) { return(((AddressBookDataViewModel)selectResourceForm.SelectedObject).Model); } else { return(null); } } }
static CalendarData SelectCalendar(IReadOnlyList <CalendarData> items) { using (SelectResourceForm selectResourceForm = SelectResourceForm.CreateForResourceSelection(ResourceType.Calendar, items.Select(d => new CalendarDataViewModel(d)).ToArray())) { if (selectResourceForm.ShowDialog() == DialogResult.OK) { return(((CalendarDataViewModel)selectResourceForm.SelectedObject).Model); } else { return(null); } } }
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 static async Task<AutoDiscoveryResult> DoAutoDiscovery (Uri autoDiscoveryUri, IWebDavClient webDavClient, bool useWellKnownCalDav, bool useWellKnownCardDav, OlItemType? selectedOutlookFolderType) { var calDavDataAccess = new CalDavDataAccess (autoDiscoveryUri, webDavClient); IReadOnlyList<Tuple<Uri, string, string>> foundCaldendars = await calDavDataAccess.GetUserCalendarsNoThrow (useWellKnownCalDav); var cardDavDataAccess = new CardDavDataAccess (autoDiscoveryUri, webDavClient); IReadOnlyList<Tuple<Uri, string>> foundAddressBooks = await cardDavDataAccess.GetUserAddressBooksNoThrow (useWellKnownCardDav); if (foundCaldendars.Count > 0 || foundAddressBooks.Count > 0) { using (SelectResourceForm listCalendarsForm = new SelectResourceForm ( foundCaldendars, foundAddressBooks, new Tuple<string, string>[0], selectedOutlookFolderType == OlItemType.olContactItem ? ResourceType.AddressBook : ResourceType.Calendar)) { if (listCalendarsForm.ShowDialog() == DialogResult.OK) return new AutoDiscoveryResult (new Uri (autoDiscoveryUri.GetLeftPart (UriPartial.Authority) + listCalendarsForm.SelectedUrl), false, listCalendarsForm.ResourceType); else return new AutoDiscoveryResult (null, true, ResourceType.None); } } else { MessageBox.Show (useWellKnownCalDav ? "No resources were found via well-known URLs!" : "No resources were found via autodiscovery!", OptionTasks.ConnectionTestCaption); return new AutoDiscoveryResult (null, false, ResourceType.None); } }
private async Task TestGoogleConnection () { StringBuilder errorMessageBuilder = new StringBuilder (); if (!OptionTasks.ValidateGoogleEmailAddress (errorMessageBuilder, _emailAddressTextBox.Text)) { MessageBox.Show (errorMessageBuilder.ToString(), "The Email Address is invalid", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (UsedServerAdapterType == ServerAdapterType.GoogleTaskApi && !string.IsNullOrWhiteSpace (_calenderUrlTextBox.Text) && _calenderUrlTextBox.Text != c_googleDavBaseUrl) { var service = await OAuth.Google.GoogleHttpClientFactory.LoginToGoogleTasksService (_emailAddressTextBox.Text); try { TaskList task = await service.Tasklists.Get (_calenderUrlTextBox.Text).ExecuteAsync(); } catch (Exception) { errorMessageBuilder.AppendFormat ("The tasklist with id '{0}' is invalid.", _calenderUrlTextBox.Text); MessageBox.Show(errorMessageBuilder.ToString(), "The tasklist is invalid", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } TestResult result = new TestResult (ResourceType.TaskList, CalendarProperties.None, AddressBookProperties.None); OptionTasks.DisplayTestReport (result, false, _dependencies.SelectedSynchronizationModeDisplayName, _dependencies.OutlookFolderType, UsedServerAdapterType); return; } if (!OptionTasks.ValidateWebDavUrl (_calenderUrlTextBox.Text, errorMessageBuilder, false)) { MessageBox.Show (errorMessageBuilder.ToString(), "The CalDav/CardDav Url is invalid", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var enteredUri = new Uri (_calenderUrlTextBox.Text); var webDavClient = CreateWebDavClient (); Uri autoDiscoveredUrl; ResourceType autoDiscoveredResourceType; if (ConnectionTester.RequiresAutoDiscovery (enteredUri)) { var calDavDataAccess = new CalDavDataAccess(enteredUri, webDavClient); IReadOnlyList<Tuple<Uri, string, string>> foundCaldendars = await calDavDataAccess.GetUserCalendarsNoThrow(false); var cardDavDataAccess = new CardDavDataAccess(enteredUri, webDavClient); IReadOnlyList<Tuple<Uri, string>> foundAddressBooks = await cardDavDataAccess.GetUserAddressBooksNoThrow(true); var service = await OAuth.Google.GoogleHttpClientFactory.LoginToGoogleTasksService(_emailAddressTextBox.Text); TaskLists taskLists = await service.Tasklists.List().ExecuteAsync(); if (foundCaldendars.Count > 0 || foundAddressBooks.Count > 0 || taskLists.Items.Any()) { ResourceType initalResourceType; if (_dependencies.OutlookFolderType == OlItemType.olContactItem) { initalResourceType = ResourceType.AddressBook; } else if (_dependencies.OutlookFolderType == OlItemType.olTaskItem) { initalResourceType = ResourceType.TaskList; } else { initalResourceType = ResourceType.Calendar; } using (SelectResourceForm listCalendarsForm = new SelectResourceForm( foundCaldendars, foundAddressBooks, taskLists.Items.Select(i => Tuple.Create(i.Id, i.Title)).ToArray(), initalResourceType)) { if (listCalendarsForm.ShowDialog() == DialogResult.OK) { if (listCalendarsForm.ResourceType == ResourceType.TaskList) { autoDiscoveredUrl = null; _calenderUrlTextBox.Text = listCalendarsForm.SelectedUrl; UsedServerAdapterType = ServerAdapterType.GoogleTaskApi; } else { autoDiscoveredUrl = new Uri(enteredUri.GetLeftPart(UriPartial.Authority) + listCalendarsForm.SelectedUrl); UsedServerAdapterType = ServerAdapterType.WebDavHttpClientBasedWithGoogleOAuth; } autoDiscoveredResourceType = listCalendarsForm.ResourceType; } else { autoDiscoveredUrl = null; autoDiscoveredResourceType = ResourceType.None; } } } else { MessageBox.Show("No resources were found via autodiscovery!", OptionTasks.ConnectionTestCaption); autoDiscoveredUrl = null; autoDiscoveredResourceType = ResourceType.None; } } else { var result = await ConnectionTester.TestConnection (enteredUri, webDavClient, ResourceType.None); if (result.ResourceType != ResourceType.None) { _settingsFaultFinder.FixSynchronizationMode (result); } OptionTasks.DisplayTestReport ( result, _dependencies.SelectedSynchronizationModeRequiresWriteableServerResource, _dependencies.SelectedSynchronizationModeDisplayName, _dependencies.OutlookFolderType, UsedServerAdapterType); return; } if (autoDiscoveredUrl != null) { _calenderUrlTextBox.Text = autoDiscoveredUrl.ToString(); var finalResult = await ConnectionTester.TestConnection(autoDiscoveredUrl, webDavClient, autoDiscoveredResourceType); _settingsFaultFinder.FixSynchronizationMode(finalResult); OptionTasks.DisplayTestReport( finalResult, _dependencies.SelectedSynchronizationModeRequiresWriteableServerResource, _dependencies.SelectedSynchronizationModeDisplayName, _dependencies.OutlookFolderType, UsedServerAdapterType); } else if (UsedServerAdapterType == ServerAdapterType.GoogleTaskApi) { TestResult result = new TestResult(ResourceType.TaskList, CalendarProperties.None, AddressBookProperties.None); OptionTasks.DisplayTestReport (result,false,_dependencies.SelectedSynchronizationModeDisplayName, _dependencies.OutlookFolderType, UsedServerAdapterType); } }
public static async Task TestGoogleConnection(ICurrentOptions currentOptions, ISettingsFaultFinder settingsFaultFinder) { if (currentOptions.OutlookFolderType == null) { MessageBox.Show("Please select an Outlook folder to specify the item type for this profile", ConnectionTestCaption); return; } var outlookFolderType = currentOptions.OutlookFolderType.Value; StringBuilder errorMessageBuilder = new StringBuilder(); if (!ValidateGoogleEmailAddress(errorMessageBuilder, currentOptions.EmailAddress)) { MessageBox.Show(errorMessageBuilder.ToString(), "The Email Address is invalid", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (outlookFolderType == OlItemType.olTaskItem) { await TestGoogleTaskConnection(currentOptions, errorMessageBuilder, outlookFolderType); return; } if (!ValidateWebDavUrl(currentOptions.ServerUrl, errorMessageBuilder, false)) { MessageBox.Show(errorMessageBuilder.ToString(), "The CalDav/CardDav Url is invalid", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var enteredUri = new Uri(currentOptions.ServerUrl); var webDavClient = currentOptions.CreateWebDavClient(); Uri autoDiscoveredUrl; ResourceType autoDiscoveredResourceType; if (ConnectionTester.RequiresAutoDiscovery(enteredUri)) { var calDavDataAccess = new CalDavDataAccess(enteredUri, webDavClient); var foundCaldendars = await calDavDataAccess.GetUserCalendarsNoThrow(false); var cardDavDataAccess = new CardDavDataAccess(enteredUri, webDavClient); IReadOnlyList <Tuple <Uri, string> > foundAddressBooks = await cardDavDataAccess.GetUserAddressBooksNoThrow(true); if (foundCaldendars.Count > 0 || foundAddressBooks.Count > 0) { ResourceType initalResourceType; if (currentOptions.OutlookFolderType == OlItemType.olContactItem) { initalResourceType = ResourceType.AddressBook; } else if (currentOptions.OutlookFolderType == OlItemType.olTaskItem) { initalResourceType = ResourceType.TaskList; } else { initalResourceType = ResourceType.Calendar; } using (SelectResourceForm listCalendarsForm = new SelectResourceForm( foundCaldendars, foundAddressBooks, new Tuple <string, string>[] {}, initalResourceType)) { if (listCalendarsForm.ShowDialog() == DialogResult.OK) { if (listCalendarsForm.ResourceType == ResourceType.TaskList) { autoDiscoveredUrl = null; currentOptions.ServerUrl = listCalendarsForm.SelectedUrl; } else { autoDiscoveredUrl = new Uri(enteredUri.GetLeftPart(UriPartial.Authority) + listCalendarsForm.SelectedUrl); } autoDiscoveredResourceType = listCalendarsForm.ResourceType; } else { autoDiscoveredUrl = null; autoDiscoveredResourceType = ResourceType.None; } } } else { MessageBox.Show("No resources were found via autodiscovery!", ConnectionTestCaption); autoDiscoveredUrl = null; autoDiscoveredResourceType = ResourceType.None; } } else { var result = await ConnectionTester.TestConnection(enteredUri, webDavClient, ResourceType.None); if (result.ResourceType != ResourceType.None) { settingsFaultFinder.FixSynchronizationMode(result); } DisplayTestReport( result, currentOptions.SynchronizationMode, currentOptions.SynchronizationModeDisplayName, outlookFolderType); return; } if (autoDiscoveredUrl != null) { currentOptions.ServerUrl = autoDiscoveredUrl.ToString(); var finalResult = await ConnectionTester.TestConnection(autoDiscoveredUrl, webDavClient, autoDiscoveredResourceType); settingsFaultFinder.FixSynchronizationMode(finalResult); DisplayTestReport( finalResult, currentOptions.SynchronizationMode, currentOptions.SynchronizationModeDisplayName, outlookFolderType); } else if (outlookFolderType == OlItemType.olTaskItem) { TestResult result = new TestResult(ResourceType.TaskList, CalendarProperties.None, AddressBookProperties.None); DisplayTestReport( result, currentOptions.SynchronizationMode, currentOptions.SynchronizationModeDisplayName, outlookFolderType); } }