/// <summary> /// Button Click Action, Connect and add a CRM Organization /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param> private void Button_Click(object sender, RoutedEventArgs e) { try { crmConnection = null; using (Core.Xrm.ToolingConnector toolingConnector = new Core.Xrm.ToolingConnector()) { CrmServiceClient crmServiceClient = toolingConnector.GetCrmServiceClient(tbx_connectionString.Text); if (crmServiceClient != null && crmServiceClient.IsReady) { this.crmConnection = new Core.Xrm.CrmConnection { ConnectionID = Guid.NewGuid(), ConnectionString = this.tbx_connectionString.Text, Name = crmServiceClient.ConnectedOrgFriendlyName }; this.tbx_connectionName.IsReadOnly = false; this.tbx_connectionName.Text = this.crmConnection.Name; this.tbx_connectionName.Text = this.crmConnection.Name; this.Lbl_ConnectionName.Visibility = Visibility.Visible; this.tbx_connectionName.Visibility = Visibility.Visible; btn_save.IsEnabled = true; } else { MessageBox.Show((string)Application.Current.FindResource("ConnectionManager_Code_UnableToOpenCRM"), (string)Application.Current.FindResource("ConnectionManager_Code_UnableToOpenCRM_Caption"), MessageBoxButton.OK, MessageBoxImage.Error); } } } catch (Exception ex) { if (!Properties.Settings.Default.DisableErrorReports) { Diagnostics.ErrorReport errorReport = new Diagnostics.ErrorReport(ex); errorReport.Show(); } ConnectionManger.Log.Error(ex.Message, ex); } }
/// <summary> /// Tests the Connection /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> private void Btn_TestConnection_Click(object sender, RoutedEventArgs e) { try { using (Core.Xrm.ToolingConnector toolingConnector = new Core.Xrm.ToolingConnector()) { if (toolingConnector.TestCRMConnection(Tbx_ConnectionString.Text)) { Btn_SaveConnection.IsEnabled = true; } else { MessageBox.Show("Unable to connect to CRM", "Connection Error", MessageBoxButton.OK, MessageBoxImage.Error); } } } catch (Exception ex) { MessageBox.Show("An exception occured while trying to test the CRM Connection : " + ex.Message, "An Exception occured", MessageBoxButton.OK, MessageBoxImage.Error); ConnectionOverview.Log.Error(ex.Message, ex); } }