コード例 #1
0
        private async void JoinButton_Click(object sender, RoutedEventArgs e)
        {
            var parameters = myParameters;

            parameters.Password = MainPasswordBox.Password;

            if (!IsValid(parameters))
            {
                return;
            }

            EnableUI(false);

            SpreadsheetServiceClient spreadsheetServiceClient = null;
            JoinSessionResponse      response = null;
            string errorMessage;

            try
            {
                spreadsheetServiceClient = new SpreadsheetServiceClient();
                await spreadsheetServiceClient.Connect(parameters.Server);

                response = await spreadsheetServiceClient.JoinSession(parameters.SpreadsheetName, parameters.Password);

                errorMessage = response.ErrorMessage;
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
            }

            if (errorMessage == null)
            {
                new MainWindow(spreadsheetServiceClient, response).Show();
                Close();
            }
            else
            {
                spreadsheetServiceClient.Dispose();
                MessageBox.Show(this, "Unable to join the session:\r\n" + errorMessage, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
                EnableUI(true);
            }

            return;
        }
コード例 #2
0
        private async void CreateButton_Click(object sender, RoutedEventArgs e)
        {
            var parameters = myParameters;

            parameters.Password = MainPasswordBox.Password;

            if (!IsValid(parameters))
            {
                return;
            }

            EnableUI(false);

            CreateSessionResponse response;
            string errorMessage;

            try
            {
                using (var spreadsheetServiceClient = new SpreadsheetServiceClient())
                {
                    await spreadsheetServiceClient.Connect(parameters.Server);

                    response = await spreadsheetServiceClient.CreateSession(parameters.SpreadsheetName, parameters.Password);
                }
                errorMessage = response.ErrorMessage;
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
            }

            if (errorMessage == null)
            {
                MessageBox.Show(this, "Session created.", Title, MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                MessageBox.Show(this, "Unable to create a new session:\r\n" + errorMessage, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            EnableUI(true);

            return;
        }