private void btnLogin_Click(object sender, RoutedEventArgs e) { //Login and get all domains in XML format try { sapi.Login("http://usman-smappvw04.sncorp.smith-nephew.com:8080/qcbin", txtUsername.Text, txtPassword.Password); } catch (COMException) { MessageBox.Show("Login Failed. Check Username and Password!"); return; } string xmlDomains = sapi.GetAllDomains(); XDocument xml = XDocument.Parse(xmlDomains); IEnumerable <XElement> allDomains = xml.Root.Elements("TDXItem").Elements("DOMAIN_NAME"); //For each Xml domain element get just the value List <string> finalDomains = new List <string>(); foreach (XElement domain in allDomains) { finalDomains.Add(domain.Value); } //Set dropdown source and enable controls drpDomain.ItemsSource = finalDomains; drpDomain.IsEnabled = true; drpProject.IsEnabled = true; txtFileLocation.IsEnabled = true; btnBrowse.IsEnabled = true; btnClear.IsEnabled = true; lblLoginStatus.Content = "Logged in as " + txtUsername.Text; //disable login fields btnLogin.IsEnabled = false; txtUsername.IsEnabled = false; txtPassword.IsEnabled = false; }
public void connect() { disconnect(); saConnection = new SAapi(); saConnection.Login(url, admin, adminPassword); }
/// <summary> /// Authenticates the user from the providing server/login/password information /// </summary> /// <param name="sender">The sending object</param> /// <param name="e">The event arguments</param> private void btnAuthenticate_Click(object sender, System.EventArgs e) { //Disable the login and next button this.btnLogin.Enabled = false; this.btnNext.Enabled = false; //Make sure that a login was entered if (this.txtLogin.Text.Trim() == "") { MessageBox.Show("You need to enter a QualityCenter login", "Authentication Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } //Make sure that a server was entered if (this.txtServer.Text.Trim() == "") { MessageBox.Show("You need to enter a QualityCenter server name", "Authentication Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } try { //Instantiate the connection to QualityCenter TdConnection = new HP.QUalityCenter.TDConnection(); try { try { //The OTA API TdConnection.InitConnectionEx(this.txtServer.Text); TdConnection.Login(this.txtLogin.Text, this.txtPassword.Text); //The Site Admin API try { SaConnection = new SAapi(); SaConnection.Login(this.txtServer.Text, this.txtLogin.Text, this.txtPassword.Text); } catch (Exception) { //Unable to use the SiteAdmin API, so just leave NULL and don't use SaConnection = null; } } catch (Exception exception) { MessageBox.Show("Error Logging in to QualityCenter: " + exception.Message, "Authentication Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //Check to see if logged in and change the UI as appropriate if (TdConnection.LoggedIn) { MessageBox.Show("You have logged into Quality Center Successfully", "Authentication", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("That login/password combination was not valid for the instance of QualityCenter", "Authentication Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } //Now we need to populate the list of domains HP.QUalityCenter.List domainsOleList = TdConnection.VisibleDomains; ArrayList domainsList = new ArrayList(); //Convert into a standard bindable list source (OLEList index starts at 1) for (int i = 1; i <= domainsOleList.Count; i++) { domainsList.Add(domainsOleList[i]); } this.cboDomain.DataSource = domainsList; //Make sure we have at least one domain if (domainsList.Count >= 1) { //Reload the projects list ReloadProjects(); } } catch (COMException exception) { MessageBox.Show("Unable to access the HP QC API. Please make sure you that you have downloaded and installed the HP client components for HP QC (" + exception.Message + ")", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } catch (FileNotFoundException exception) { MessageBox.Show("Unable to access the HP QC API. Please make sure you that you have downloaded and installed the HP client components for HP QC (" + exception.Message + ")", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } catch (COMException exception) { MessageBox.Show("Unable to access the HP QC API. Please make sure you that you have downloaded and installed the HP client components for HP QC (" + exception.Message + ")", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } catch (FileNotFoundException exception) { MessageBox.Show("Unable to access the HP QC API. Please make sure you that you have downloaded and installed the HP client components for HP QC (" + exception.Message + ")", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } }