예제 #1
0
        public static async Task <Uri> AddResource(Uri davUri, IWebDavClient webDavClient, OlItemType selectedOutlookFolderType)
        {
            switch (selectedOutlookFolderType)
            {
            case OlItemType.olAppointmentItem:
            case OlItemType.olTaskItem:
                var calDavDataAccess = new CalDavDataAccess(davUri, webDavClient);
                using (var addResourceForm = new AddResourceForm(true))
                {
                    addResourceForm.Text = Strings.Get($"Add calendar resource on server");
                    if (addResourceForm.ShowDialog() == DialogResult.OK)
                    {
                        try
                        {
                            var newUri = await calDavDataAccess.AddResource(addResourceForm.ResourceName, addResourceForm.UseRandomUri);

                            MessageBox.Show(Strings.Get($"Added calendar resource '{addResourceForm.ResourceName}' successfully!"), CreateDavResourceCaption, MessageBoxButtons.OK, MessageBoxIcon.Information);
                            if (!await new CalDavDataAccess(newUri, webDavClient).SetCalendarColorNoThrow(new ArgbColor(addResourceForm.CalendarColor.ToArgb())))
                            {
                                MessageBox.Show(Strings.Get($"Can't set the calendar color!'"), CreateDavResourceCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                            return(newUri);
                        }
                        catch (Exception ex)
                        {
                            s_logger.Error($"Can't add calendar resource '{addResourceForm.ResourceName}'", ex);
                            MessageBox.Show(Strings.Get($"Can't add calendar resource '{addResourceForm.ResourceName}'"), CreateDavResourceCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }

                break;

            case OlItemType.olContactItem:
                var cardDavDataAccess = new CardDavDataAccess(davUri, webDavClient, string.Empty, contentType => true);
                using (var addResourceForm = new AddResourceForm(false))
                {
                    addResourceForm.Text = Strings.Get($"Add addressbook resource on server");
                    if (addResourceForm.ShowDialog() == DialogResult.OK)
                    {
                        try
                        {
                            var newUri = await cardDavDataAccess.AddResource(addResourceForm.ResourceName, addResourceForm.UseRandomUri);

                            MessageBox.Show(Strings.Get($"Added addressbook resource '{addResourceForm.ResourceName}' successfully!"), CreateDavResourceCaption, MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return(newUri);
                        }
                        catch (Exception ex)
                        {
                            s_logger.Error($"Can't add addressbook resource '{addResourceForm.ResourceName}'", ex);
                            MessageBox.Show(Strings.Get($"Can't add addressbook resource '{addResourceForm.ResourceName}'"), CreateDavResourceCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }

                break;
            }

            return(davUri);
        }
예제 #2
0
        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, selectedOutlookFolderType == OlItemType.olContactItem))
                {
                    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));
            }
        }
예제 #3
0
 private static async Task <CalendarProperties> GetCalendarProperties(CalDavDataAccess calDavDataAccess)
 {
     return
         ((await calDavDataAccess.IsCalendarAccessSupported() ? CalendarProperties.CalendarAccessSupported : CalendarProperties.None) |
          (await calDavDataAccess.IsWriteable() ? CalendarProperties.IsWriteable : CalendarProperties.None) |
          (await calDavDataAccess.DoesSupportCalendarQuery() ? CalendarProperties.SupportsCalendarQuery : CalendarProperties.None));
 }
예제 #4
0
        public static async Task <AutoDiscoveryResult> DoAutoDiscovery(Uri autoDiscoveryUri, IWebDavClient webDavClient, bool useWellKnownCalDav, bool useWellKnownCardDav, OlItemType selectedOutlookFolderType)
        {
            switch (selectedOutlookFolderType)
            {
            case OlItemType.olAppointmentItem:
                var calDavDataAccess = new CalDavDataAccess(autoDiscoveryUri, webDavClient);
                var foundCalendars   = (await calDavDataAccess.GetUserResourcesIncludingCalendarProxies(useWellKnownCalDav)).CalendarResources;
                if (foundCalendars.Count == 0)
                {
                    return(new AutoDiscoveryResult(null, AutoDiscoverResultStatus.NoResourcesFound));
                }
                var selectedCalendar = SelectCalendar(foundCalendars);
                if (selectedCalendar != null)
                {
                    return(new AutoDiscoveryResult(selectedCalendar.Uri, AutoDiscoverResultStatus.ResourceSelected));
                }
                else
                {
                    return(new AutoDiscoveryResult(null, AutoDiscoverResultStatus.UserCancelled));
                }

            case OlItemType.olTaskItem:
                var calDavDataAccessTasks = new CalDavDataAccess(autoDiscoveryUri, webDavClient);
                var foundTasks            = (await calDavDataAccessTasks.GetUserResourcesIncludingCalendarProxies(useWellKnownCalDav)).TaskListResources;
                if (foundTasks.Count == 0)
                {
                    return(new AutoDiscoveryResult(null, AutoDiscoverResultStatus.NoResourcesFound));
                }
                var selectedTask = SelectTaskList(foundTasks);
                if (selectedTask != null)
                {
                    return(new AutoDiscoveryResult(new Uri(selectedTask.Id), AutoDiscoverResultStatus.ResourceSelected));
                }
                else
                {
                    return(new AutoDiscoveryResult(null, AutoDiscoverResultStatus.UserCancelled));
                }

            case OlItemType.olContactItem:
                var cardDavDataAccess = new CardDavDataAccess(autoDiscoveryUri, webDavClient, string.Empty, contentType => true);
                var foundAddressBooks = await cardDavDataAccess.GetUserAddressBooksNoThrow(useWellKnownCardDav);

                if (foundAddressBooks.Count == 0)
                {
                    return(new AutoDiscoveryResult(null, AutoDiscoverResultStatus.NoResourcesFound));
                }
                var selectedAddressBook = SelectAddressBook(foundAddressBooks);
                if (selectedAddressBook != null)
                {
                    return(new AutoDiscoveryResult(selectedAddressBook.Uri, AutoDiscoverResultStatus.ResourceSelected));
                }
                else
                {
                    return(new AutoDiscoveryResult(null, AutoDiscoverResultStatus.UserCancelled));
                }

            default:
                throw new NotImplementedException($"'{selectedOutlookFolderType}' not implemented.");
            }
        }
        private async Task <IOutlookSynchronizer> CreateEventSynchronizer(Options options, GeneralOptions generalOptions, AvailableSynchronizerComponents componentsToFill)
        {
            ICalDavDataAccess calDavDataAccess;

            var calendarUrl = new Uri(options.CalenderUrl);

            if (calendarUrl.Scheme == Uri.UriSchemeFile)
            {
                calDavDataAccess = new FileSystemDavDataAccess(calendarUrl);
            }
            else
            {
                calDavDataAccess = new CalDavDataAccess(
                    calendarUrl,
                    CreateWebDavClient(options, _outlookAccountPasswordProvider, generalOptions));
            }

            componentsToFill.CalDavDataAccess = calDavDataAccess;

            var storageDataDirectory = _profileDataDirectoryFactory(options.Id);

            var entityRelationDataAccess = new EntityRelationDataAccess <AppointmentId, DateTime, OutlookEventRelationData, WebResourceName, string> (storageDataDirectory);

            return(await CreateEventSynchronizer(options, calDavDataAccess, entityRelationDataAccess));
        }
예제 #6
0
        public async Task <ServerResources> GetServerResources()
        {
            string caldavUrlString;
            string carddavUrlString;

            if (string.IsNullOrEmpty(CalenderUrl) && !string.IsNullOrEmpty(EmailAddress))
            {
                bool success;
                caldavUrlString  = OptionTasks.DoSrvLookup(EmailAddress, OlItemType.olAppointmentItem, out success);
                carddavUrlString = OptionTasks.DoSrvLookup(EmailAddress, OlItemType.olContactItem, out success);
            }
            else
            {
                caldavUrlString  = CalenderUrl;
                carddavUrlString = CalenderUrl;
            }

            var trimmedCaldavUrl = caldavUrlString.Trim();
            var caldavUrl        = new Uri(trimmedCaldavUrl.EndsWith("/") ? trimmedCaldavUrl : trimmedCaldavUrl + "/");

            var trimmedCarddavUrl = carddavUrlString.Trim();
            var carddavUrl        = new Uri(trimmedCarddavUrl.EndsWith("/") ? trimmedCarddavUrl : trimmedCarddavUrl + "/");

            var webDavClientCaldav  = _prototypeModel.CreateWebDavClient(new Uri(trimmedCaldavUrl));
            var webDavClientCarddav = _prototypeModel.CreateWebDavClient(new Uri(trimmedCarddavUrl));
            var calDavDataAccess    = new CalDavDataAccess(caldavUrl, webDavClientCaldav);
            var cardDavDataAccess   = new CardDavDataAccess(carddavUrl, webDavClientCarddav, string.Empty, contentType => true);

            return(await GetUserResources(calDavDataAccess, cardDavDataAccess));
        }
        private async Task <bool> TestCalendar(CalDavDataAccess calDavDataAccess, StringBuilder errorMessageBuilder)
        {
            bool hasError = false;

            if (!await calDavDataAccess.IsCalendarAccessSupported())
            {
                errorMessageBuilder.AppendLine("- The specified Url does not support calendar access.");
                hasError = true;
            }

            if (!await calDavDataAccess.IsWriteable())
            {
                errorMessageBuilder.AppendLine("- The specified Url is a read-only calendar.");
                hasError = true;
            }

            if (!await calDavDataAccess.DoesSupportCalendarQuery())
            {
                errorMessageBuilder.AppendLine("- The specified Url does not support Calendar Queries.");
                hasError = true;
            }

            if (_folderType != OlItemType.olAppointmentItem && _folderType != OlItemType.olTaskItem)
            {
                errorMessageBuilder.AppendLine("- The outlook folder is not a calendar or task folder, or there is no folder selected.");
                hasError = true;
            }

            return(hasError);
        }
        public async Task <ServerResources> GetServerResources(NetworkSettingsViewModel networkSettings, GeneralOptions generalOptions)
        {
            string caldavUrlString;
            string carddavUrlString;

            if (string.IsNullOrEmpty(CalenderUrl) && !string.IsNullOrEmpty(EmailAddress))
            {
                bool success;
                caldavUrlString  = OptionTasks.DoSrvLookup(EmailAddress, OlItemType.olAppointmentItem, out success);
                carddavUrlString = OptionTasks.DoSrvLookup(EmailAddress, OlItemType.olContactItem, out success);
            }
            else
            {
                caldavUrlString  = CalenderUrl;
                carddavUrlString = CalenderUrl;
            }

            var trimmedCaldavUrl = caldavUrlString.Trim();
            var caldavUrl        = new Uri(trimmedCaldavUrl.EndsWith("/") ? trimmedCaldavUrl : trimmedCaldavUrl + "/");

            var trimmedCarddavUrl = carddavUrlString.Trim();
            var carddavUrl        = new Uri(trimmedCarddavUrl.EndsWith("/") ? trimmedCarddavUrl : trimmedCarddavUrl + "/");

            var webDavClientCaldav  = CreateWebDavClient(networkSettings, generalOptions, trimmedCaldavUrl);
            var webDavClientCarddav = CreateWebDavClient(networkSettings, generalOptions, trimmedCarddavUrl);
            var calDavDataAccess    = new CalDavDataAccess(caldavUrl, webDavClientCaldav);
            var cardDavDataAccess   = new CardDavDataAccess(carddavUrl, webDavClientCarddav);

            return(await GetUserResources(calDavDataAccess, cardDavDataAccess));
        }
예제 #9
0
        private IOutlookSynchronizer CreateTaskSynchronizer(Options options, AvailableSynchronizerComponents componentsToFill)
        {
            var mappingParameters = GetMappingParameters <TaskMappingConfiguration> (options);

            var atypeRepository = new OutlookTaskRepository(_outlookSession, options.OutlookFolderEntryId, options.OutlookFolderStoreId, _daslFilterProvider);

            var calDavDataAccess = new CalDavDataAccess(
                new Uri(options.CalenderUrl),
                CreateWebDavClient(
                    options.UserName,
                    options.GetEffectivePassword(_outlookAccountPasswordProvider),
                    options.CalenderUrl,
                    _calDavConnectTimeout,
                    options.ServerAdapterType,
                    options.CloseAfterEachRequest,
                    options.PreemptiveAuthentication,
                    options.ForceBasicAuthentication,
                    options.ProxyOptions));

            componentsToFill.CalDavDataAccess = calDavDataAccess;

            var btypeRepository = new CalDavRepository(
                calDavDataAccess,
                new iCalendarSerializer(),
                CalDavRepository.EntityType.Todo,
                NullDateTimeRangeProvider.Instance,
                false);

            var outlookEventRelationDataFactory = new OutlookEventRelationDataFactory();
            var syncStateFactory = new EntitySyncStateFactory <string, DateTime, TaskItemWrapper, WebResourceName, string, IICalendar> (
                new TaskMapper(_outlookSession.Application.TimeZones.CurrentTimeZone.ID, mappingParameters),
                atypeRepository,
                btypeRepository,
                outlookEventRelationDataFactory,
                ExceptionHandler.Instance);

            var storageDataDirectory = _profileDataDirectoryFactory(options.Id);

            var btypeIdEqualityComparer = WebResourceName.Comparer;
            var atypeIdEqualityComparer = EqualityComparer <string> .Default;

            var synchronizer = new Synchronizer <string, DateTime, TaskItemWrapper, WebResourceName, string, IICalendar> (
                atypeRepository,
                btypeRepository,
                InitialTaskSyncStateCreationStrategyFactory.Create(
                    syncStateFactory,
                    syncStateFactory.Environment,
                    options.SynchronizationMode,
                    options.ConflictResolution),
                new EntityRelationDataAccess <string, DateTime, OutlookEventRelationData, WebResourceName, string> (storageDataDirectory),
                outlookEventRelationDataFactory,
                new InitialTaskEntityMatcher(btypeIdEqualityComparer),
                atypeIdEqualityComparer,
                btypeIdEqualityComparer,
                _totalProgressFactory,
                ExceptionHandler.Instance);

            return(new OutlookSynchronizer <WebResourceName, string> (synchronizer));
        }
        private static async Task <ServerResources> GetUserResources(CalDavDataAccess calDavDataAccess, CardDavDataAccess cardDavDataAccess, bool useWellKNownUrl)
        {
            var calDavResources = await calDavDataAccess.GetUserResourcesNoThrow(useWellKNownUrl);

            var foundAddressBooks = await cardDavDataAccess.GetUserAddressBooksNoThrow(useWellKNownUrl);

            return(new ServerResources(calDavResources.CalendarResources, foundAddressBooks, calDavResources.TaskListResources));
        }
        private void TestServerConnection()
        {
            const string connectionTestCaption = "Test settings";

            try
            {
                StringBuilder errorMessageBuilder = new StringBuilder();
                if (!ValidateCalendarUrl(errorMessageBuilder))
                {
                    MessageBox.Show(errorMessageBuilder.ToString(), "The calendar Url is invalid", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                var dataAccess = new CalDavDataAccess(
                    new Uri(_calenderUrlTextBox.Text),
                    new CalDavWebClient(
                        _userNameTextBox.Text,
                        _passwordTextBox.Text,
                        TimeSpan.Parse(ConfigurationManager.AppSettings["calDavConnectTimeout"]),
                        TimeSpan.Parse(ConfigurationManager.AppSettings["calDavReadWriteTimeout"]),
                        Boolean.Parse(ConfigurationManager.AppSettings["disableCertificateValidation"]),
                        Boolean.Parse(ConfigurationManager.AppSettings["enableSsl3"]),
                        Boolean.Parse(ConfigurationManager.AppSettings["enableTls12"]))
                    );

                if (!dataAccess.IsCalendarAccessSupported())
                {
                    MessageBox.Show("The specified Url does not support calendar access!", connectionTestCaption);
                }

                if (!dataAccess.IsResourceCalender())
                {
                    MessageBox.Show("The specified Url is not a calendar!", connectionTestCaption);
                }

                if (!dataAccess.IsWriteableCalender())
                {
                    MessageBox.Show("The specified Url is a read-only calendar!", connectionTestCaption);
                }

                if (!dataAccess.DoesSupportCalendarQuery())
                {
                    MessageBox.Show("The specified Url does not support Calendar Queries!", connectionTestCaption);
                }


                MessageBox.Show("Connection test successful.", connectionTestCaption);
            }
            catch (Exception x)
            {
                MessageBox.Show(x.Message, connectionTestCaption);
            }
        }
        private OutlookSynchronizer CreateEventSynchronizer(Options options)
        {
            var calDavDataAccess = new CalDavDataAccess(
                new Uri(options.CalenderUrl),
                CreateWebDavClient(options, _calDavConnectTimeout));

            var storageDataDirectory = _profileDataDirectoryFactory(options.Id);

            var entityRelationDataAccess = new EntityRelationDataAccess <string, DateTime, OutlookEventRelationData, Uri, string> (storageDataDirectory);

            return(CreateEventSynchronizer(options, calDavDataAccess, entityRelationDataAccess));
        }
        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 cardDavDataAccess = new CardDavDataAccess(url, webDavClient);

            var resources = await GetUserResources(calDavDataAccess, cardDavDataAccess, true);

            return(resources.ContainsResources ? resources : await GetUserResources(calDavDataAccess, cardDavDataAccess, false));
        }
        private IOutlookSynchronizer CreateEventSynchronizer(Options options, GeneralOptions generalOptions, AvailableSynchronizerComponents componentsToFill)
        {
            var calDavDataAccess = new CalDavDataAccess(
                new Uri(options.CalenderUrl),
                CreateWebDavClient(options, _calDavConnectTimeout, _outlookAccountPasswordProvider, generalOptions));

            componentsToFill.CalDavDataAccess = calDavDataAccess;

            var storageDataDirectory = _profileDataDirectoryFactory(options.Id);

            var entityRelationDataAccess = new EntityRelationDataAccess <string, DateTime, OutlookEventRelationData, WebResourceName, string> (storageDataDirectory);

            return(CreateEventSynchronizer(options, calDavDataAccess, entityRelationDataAccess));
        }
예제 #15
0
        public static async Task <TestResult> TestConnection(Uri url, IWebDavClient webDavClient)
        {
            var calDavDataAccess  = new CalDavDataAccess(url, webDavClient);
            var cardDavDataAccess = new CardDavDataAccess(url, webDavClient);

            // Note: CalDav Calendars can contain Events and Todos. Therefore an calender resource is always a calendar and a task list.
            var ressourceType =
                (await calDavDataAccess.IsResourceCalender() ? ResourceType.Calendar | ResourceType.TaskList : ResourceType.None) |
                (await cardDavDataAccess.IsResourceAddressBook() ? ResourceType.AddressBook : ResourceType.None);

            return(new TestResult(
                       ressourceType,
                       ressourceType.HasFlag(ResourceType.Calendar) ? await GetCalendarProperties(calDavDataAccess) : CalendarProperties.None,
                       ressourceType.HasFlag(ResourceType.AddressBook) ? await GetAddressBookProperties(cardDavDataAccess) : AddressBookProperties.None));
        }
예제 #16
0
        private static async Task <ServerResources> GetUserResources(CalDavDataAccess calDavDataAccess, CardDavDataAccess cardDavDataAccess)
        {
            var calDavResources = await calDavDataAccess.GetUserResourcesNoThrow(true);

            if (calDavResources.CalendarResources.Count == 0 && calDavResources.TaskListResources.Count == 0)
            {
                calDavResources = await calDavDataAccess.GetUserResourcesNoThrow(false);
            }
            var foundAddressBooks = await cardDavDataAccess.GetUserAddressBooksNoThrow(true);

            if (foundAddressBooks.Count == 0)
            {
                foundAddressBooks = await cardDavDataAccess.GetUserAddressBooksNoThrow(false);
            }
            return(new ServerResources(calDavResources.CalendarResources, foundAddressBooks, calDavResources.TaskListResources));
        }
        public static async Task <TestResult> TestConnection(Uri url, IWebDavClient webDavClient)
        {
            var calDavDataAccess  = new CalDavDataAccess(url, webDavClient);
            var cardDavDataAccess = new CardDavDataAccess(url, webDavClient, string.Empty, contentType => true);

            // Note: CalDav Calendars can contain Events and Todos. Therefore an calender resource is always a calendar and a task list.
            var ressourceType =
                (await calDavDataAccess.IsResourceCalender() ? ResourceType.Calendar | ResourceType.TaskList : ResourceType.None) |
                (await cardDavDataAccess.IsResourceAddressBook() ? ResourceType.AddressBook : ResourceType.None);

            return(new TestResult(
                       ressourceType,
                       ressourceType.HasFlag(ResourceType.Calendar) ? await GetCalendarProperties(calDavDataAccess) : CalendarProperties.None,
                       ressourceType.HasFlag(ResourceType.AddressBook) ? await GetAddressBookProperties(cardDavDataAccess) : AddressBookProperties.None,
                       await calDavDataAccess.GetPrivileges(),
                       await calDavDataAccess.DoesSupportWebDavCollectionSync(),
                       ressourceType.HasFlag(ResourceType.Calendar) ? await calDavDataAccess.GetCalendarOwnerPropertiesOrNull() : null));
        }
        public static CalDavDataAccess CreateCalDavDataAccess(
            string calenderUrl,
            string username,
            string password,
            TimeSpan timeout,
            ServerAdapterType serverAdapterType)
        {
            var productAndVersion = GetProductAndVersion();

            var calDavDataAccess = new CalDavDataAccess(
                new Uri(calenderUrl),
                new CalDavClient(
                    () => CreateHttpClient(username, password, timeout, serverAdapterType),
                    productAndVersion.Item1,
                    productAndVersion.Item2));

            return(calDavDataAccess);
        }
예제 #19
0
        public static async Task <TestResult> TestConnection(Uri url, IWebDavClient webDavClient, ResourceType supposedRessourceType)
        {
            var calDavDataAccess  = new CalDavDataAccess(url, webDavClient);
            var cardDavDataAccess = new CardDavDataAccess(url, webDavClient);

            TestResult result;


            switch (supposedRessourceType)
            {
            case ResourceType.None:
                var ressourceType =
                    (await calDavDataAccess.IsResourceCalender() ? ResourceType.Calendar : ResourceType.None) |
                    (await cardDavDataAccess.IsResourceAddressBook() ? ResourceType.AddressBook : ResourceType.None);

                result = new TestResult(
                    ressourceType,
                    ressourceType.HasFlag(ResourceType.Calendar) ? await GetCalendarProperties(calDavDataAccess) : CalendarProperties.None,
                    ressourceType.HasFlag(ResourceType.AddressBook) ? await GetAddressBookProperties(cardDavDataAccess) : AddressBookProperties.None);
                break;

            case ResourceType.Calendar:
                result = new TestResult(
                    supposedRessourceType,
                    CalendarProperties.CalendarAccessSupported |
                    (await calDavDataAccess.IsWriteable() ? CalendarProperties.IsWriteable : CalendarProperties.None) |
                    (await calDavDataAccess.DoesSupportCalendarQuery() ? CalendarProperties.SupportsCalendarQuery : CalendarProperties.None),
                    AddressBookProperties.None);
                break;

            case ResourceType.AddressBook:
                result = new TestResult(
                    supposedRessourceType,
                    CalendarProperties.None,
                    AddressBookProperties.AddressBookAccessSupported |
                    (await cardDavDataAccess.IsWriteable() ? AddressBookProperties.IsWriteable : AddressBookProperties.None));
                break;

            default:
                throw new ArgumentOutOfRangeException("supposedRessourceType");
            }

            return(result);
        }
예제 #20
0
        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));
        }
예제 #21
0
        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));
        }
예제 #22
0
        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);
            }
        }
        private IOutlookSynchronizer CreateTaskSynchronizer(Options options, GeneralOptions generalOptions, AvailableSynchronizerComponents componentsToFill)
        {
            var mappingParameters = GetMappingParameters <TaskMappingConfiguration> (options);

            var atypeRepository = new OutlookTaskRepository(_outlookSession, options.OutlookFolderEntryId, options.OutlookFolderStoreId, _daslFilterProvider, mappingParameters);



            ICalDavDataAccess calDavDataAccess;
            var calendarUrl = new Uri(options.CalenderUrl);

            if (calendarUrl.Scheme == Uri.UriSchemeFile)
            {
                calDavDataAccess = new FileSystemDavDataAccess(calendarUrl);
            }
            else
            {
                calDavDataAccess = new CalDavDataAccess(
                    calendarUrl,
                    CreateWebDavClient(
                        options.UserName,
                        options.GetEffectivePassword(_outlookAccountPasswordProvider),
                        options.CalenderUrl,
                        generalOptions.CalDavConnectTimeout,
                        options.ServerAdapterType,
                        options.CloseAfterEachRequest,
                        options.PreemptiveAuthentication,
                        options.ForceBasicAuthentication,
                        options.ProxyOptions,
                        generalOptions.EnableClientCertificate,
                        generalOptions.AcceptInvalidCharsInServerResponse));
            }

            componentsToFill.CalDavDataAccess = calDavDataAccess;

            var btypeRepository = new CalDavRepository <int> (
                calDavDataAccess,
                new iCalendarSerializer(),
                CalDavRepository.EntityType.Todo,
                NullDateTimeRangeProvider.Instance,
                false,
                options.IsChunkedSynchronizationEnabled ? new ChunkedExecutor(options.ChunkSize) : NullChunkedExecutor.Instance);

            var relationDataFactory = new TaskRelationDataFactory();
            var syncStateFactory    = new EntitySyncStateFactory <string, DateTime, TaskItemWrapper, WebResourceName, string, IICalendar> (
                new TaskMapper(_outlookSession.Application.TimeZones.CurrentTimeZone.ID, mappingParameters),
                relationDataFactory,
                ExceptionHandler.Instance);

            var storageDataDirectory = _profileDataDirectoryFactory(options.Id);

            var btypeIdEqualityComparer = WebResourceName.Comparer;
            var atypeIdEqualityComparer = EqualityComparer <string> .Default;

            var atypeWriteRepository = BatchEntityRepositoryAdapter.Create(atypeRepository);
            var btypeWriteRepository = BatchEntityRepositoryAdapter.Create(btypeRepository);

            var synchronizer = new Synchronizer <string, DateTime, TaskItemWrapper, WebResourceName, string, IICalendar, int> (
                atypeRepository,
                btypeRepository,
                atypeWriteRepository,
                btypeWriteRepository,
                InitialSyncStateCreationStrategyFactory <string, DateTime, TaskItemWrapper, WebResourceName, string, IICalendar> .Create(
                    syncStateFactory,
                    syncStateFactory.Environment,
                    options.SynchronizationMode,
                    options.ConflictResolution,
                    e => new TaskConflictInitialSyncStateCreationStrategyAutomatic(e)),
                new EntityRelationDataAccess <string, DateTime, TaskRelationData, WebResourceName, string> (storageDataDirectory),
                relationDataFactory,
                new InitialTaskEntityMatcher(btypeIdEqualityComparer),
                atypeIdEqualityComparer,
                btypeIdEqualityComparer,
                _totalProgressFactory,
                ExceptionHandler.Instance,
                NullSynchronizationContextFactory.Instance,
                EqualityComparer <DateTime> .Default,
                EqualityComparer <string> .Default,
                syncStateFactory);

            return(new OutlookSynchronizer <WebResourceName, string> (synchronizer));
        }