private void btnSave_Click(object sender, EventArgs e) { if (!ValidateDetails()) { this.DialogResult = DialogResult.None; return; } try { if (!SafelyGetText(txtURL).EndsWith(@"/")) { txtURL.Text = SafelyGetText(txtURL) + "/"; } string LDAPAuthenticationKey = SafelyGetText(txtLDAPAuthenticationKey); if (LDAPAuthenticationKey == string.Empty) { LDAPAuthenticationKey = null; } /* save settings before, and regardless of, test that login succeeds. * Otherwise in cases where login is impossible (e.g. network failure) * settings get lost. See bug #187 */ this.SaveSettings(); Globals.ThisAddIn.SuiteCRMUserSession = new SuiteCRMClient.UserSession( SafelyGetText(txtURL), SafelyGetText(txtUsername), SafelyGetText(txtPassword), LDAPAuthenticationKey, ThisAddIn.AddInTitle, Log, Properties.Settings.Default.RestTimeout); Globals.ThisAddIn.SuiteCRMUserSession.Login(); if (Globals.ThisAddIn.SuiteCRMUserSession.NotLoggedIn) { MessageBox.Show("Authentication failed!!!", "Authentication failed", MessageBoxButtons.OK, MessageBoxIcon.Error); this.DialogResult = DialogResult.None; return; } } catch (Exception ex) { Log.Warn("Unable to connect to SuiteCRM", ex); MessageBox.Show(ex.Message, "Unable to connect to SuiteCRM", MessageBoxButtons.OK, MessageBoxIcon.Error); this.DialogResult = DialogResult.None; return; } RestAPIWrapper.FlushUserIdCache(); base.Close(); this.SettingsChanged?.Invoke(this, EventArgs.Empty); }
private void btnSave_Click(object sender, EventArgs e) { if (!ValidateDetails()) { this.DialogResult = DialogResult.None; return; } try { using (WaitCursor.For(this)) { ErrorHandler.DoOrHandleError(() => CheckUrlChanged(), "checking whether CRM URL has changed"); /* save settings before, and regardless of, test that login succeeds. * Otherwise in cases where login is impossible (e.g. network failure) * settings get lost. See bug #187 */ ErrorHandler.DoOrHandleError(() => this.SaveSettings(), "saving settings"); Globals.ThisAddIn.Authenticate(); } if (Globals.ThisAddIn.SuiteCRMUserSession.NotLoggedIn) { MessageBox.Show("Authentication failed!", "Authentication failed", MessageBoxButtons.OK, MessageBoxIcon.Error); this.DialogResult = DialogResult.None; return; } } catch (Exception ex) { Log.Warn("Unable to connect to SuiteCRM", ex); MessageBox.Show(ex.Message, "Unable to connect to SuiteCRM", MessageBoxButtons.OK, MessageBoxIcon.Error); this.DialogResult = DialogResult.None; return; } RestAPIWrapper.FlushUserIdCache(); base.Close(); this.SettingsChanged?.Invoke(this, EventArgs.Empty); }