Пример #1
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.GetUserResourcesNoThrow(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.GetUserResourcesNoThrow(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.");
            }
        }
Пример #2
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));
        }
        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));
        }
Пример #4
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));
        }