Beispiel #1
0
        public void Initialize()
        {
            var applicationDataDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CalDavSynchronizer");

            var optionsDataAccess = new OptionsDataAccess(
                Path.Combine(
                    applicationDataDirectory,
                    ComponentContainer.GetOrCreateConfigFileName(applicationDataDirectory, "Outlook")
                    ));

            var options = optionsDataAccess.LoadOptions().Single(o => o.Name == ProfileName);

            _calDavDataAccess = SynchronizerFactory.CreateCalDavDataAccess(
                options.CalenderUrl,
                options.UserName,
                options.Password,
                TimeSpan.FromSeconds(30),
                options.ServerAdapterType);
        }
        private async Task 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 calDavDataAccess = SynchronizerFactory.CreateCalDavDataAccess(
                    _calenderUrlTextBox.Text,
                    _userNameTextBox.Text,
                    _passwordTextBox.Text,
                    TimeSpan.Parse(ConfigurationManager.AppSettings["calDavConnectTimeout"]),
                    SelectedServerAdapterType);

                var cardDavDataAccess = SynchronizerFactory.CreateCardDavDataAccess(
                    _calenderUrlTextBox.Text,
                    _userNameTextBox.Text,
                    _passwordTextBox.Text,
                    TimeSpan.Parse(ConfigurationManager.AppSettings["calDavConnectTimeout"]),
                    SelectedServerAdapterType);

                var isCalendar = await calDavDataAccess.IsResourceCalender();

                var isAddressBook = await cardDavDataAccess.IsResourceAddressBook();

                if (!isCalendar && !isAddressBook)
                {
                    MessageBox.Show("The specified Url is neither a calendar nor an addressbook!", connectionTestCaption);
                    return;
                }

                if (isCalendar && isAddressBook)
                {
                    MessageBox.Show("Ressources which are a calendar and a addressbook are not valid!", connectionTestCaption);
                    return;
                }

                bool hasError = false;
                errorMessageBuilder.Clear();

                if (isCalendar)
                {
                    hasError = await TestCalendar(calDavDataAccess, errorMessageBuilder);
                }

                if (isAddressBook)
                {
                    hasError = await TestAddressBook(cardDavDataAccess, errorMessageBuilder);
                }

                if (hasError)
                {
                    MessageBox.Show("Connection test NOT successful:" + Environment.NewLine + errorMessageBuilder.ToString(), connectionTestCaption);
                }
                else
                {
                    MessageBox.Show("Connection test successful.", connectionTestCaption);
                }
            }
            catch (Exception x)
            {
                MessageBox.Show(x.Message, connectionTestCaption);
            }
        }