public void FixSynchronizationMode(OptionsModel options, TestResult result) { const SynchronizationMode readOnlyDefaultMode = SynchronizationMode.ReplicateServerIntoOutlook; if (result.ResourceType.HasFlag(ResourceType.Calendar)) { if (!result.AccessPrivileges.HasFlag(AccessPrivileges.Modify) && OptionTasks.DoesModeRequireWriteableServerResource(options.SynchronizationMode)) { options.SynchronizationMode = readOnlyDefaultMode; MessageBox.Show( Strings.Get($"The specified URL is a read-only calendar. Synchronization mode set to '{_enumDisplayNameProvider.Get(readOnlyDefaultMode)}'."), OptionTasks.ConnectionTestCaption); } } if (result.ResourceType.HasFlag(ResourceType.AddressBook)) { if (!result.AccessPrivileges.HasFlag(AccessPrivileges.Modify) && OptionTasks.DoesModeRequireWriteableServerResource(options.SynchronizationMode)) { options.SynchronizationMode = readOnlyDefaultMode; MessageBox.Show( Strings.Get($"The specified URL is a read-only addressbook. Synchronization mode set to '{_enumDisplayNameProvider.Get(readOnlyDefaultMode)}'."), OptionTasks.ConnectionTestCaption); } } if (options.SynchronizationMode == readOnlyDefaultMode && options.SelectedFolderOrNull?.ItemCount > 0) { MessageBox.Show( Strings.Get($"Synchronization mode is set to '{_enumDisplayNameProvider.Get(readOnlyDefaultMode)}' and the selected Outlook folder is not empty. Are you sure, you want to select this folder because all items will be overwritten with the DAV server resources!"), OptionTasks.ConnectionTestCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (options.SynchronizationMode == SynchronizationMode.ReplicateOutlookIntoServer && options.SelectedFolderOrNull?.ItemCount == 0) { MessageBox.Show( Strings.Get($"Synchronization mode is set to '{_enumDisplayNameProvider.Get(SynchronizationMode.ReplicateOutlookIntoServer)}' and the selected Outlook folder is empty. Are you sure, you want to select this folder, because all items on the DAV server will be deleted!"), OptionTasks.ConnectionTestCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
public async Task <string> TestWebDavConnection(OptionsModel options) { string url = options.CalenderUrl; if (options.SelectedFolderOrNull == null) { MessageBox.Show(Strings.Get($"Please select an Outlook folder to specify the item type for this profile"), ConnectionTestCaption); return(url); } var outlookFolderType = options.SelectedFolderOrNull.DefaultItemType; string serverUrl = url; StringBuilder errorMessageBuilder = new StringBuilder(); if (string.IsNullOrEmpty(url) && (!string.IsNullOrEmpty(options.EmailAddress) || !string.IsNullOrEmpty(options.UserName))) { var lookupEmail = !string.IsNullOrEmpty(options.EmailAddress) ? options.EmailAddress : options.UserName; if (!ValidateEmailAddress(errorMessageBuilder, lookupEmail, true)) { MessageBox.Show(errorMessageBuilder.ToString(), Strings.Get($"The Email address is invalid"), MessageBoxButtons.OK, MessageBoxIcon.Error); return(url); } bool success; serverUrl = DoSrvLookup(lookupEmail, outlookFolderType, out success); } if (!ValidateWebDavUrl(serverUrl, errorMessageBuilder, false)) { MessageBox.Show(errorMessageBuilder.ToString(), Strings.Get($"The CalDav/CardDav URL is invalid"), MessageBoxButtons.OK, MessageBoxIcon.Error); return(url); } var enteredUri = new Uri(serverUrl); var webDavClient = options.CreateWebDavClient(enteredUri); Uri autoDiscoveredUrl; if (ConnectionTester.RequiresAutoDiscovery(enteredUri)) { var autodiscoveryResult = await DoAutoDiscovery(enteredUri, webDavClient, true, true, outlookFolderType); switch (autodiscoveryResult.Status) { case AutoDiscoverResultStatus.UserCancelled: return(url); case AutoDiscoverResultStatus.ResourceSelected: autoDiscoveredUrl = autodiscoveryResult.RessourceUrl; break; case AutoDiscoverResultStatus.NoResourcesFound: var autodiscoveryResult2 = await DoAutoDiscovery(enteredUri.AbsolutePath.EndsWith("/")?enteredUri : new Uri(enteredUri.ToString() + "/"), webDavClient, false, false, outlookFolderType); switch (autodiscoveryResult2.Status) { case AutoDiscoverResultStatus.UserCancelled: return(url); case AutoDiscoverResultStatus.ResourceSelected: autoDiscoveredUrl = autodiscoveryResult2.RessourceUrl; break; case AutoDiscoverResultStatus.NoResourcesFound: MessageBox.Show(Strings.Get($"No resources were found via autodiscovery!"), ConnectionTestCaption); return(url); default: throw new NotImplementedException(autodiscoveryResult2.Status.ToString()); } break; default: throw new NotImplementedException(autodiscoveryResult.Status.ToString()); } } else { var result = await ConnectionTester.TestConnection(enteredUri, webDavClient); if (result.ResourceType != ResourceType.None) { FixSynchronizationMode(options, result); FixWebDavCollectionSync(options, result); UpdateServerEmailAndSchedulingSettings(options, result); DisplayTestReport( result, options.SynchronizationMode, _enumDisplayNameProvider.Get(options.SynchronizationMode), outlookFolderType); return(url); } else { var autodiscoveryResult = await DoAutoDiscovery(enteredUri, webDavClient, false, false, outlookFolderType); switch (autodiscoveryResult.Status) { case AutoDiscoverResultStatus.UserCancelled: return(url); case AutoDiscoverResultStatus.ResourceSelected: autoDiscoveredUrl = autodiscoveryResult.RessourceUrl; break; case AutoDiscoverResultStatus.NoResourcesFound: var autodiscoveryResult2 = await DoAutoDiscovery(enteredUri, webDavClient, true, true, outlookFolderType); switch (autodiscoveryResult2.Status) { case AutoDiscoverResultStatus.UserCancelled: return(url); case AutoDiscoverResultStatus.ResourceSelected: autoDiscoveredUrl = autodiscoveryResult2.RessourceUrl; break; case AutoDiscoverResultStatus.NoResourcesFound: MessageBox.Show(Strings.Get($"No resources were found via autodiscovery!"), ConnectionTestCaption); return(url); default: throw new NotImplementedException(autodiscoveryResult2.Status.ToString()); } break; default: throw new NotImplementedException(autodiscoveryResult.Status.ToString()); } } } var finalResult = await ConnectionTester.TestConnection(autoDiscoveredUrl, webDavClient); FixSynchronizationMode(options, finalResult); FixWebDavCollectionSync(options, finalResult); UpdateServerEmailAndSchedulingSettings(options, finalResult); DisplayTestReport( finalResult, options.SynchronizationMode, _enumDisplayNameProvider.Get(options.SynchronizationMode), outlookFolderType); return(autoDiscoveredUrl.ToString()); }
public void FixSynchronizationMode(OptionsModel options, TestResult result) { const SynchronizationMode readOnlyDefaultMode = SynchronizationMode.ReplicateServerIntoOutlook; if (result.ResourceType.HasFlag(ResourceType.Calendar)) { if (!result.AccessPrivileges.HasFlag(AccessPrivileges.Modify) && OptionTasks.DoesModeRequireWriteableServerResource(options.SynchronizationMode)) { options.SynchronizationMode = readOnlyDefaultMode; MessageBox.Show( $"The specified Url is a read-only calendar. Synchronization mode set to '{_enumDisplayNameProvider.Get(readOnlyDefaultMode)}'.", OptionTasks.ConnectionTestCaption); } } if (result.ResourceType.HasFlag(ResourceType.AddressBook)) { if (!result.AccessPrivileges.HasFlag(AccessPrivileges.Modify) && OptionTasks.DoesModeRequireWriteableServerResource(options.SynchronizationMode)) { options.SynchronizationMode = readOnlyDefaultMode; MessageBox.Show( $"The specified Url is a read-only addressbook. Synchronization mode set to '{_enumDisplayNameProvider.Get(readOnlyDefaultMode)}'.", OptionTasks.ConnectionTestCaption); } } }