Browse Source

additions to ServerBrowserTool and updates to ConnectionStringDefinitionDialog to modified connection string associated with a database connection

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1681 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Dickon Field 20 years ago
parent
commit
3ea7fcaf12
  1. 21
      src/AddIns/Misc/SharpDbTools/Project/Src/Connection/ConnectionStringDefinitionDialog.cs
  2. 77
      src/AddIns/Misc/SharpDbTools/Project/Src/ServerBrowserTool.cs

21
src/AddIns/Misc/SharpDbTools/Project/Src/Connection/ConnectionStringDefinitionDialog.cs

@ -30,6 +30,7 @@ namespace SharpDbTools.Connection
ToolStripProgressBar connectionTestProgressBar = new ToolStripProgressBar(); ToolStripProgressBar connectionTestProgressBar = new ToolStripProgressBar();
ConnectionTestBackgroundWorker testConnectionBackgroundWorker; ConnectionTestBackgroundWorker testConnectionBackgroundWorker;
string resultMessage; string resultMessage;
ConnectionTestState connectionTestState = ConnectionTestState.UnTested;
public ConnectionStringDefinitionDialog() public ConnectionStringDefinitionDialog()
{ {
@ -46,6 +47,12 @@ namespace SharpDbTools.Connection
this.connectionTestProgressBar.Maximum = 150; this.connectionTestProgressBar.Maximum = 150;
} }
public ConnectionTestState ConnectionTestState {
get {
return this.connectionTestState;
}
}
public string ResultMessage public string ResultMessage
{ {
get get
@ -90,6 +97,7 @@ namespace SharpDbTools.Connection
void CancelButtonClick(object sender, System.EventArgs e) void CancelButtonClick(object sender, System.EventArgs e)
{ {
this.DialogResult = DialogResult.Cancel;
this.Close(); this.Close();
} }
@ -143,7 +151,8 @@ namespace SharpDbTools.Connection
void ResetTestResultTextBox() void ResetTestResultTextBox()
{ {
this.testResultTextBox.Text = ""; this.testResultTextBox.Text = "";
this.connectionTestState = ConnectionTestState.UnTested;
} }
void TestConnectionBackgroundWorkerDoWork(object sender, DoWorkEventArgs e) void TestConnectionBackgroundWorkerDoWork(object sender, DoWorkEventArgs e)
@ -168,10 +177,12 @@ namespace SharpDbTools.Connection
connection.Open(); connection.Open();
e.Result = "Connection Succeeded"; e.Result = "Connection Succeeded";
connectionTestState = ConnectionTestState.TestSucceeded;
} }
catch(Exception ex) catch(Exception ex)
{ {
e.Result = "Connection Failed: " + ex.Message; e.Result = "Connection Failed: " + ex.Message;
connectionTestState = ConnectionTestState.TestFailed;
} }
finally finally
{ {
@ -198,10 +209,18 @@ namespace SharpDbTools.Connection
void SubmitButtonClick(object sender, System.EventArgs e) void SubmitButtonClick(object sender, System.EventArgs e)
{ {
this.DialogResult = DialogResult.OK;
this.Close(); this.Close();
} }
} }
public enum ConnectionTestState
{
UnTested,
TestFailed,
TestSucceeded
}
class ConnectionTestBackgroundWorker: BackgroundWorker class ConnectionTestBackgroundWorker: BackgroundWorker
{ {
private string dbTypeName; private string dbTypeName;

77
src/AddIns/Misc/SharpDbTools/Project/Src/ServerBrowserTool.cs

@ -16,6 +16,7 @@ using System.Windows.Forms;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
using SharpDbTools.Model; using SharpDbTools.Model;
using SharpDbTools.Connection;
namespace SharpDbTools namespace SharpDbTools
{ {
@ -113,17 +114,35 @@ namespace SharpDbTools
/// Rebuilds the database connection tree. /// Rebuilds the database connection tree.
/// Should only be called from a delegate via Invoke or BeginInvoke. /// Should only be called from a delegate via Invoke or BeginInvoke.
/// </summary> /// </summary>
public void RebuildDbConnectionNode() public void RebuildDbConnectionsNode()
{ {
// Rebuild each of the root nodes in the ServerToolTreeView // Rebuild each of the root nodes in the ServerToolTreeView
this.BeginUpdate(); this.BeginUpdate();
dbNode.Nodes.Clear(); dbNode.Nodes.Clear();
foreach (string name in DbModelInfoService.Names) { foreach (string name in DbModelInfoService.Names) {
dbNode.Nodes.Add(new TreeNode(name)); TreeNode dbModelInfoNode = CreateDbModelInfoNode(name);
dbNode.Nodes.Add(dbModelInfoNode);
} }
this.EndUpdate(); this.EndUpdate();
} }
public TreeNode CreateDbModelInfoNode(string name)
{
TreeNode treeNode = new TreeNode(name);
// create and add the menustrip for this node
DbModelInfoContextMenuStrip cMenu = new DbModelInfoContextMenuStrip(treeNode);
ToolStripMenuItem setConnectionStringMenuItem =
new ToolStripMenuItem("Set Connection String");
setConnectionStringMenuItem.Click += new EventHandler(SetConnectionStringOnDbModelInfoClickHandler);
cMenu.Items.AddRange(new ToolStripMenuItem[]
{
setConnectionStringMenuItem
});
treeNode.ContextMenuStrip = cMenu;
return treeNode;
}
/// <summary> /// <summary>
/// Uses a dialog to get the logical name of a new Connection then /// Uses a dialog to get the logical name of a new Connection then
/// adds a new DbModelInfo for it to the cache and updates the DatabaseServer /// adds a new DbModelInfo for it to the cache and updates the DatabaseServer
@ -149,7 +168,7 @@ namespace SharpDbTools
DbModelInfoService.Add(logicalName, null, null); DbModelInfoService.Add(logicalName, null, null);
// rebuild the database server node // rebuild the database server node
this.BeginInvoke(new MethodInvoker(this.RebuildDbConnectionNode)); this.BeginInvoke(new MethodInvoker(this.RebuildDbConnectionsNode));
} }
public void DeleteDbConnectionClickHandler(object sender, EventArgs e) public void DeleteDbConnectionClickHandler(object sender, EventArgs e)
@ -160,9 +179,57 @@ namespace SharpDbTools
public void SaveDbModelInfoClickHandler(object sender, EventArgs e) public void SaveDbModelInfoClickHandler(object sender, EventArgs e)
{ {
LoggingService.Debug("save all metadata clicked"); LoggingService.Debug("save all metadata clicked");
} }
public void SetConnectionStringOnDbModelInfoClickHandler(object sender, EventArgs e)
{
ToolStripMenuItem menuItem = sender as ToolStripMenuItem;
DbModelInfoContextMenuStrip toolStrip = menuItem.Owner as DbModelInfoContextMenuStrip;
TreeNode node = toolStrip.TreeNode;
string connectionLogicalName = node.Text;
LoggingService.Debug("add connection string clicked for item with name: " + node.Text);
// use the ConnectionStringDefinitionDialog to get a connection string and invariant name
ConnectionStringDefinitionDialog definitionDialog = new ConnectionStringDefinitionDialog();
DialogResult result = definitionDialog.ShowDialog();
// if the dialog was submitted and connection string has changed then clear the DbModelInfo metadata
// note that is is not required for the Connection string to be valid - it may be work
// in progress and a user might want to save a partially formed connection string
if (result == DialogResult.OK) {
DbModelInfo dbModelInfo = DbModelInfoService.GetDbModelInfo(connectionLogicalName);
string connectionString = dbModelInfo.ConnectionString;
string newConnectionString = definitionDialog.ConnectionString;
if (connectionString == null && newConnectionString != null) {
//dbModelInfo.ConnectionString = newConnectionString;
//dbModelInfo.InvariantName = // TODO: START HERE sort out invariant name
} //else
}
// if the dialog was cancelled then do nothing
}
} }
class DbModelInfoContextMenuStrip : ContextMenuStrip
{
TreeNode treeNodeAttached;
public DbModelInfoContextMenuStrip(TreeNode treeNodeAttached) : base()
{
this.treeNodeAttached = treeNodeAttached;
}
public TreeNode TreeNode {
get {
return treeNodeAttached;
}
}
}
} }

Loading…
Cancel
Save