private void buttonRequest_Click(object sender, System.EventArgs e) { Npgsql.Connector Connector = Npgsql.ConnectorPool.ConnectorPoolMgr.RequestConnector( this.textboxConnectionString.Text, this.checkboxShared.Checked ); this.ConnectorList.Add(Connector); this.listboxConnectors.Items.Add(this.ConnectorInfoString(Connector)); this.buttonRefreshPooledConnectors_Click(null, null); this.buttonRefreshSharedConnectors_Click(null, null); }
private void listboxConnectors_SelectedIndexChanged(object sender, System.EventArgs e) { int Index = this.listboxConnectors.SelectedIndex; if (Index == -1) { return; } Npgsql.Connector Connector = (Npgsql.Connector) this.ConnectorList[Index]; this.checkboxListPooled.Checked = Connector.Pooled; this.checkboxListShared.Checked = Connector.Shared; }
private void checkboxListPooled_Click(object sender, System.EventArgs e) { int Index = this.listboxConnectors.SelectedIndex; if (Index == -1) { return; } Npgsql.Connector Connector = (Npgsql.Connector) this.ConnectorList[Index]; Connector.Pooled = this.checkboxListPooled.Checked; // Reflect the changes in the Used Connectors Listbox this.listboxConnectors.Items.RemoveAt(Index); this.listboxConnectors.Items.Insert(Index, this.ConnectorInfoString(Connector)); this.listboxConnectors.SelectedIndex = Index; }
private void checkboxListShared_Click(object sender, System.EventArgs e) { int Index = this.listboxConnectors.SelectedIndex; if (Index == -1) { return; } Npgsql.Connector Connector = (Npgsql.Connector) this.ConnectorList[Index]; Connector.Shared = this.checkboxListShared.Checked; // Read back the value, changes might have been rejected... this.checkboxListShared.Checked = Connector.Shared; // Reflect the changes in the Used Connectors Listbox this.listboxConnectors.Text = this.ConnectorInfoString(Connector); }
private void buttonReleaseConnector_Click(object sender, System.EventArgs e) { int Index = this.listboxConnectors.SelectedIndex; if (Index == -1) { return; } Npgsql.Connector Connector = (Npgsql.Connector) this.ConnectorList[Index]; try { Connector.Release(); this.listboxConnectors.Items.RemoveAt(Index); this.ConnectorList.RemoveAt(Index); } finally { } this.buttonRefreshPooledConnectors_Click(null, null); this.buttonRefreshSharedConnectors_Click(null, null); }
private string ConnectorInfoString(Npgsql.Connector Connector) { // Formats the connector properties into a string representíon string Shared = "s"; if (Connector.Shared) { Shared = "S"; } string Pooled = "p"; if (Connector.Pooled) { Pooled = "P"; } return("[ " + Connector.InstanceNumber.ToString() + " ]" + "[ " + Pooled + " ]" + "[ " + Shared + " ]" + "[ " + Connector.ShareCount.ToString() + " ] " + Connector.ConnectString ); }
/// <summary> /// Searches the shared and pooled connector lists for a /// matching connector object or creates a new one. /// </summary> /// <param name="ConnectString">used to connect to the /// database server</param> /// <param name="Shared">Allows multiple connections /// on a single connector. </param> /// <returns>A pooled connector object.</returns> /// <status>test</status> /// <revised>06/20/2002</revised> <by>usp</by> internal Npgsql.Connector RequestConnector( string ConnectString, bool Shared) { // if a shared connector is requested then the Shared // Connector List is searched first: if (Shared) { foreach (Npgsql.Connector Connector in this.SharedConnectors) { if (Connector.ConnectString == ConnectString) { // Bingo! // Return the shared connector to caller. // The connector is already in use. Connector.mShareCount++; return(Connector); } } } // if a shared connector could not be found or a // nonshared connector is requested, then the pooled // (unused) connectors are beeing searched. foreach (Npgsql.Connector Connector in this.PooledConnectors) { if (Connector.ConnectString == ConnectString) { // Bingo! // Remove the Connector from the pooled connectors list. this.PooledConnectors.Remove(Connector); // Make the connector shared if requested if (Connector.Shared = Shared) { this.SharedConnectors.Add(Connector); Connector.mShareCount = 1; } // done... Connector.InUse = true; return(Connector); } } // No suitable connector found, so create new one Npgsql.Connector NewConnector = new Npgsql.Connector( ConnectString, Shared ); // Shared connections must be added to the shared // connectors list if (Shared) { this.SharedConnectors.Add(NewConnector); NewConnector.mShareCount = 1; } // and then returned to the caller NewConnector.InUse = true; NewConnector.Open(); return(NewConnector); }