/// <summary> /// Initializes a new instance of the <see cref="TFSConnectionEditor"/> class. /// </summary> /// <param name="tfsConectionString">The TFS conection string.</param> /// <param name="isEdit">if set to <c>true</c> [is edit].</param> public TFSConnectionEditor(TFSConnectionString tfsConectionString, bool isEdit = false) : this() { tfsConectionString.Validate(); this.txtServerName.Text = tfsConectionString.ServerName; this.txtPortNumber.Text = tfsConectionString.PortNumber.ToString(CultureInfo.InvariantCulture); this.txtDefaultCollection.Text = tfsConectionString.DefaultCollection; this.rbtHttps.Checked = tfsConectionString.IsHttps; this.rbtHttp.Checked = !tfsConectionString.IsHttps; // Fix: 251237 if (isEdit) { this.txtServerName.ReadOnly = true; } }
/// <summary> /// Handles the SelectionChanged event of the dgvTFSsettings control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void DgvTFSsettings_SelectionChanged(object sender, EventArgs e) { if (this.dgvTFSsettings.SelectedRows.Count > 0) { this.selectedTFSConnectionString = new TFSConnectionString { ServerName = this.dgvTFSsettings.SelectedRows[0].Cells[0].Value.ToString(), PortNumber = int.Parse(this.dgvTFSsettings.SelectedRows[0].Cells[1].Value.ToString()), DefaultCollection = this.dgvTFSsettings.SelectedRows[0].Cells[2].Value.ToString(), IsHttps = bool.Parse(this.dgvTFSsettings.SelectedRows[0].Cells[3].Value.ToString()) }; } }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void BtnSave_Click(object sender, EventArgs e) { // This ensures proper values for database if (!this.IsValidTFSConfiguration()) { return; } // throw any kind of db error. Don't show here since this is a dialog. try { TFSConnectionString newtfsConnectionString = new TFSConnectionString { IsHttps = this.rbtHttps.Checked, ServerName = this.txtServerName.Text, PortNumber = int.Parse(this.txtPortNumber.Text), DefaultCollection = this.txtDefaultCollection.Text }; newtfsConnectionString.Validate(); newtfsConnectionString.SaveOrUpdateTFSConnectionStringToDB(!this.txtServerName.ReadOnly); this.Close(); } catch (InvalidOperationException ex) { ex.ShowUIException(); } catch (ArgumentException ex) { ex.ShowUIException(); } catch { new DBConcurrencyException("Unable to write changes to database. Unexpected error. Please try again.").ShowUIException(); } }
/// <summary> /// Gets the TFS connection string. /// </summary> /// <param name="tfsServerName">Name of the TFS server.</param> /// <returns>Looks up and returns TFS connectionstring from database</returns> public static TFSConnectionString GetTFSConnectionString(this string tfsServerName) { // Retrieve the connection string from the settings file. string conString = Properties.Settings.Default.DeploymentTrackerLocalDBConnectionString; TFSConnectionString connectionString = null; // Open the connection using the connection string. using (SqlCeConnection con = new SqlCeConnection(conString)) { con.Open(); using (SqlCeCommand com = new SqlCeCommand("SELECT servername, portnumber, defaultcollection, ishttps from TFSConnections where servername = @servername", con)) { com.Parameters.AddWithValue("@servername", tfsServerName); using (SqlCeDataReader reader = com.ExecuteReader()) { while (reader.Read()) { connectionString = new TFSConnectionString { ServerName = reader.GetString(0), PortNumber = reader.GetInt32(1), DefaultCollection = reader.GetString(2), IsHttps = bool.Parse(reader.GetString(3)) }; } } } return connectionString; } }