示例#1
0
        private async void buttonSave_Click(object sender, RoutedEventArgs e)
        {
            var password             = textBoxPassword.Password;
            SyncConfiguration config = null;

            buttonSave.IsEnabled = false;
            buttonSave.Content   = "Please wait...";

            var stop = false;
            await Task.Run(() =>
            {
                try
                {
                    config = SharePointManager.TryFindConfiguration(_viewModel.SiteUrl, _viewModel.Username, password);
                }
                catch (Exception ex)
                {
                    stop = true;
                    Dispatcher.BeginInvoke(new Action(() =>
                    {
                        buttonSave.IsEnabled = true;
                        buttonSave.Content   = "Next";
                    }));
                    MessageBox.Show("An error occured:" + Environment.NewLine + ex.Message, "SPSync", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            });

            if (stop)
            {
                return;
            }

            if (config == null)
            {
                MessageBox.Show("We could not automatically find your configuration. Please use the advanced dialog to enter your configuration manually.", "SPSync", MessageBoxButton.OK, MessageBoxImage.Error);

                DialogResult = false;
                Close();

                var d = new EditConfWindow();
                d.ShowDialog(_viewModel);
                return;
            }

            if (config.DocumentLibrary.Contains("|"))
            {
                _viewModel.DocumentLibrary = config.DocumentLibrary;
                var selectWindow = new SelectDocumentLibraryWindow();
                var selectResult = selectWindow.ShowDialog(_viewModel);
                if (!selectResult.HasValue || !selectResult.Value)
                {
                    Dispatcher.Invoke(new Action(() =>
                    {
                        buttonSave.IsEnabled = true;
                        buttonSave.Content   = "Next";
                    }));
                    return;
                }
                config.DocumentLibrary = _viewModel.DocumentLibrary;
            }

            config.Name        = _viewModel.Name;
            config.LocalFolder = _viewModel.LocalFolder;

            App.MainViewModel.AddOrUpdateConfiguration(config);

            DialogResult = true;
            Close();

            new NewConfigFolderSelect(config).ShowDialog();
        }