/// <summary> /// OnDragOver is used to inform OLE that the DiagramClientView associated with /// the current diagram is willing to accept the DSRef data format. Additionally, /// we enforce that only tables can be copied onto the diagram. We would /// normally do this in OnDragEnter as it's the appropriate event, but the /// DiagramClientView does not properly implement OnDragEnter by calling its /// base method (i.e. any event we wire up to DragEnter would never fire) /// </summary> private void OnDragOver(object sender, DragEventArgs e) { // Check if the data present is in the DSRef format if (e.Data.GetDataPresent(DSRefNavigator.DataSourceReferenceFormat)) { try { // Create a navigator for the DSRef Consumer (and dispose it when finished) using (DSRefNavigator navigator = new DSRefNavigator(e.Data.GetData( DSRefNavigator.DataSourceReferenceFormat) as Stream)) { // Only allow a copy if they selected table leaf nodes (we of // course don't set the Effect to None if not as the base classes // do their own drag/drop manipulation on other data formats) if (navigator.ContainsOnlyTables) { e.Effect = DragDropEffects.Copy; } } } catch { } } }
/// <summary> /// OnDragOver is used to inform OLE that the DiagramClientView associated with /// the current diagram is willing to accept the DSRef data format. Additionally, /// we enforce that only tables can be copied onto the diagram. We would /// normally do this in OnDragEnter as it's the appropriate event, but the /// DiagramClientView does not properly implement OnDragEnter by calling its /// base method (i.e. any event we wire up to DragEnter would never fire) /// </summary> private void OnDragOver(object sender, DragEventArgs e) { // Check if the data present is in the DSRef format if (e.Data.GetDataPresent(DSRefNavigator.DataSourceReferenceFormat)) { try { // Create a navigator for the DSRef Consumer (and dispose it when finished) using(DSRefNavigator navigator = new DSRefNavigator(e.Data.GetData( DSRefNavigator.DataSourceReferenceFormat) as Stream)) { // Only allow a copy if they selected table leaf nodes (we of // course don't set the Effect to None if not as the base classes // do their own drag/drop manipulation on other data formats) if (navigator.ContainsOnlyTables) { e.Effect = DragDropEffects.Copy; } } } catch { } } }
/// <summary> /// OnDragDrop is used to create classes corresponding to the selection dragged /// from the Server Explorer /// </summary> private void OnDragDrop(object sender, DragEventArgs e) { // Check if the data present is in the DSRef format if (e.Data.GetDataPresent(DSRefNavigator.DataSourceReferenceFormat)) { try { // Create a navigator for the DSRef Consumer (and dispose it when finished) using (DSRefNavigator navigator = new DSRefNavigator(e.Data.GetData( DSRefNavigator.DataSourceReferenceFormat) as Stream)) { _output = new OutputWindowHelper(DTEHelper.GetDTE(this.Store)); // Get connection info of the connection of selected tables string providerType = null; IDbConnection connection = ServerExplorerHelper.GetConnection(navigator, out providerType); IDbHelper helper; switch (providerType) { case "System.Data.SqlClient.SqlConnection": helper = new SqlHelper(connection); break; case "System.Data.OracleClient.OracleConnection": case "Oracle.DataAccess.Client.OracleConnection": Log("Selecting Oracle Helper for provider " + providerType); helper = new OracleHelper(connection); break; case "MySql.Data.MySqlClient.MySqlConnection": helper = new MySqlHelper(connection); break; default: // TODO: Support other databases with native providers. Log( string.Format( @"Failed: ActiveWriter does not support model generation through {0}. Supported providers: System.Data.SqlClient.SqlConnection, System.Data.OracleClient.OracleConnection, Oracle.DataAccess.Client.OracleConnection, MySql.Data.MySqlClient.MySqlConnection. You can help us improve this functionality, though. See http://www.castleproject.org/others/contrib/index.html to access ActiveWriter source code under the contrib repository, and check Dsl\ServerExplorerSupport\IDbHelper.cs for the start.", providerType)); return; } // Get the root element where we'll add the classes Model model = Helper.GetModel(this.Store); if (model == null) { Log("Failed: Cannot get the model for the store."); return; } _manager = new DiagramManager(this.Store, model); _manager.OutputWindow = _output; // Create a transaction to add the clases. using (Transaction txAdd = model.Store.TransactionManager.BeginTransaction("Add classes")) { List <DSRefNode> tableList = new List <DSRefNode>(); // Get the tables from the Server Explorer selection // We'll iterate this list twice to use nodes' list to // determine if we have to generate relations for each // table or not. foreach (DSRefNode node in navigator.ChildTableNodes) { tableList.Add(node); } _manager.Tables = tableList; _relations = new List <Relation>(); foreach (DSRefNode node in tableList) { // Create the table and add it to the model ModelClass cls = _manager.NewClass(node.Owner, node.Name); PopulateClass(cls, connection, helper); _manager.AssignModel(cls); } // Create relations if (_relations != null && _relations.Count > 0) { HandleRelations(); } // Commit the transaction and add tables to the model txAdd.Commit(); } // TODO: Auto layout doesn't work well. Will check with future versions of DSL tools. // this.AutoLayoutShapeElements(this.NestedChildShapes); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } finally { _manager = null; _relations = null; _output = null; } } }
/// <summary> /// OnDragDrop is used to create classes corresponding to the selection dragged /// from the Server Explorer /// </summary> private void OnDragDrop(object sender, DragEventArgs e) { // Check if the data present is in the DSRef format if (e.Data.GetDataPresent(DSRefNavigator.DataSourceReferenceFormat)) { try { // Create a navigator for the DSRef Consumer (and dispose it when finished) using(DSRefNavigator navigator = new DSRefNavigator(e.Data.GetData( DSRefNavigator.DataSourceReferenceFormat) as Stream)) { _output = new OutputWindowHelper(DTEHelper.GetDTE(Store)); // Get connection info of the connection of selected tables string providerType = null; IDbConnection connection = ServerExplorerHelper.GetConnection(navigator, out providerType); IDbHelper helper; switch(providerType) { case "System.Data.SqlClient.SqlConnection": helper = new SqlHelper(connection); break; case "System.Data.OracleClient.OracleConnection": case "Oracle.DataAccess.Client.OracleConnection": Log("Selecting Oracle Helper for provider " + providerType); helper = new OracleHelper(connection); break; case "MySql.Data.MySqlClient.MySqlConnection": helper = new MySqlHelper(connection); break; default: // TODO: Support other databases with native providers. Log( string.Format( @"Failed: ActiveWriter does not support model generation through {0}. Supported providers: System.Data.SqlClient.SqlConnection, System.Data.OracleClient.OracleConnection, Oracle.DataAccess.Client.OracleConnection, MySql.Data.MySqlClient.MySqlConnection. You can help us improve this functionality, though. See http://www.castleproject.org/others/contrib/index.html to access ActiveWriter source code under the contrib repository, and check Dsl\ServerExplorerSupport\IDbHelper.cs for the start.", providerType)); return; } // Get the root element where we'll add the classes Model model = Helper.GetModel(Store); if (model == null) { Log("Failed: Cannot get the model for the store."); return; } _manager = new DiagramManager(Store, model); _manager.OutputWindow = _output; // Create a transaction to add the clases. using(Transaction txAdd = model.Store.TransactionManager.BeginTransaction("Add classes")) { List<DSRefNode> tableList = new List<DSRefNode>(); // Get the tables from the Server Explorer selection // We'll iterate this list twice to use nodes' list to // determine if we have to generate relations for each // table or not. foreach(DSRefNode node in navigator.ChildTableNodes) { tableList.Add(node); } _manager.Tables = tableList; _relations = new List<Relation>(); foreach(DSRefNode node in tableList) { // Create the table and add it to the model ModelClass cls = _manager.NewClass(node.Owner, node.Name); PopulateClass(cls, connection, helper); _manager.AssignModel(cls); } // Create relations if (_relations != null && _relations.Count > 0) { HandleRelations(); } // Commit the transaction and add tables to the model txAdd.Commit(); } // TODO: Auto layout doesn't work well. Will check with future versions of DSL tools. // this.AutoLayoutShapeElements(this.NestedChildShapes); } } catch(Exception ex) { Debug.WriteLine(ex.Message); } finally { _manager = null; _relations = null; _output = null; } } }