Browse Source

More WIP - updates to DbModelInfo, DbModelInfoService and ServerBrowserTool

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@1657 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Dickon Field 19 years ago
parent
commit
370fde9769
  1. 30
      src/AddIns/Misc/SharpDbTools/Project/Src/Model/DbModelInfo.cs
  2. 58
      src/AddIns/Misc/SharpDbTools/Project/Src/Model/DbModelInfoService.cs
  3. 93
      src/AddIns/Misc/SharpDbTools/Project/Src/ServerBrowserTool.cs

30
src/AddIns/Misc/SharpDbTools/Project/Src/Model/DbModelInfo.cs

@ -58,16 +58,34 @@ namespace SharpDbTools.Model @@ -58,16 +58,34 @@ namespace SharpDbTools.Model
}
}
public DbModelInfo(string name, string invariantName, string connectionString)
public DbModelInfo() : base()
{
}
public DbModelInfo(string name) : base()
{
DataTable table = CreateConnectionTable();
// add the first and only column of this table;
table.Rows.Add(new object[] {name, null, null});
}
public DbModelInfo(string name, string invariantName, string connectionString): base()
{
DataTable table = CreateConnectionTable();
// add the first and only column of this table;
table.Rows.Add(new object[] {name, invariantName, connectionString});
}
private DataTable CreateConnectionTable()
{
// create a table in the DbModelInfo to hold this initial info.
// this creates a consistent representation of the data and makes
// it easier to serialise it
DataTable table = this.Tables.Add("Connection");
table.Columns.Add("name", typeof(string));
table.Columns.Add("invariantName", typeof(string));
table.Columns.Add("connectionString", typeof(string));
DataTable table = this.Tables.Add(TableNames.ConnectionInfo);
table.Columns.Add(ColumnNames.Name, typeof(string));
table.Columns.Add(ColumnNames.InvariantName, typeof(string));
table.Columns.Add(ColumnNames.ConnectionString, typeof(string));
return table;
}
public DataTable MetaDataCollections {

58
src/AddIns/Misc/SharpDbTools/Project/Src/Model/DbModelInfoService.cs

@ -29,39 +29,31 @@ namespace SharpDbTools.Model @@ -29,39 +29,31 @@ namespace SharpDbTools.Model
/// - adding for new connection data (name, invariant name, connection string)
/// - saving to files
/// </summary>
public class DbModelInfoService
public static class DbModelInfoService
{
static DbModelInfoService instance = new DbModelInfoService();
static string saveLocation = null;
const string dbFilesDir = "DbTools";
const string dbFilesDir = "DbTools";
static SortedList<string, DbModelInfo> cache = new SortedList<string, DbModelInfo>();
SortedList<string, DbModelInfo> cache;
DbModelInfoService()
{
cache = new SortedList<string, DbModelInfo>();
}
public static DbModelInfoService GetInstance()
{
return instance;
}
public DbModelInfo Create(string name, string invariantName, string connectionString)
public static DbModelInfo Add(string name, string invariantName, string connectionString)
{
// TODO: add validation on name; invariant name
// assume that connection string is valid - if it fails an exception will be thrown later
// this allows partially defined connection strings at least to be saved and worked on later
DbModelInfo dbModel = new DbModelInfo(name, invariantName, connectionString);
// add to cache
cache.Add(name, dbModel);
return dbModel;
}
public DbModelInfo LoadFromConnection(string name)
public static DbModelInfo GetDbModelInfo(string name) {
DbModelInfo modelInfo = null;
bool exists = cache.TryGetValue(name, out modelInfo);
return modelInfo;
}
public static DbModelInfo LoadMetadataFromConnection(string name)
{
// get the DbModelInfo
@ -105,11 +97,11 @@ namespace SharpDbTools.Model @@ -105,11 +97,11 @@ namespace SharpDbTools.Model
return modelInfo;
}
public void Save(string name)
public static void SaveToFile(string name)
{
string path = GetSaveLocation();
DbModelInfo modelInfo = null;
this.cache.TryGetValue(name, out modelInfo);
cache.TryGetValue(name, out modelInfo);
if (modelInfo != null) {
string modelName = modelInfo.Name;
// write to a file in 'path' called <name>.metadata
@ -123,14 +115,32 @@ namespace SharpDbTools.Model @@ -123,14 +115,32 @@ namespace SharpDbTools.Model
string xml = modelInfo.GetXml();
sw.Write(xml);
sw.Flush();
sw.Close();
}
}
LoggingService.Debug("DbModelInfo with name: " + name + " not found");
}
public void LoadFromFiles()
public static void LoadFromFiles()
{
// load DbModelInfo's from file system
string saveLocation = GetSaveLocation();
string[] files = Directory.GetFiles(saveLocation);
cache.Clear();
for (int i = 0; i < files.Length; i++) {
DbModelInfo nextModel = LoadFromFile(@saveLocation + files[i]);
cache.Add(nextModel.Name, nextModel);
}
}
private static DbModelInfo LoadFromFile(string filePath)
{
// TODO: load DbModelInfo's from file system
StreamReader reader = File.OpenText(filePath);
string xml = reader.ReadToEnd();
reader.Close();
DbModelInfo nextModel = new DbModelInfo();
nextModel.ReadXml(xml);
return nextModel;
}
private static string GetSaveLocation()
@ -145,7 +155,5 @@ namespace SharpDbTools.Model @@ -145,7 +155,5 @@ namespace SharpDbTools.Model
}
return saveLocation;
}
}
}

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

@ -44,17 +44,7 @@ namespace SharpDbTools @@ -44,17 +44,7 @@ namespace SharpDbTools
// initialise browser tree
dbTree.BeginUpdate();
//dbTree.Tag = "Connections";
ContextMenuStrip cMenu = new ContextMenuStrip();
ToolStripMenuItem menuItem = new ToolStripMenuItem("Save");
cMenu.Items.AddRange(new ToolStripMenuItem[] {menuItem} );
TreeNode connection1 = new TreeNode("Test");
connection1.ContextMenuStrip = cMenu;
TreeNode[] childNodes = new TreeNode[1];
childNodes[0] = connection1;
TreeNode topNode = new TreeNode("Database Connections", childNodes);
DatabaseServerNode topNode = new DatabaseServerNode();
dbTree.Nodes.Add(topNode);
dbTree.EndUpdate();
@ -90,10 +80,67 @@ namespace SharpDbTools @@ -90,10 +80,67 @@ namespace SharpDbTools
/// <summary>
/// Hosts a list of ConnectionNodes corresponding to the available
/// DbModelInfo's
/// DbModelInfo's and supports the addition and deletion of
/// ConnectionNodes.
/// </summary>
class DatabaseServerNode : TreeNode
{
public DatabaseServerNode()
{
this.Text = "Database Connections";
ContextMenuStrip cMenu = new ContextMenuStrip();
ToolStripMenuItem addConnectionMenuItem =
new ToolStripMenuItem("Add Connection");
addConnectionMenuItem.Click += new EventHandler(AddConnectionClickHandler);
ToolStripMenuItem deleteConnectionMenuItem =
new ToolStripMenuItem("Delete Connection");
deleteConnectionMenuItem.Click += new EventHandler(DeleteConnectionClickHandler);
ToolStripMenuItem saveMetadataMenuItem =
new ToolStripMenuItem("Save All");
saveMetadataMenuItem.Click += new EventHandler(SaveMetadataClickHandler);
cMenu.Items.AddRange(new ToolStripMenuItem[]
{
addConnectionMenuItem,
deleteConnectionMenuItem,
saveMetadataMenuItem
}
);
this.ContextMenuStrip = cMenu;
}
/// <summary>
/// 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
/// Tree.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void AddConnectionClickHandler(object sender, EventArgs e)
{
LoggingService.Debug("add connection clicked");
// get the logical name of the new connection
// add a new DbModelInfo to the cache
// add a new Node below this one for the Connection
}
public void DeleteConnectionClickHandler(object sender, EventArgs e)
{
LoggingService.Debug("delete connection clicked");
}
public void SaveMetadataClickHandler(object sender, EventArgs e)
{
LoggingService.Debug("save all metadata clicked");
}
}
@ -103,7 +150,27 @@ class DatabaseServerNode : TreeNode @@ -103,7 +150,27 @@ class DatabaseServerNode : TreeNode
/// DbModelInfo and to host a list of MetadataNodes for the DbModelInfo
/// </summary>
class ConnectionNode : TreeNode
{
{
public ConnectionNode(string name)
{
this.Text = name;
this.Tag = name;
}
/// <summary>
/// Changes the logical name of this connection. This is just for the convenience
/// of the user: the connection properties and metadata can remain the same
/// but the DbModelInfoService needs to be notified to make changes to the cache
/// and file for its DbModelInfo.
/// </summary>
public void ChangeName() {}
/// <summary>
/// Uses the ConnectionStringDefinitionDialog to change the properties
/// of this connection.
/// Note that by doing this the metadata for the connection must be cleared.
/// </summary>
public void ChangeConnectionProperties() {}
}

Loading…
Cancel
Save