private void doImport(String filename, Int32 index) { switch (index) { case 1: // Scenario Files (*.xml)|*.xml importTool = new ImportTool(); importTool.PutTypeInName = false; importTool.PutNameInDescription = false; // Dtermine the correct adapter to load. XmlDocument document = new XmlDocument(); document.Load(filename); AME.Adapters.IImportAdapter adapter = null; String schema = document.DocumentElement.GetAttribute("noNamespaceSchemaLocation", "http://www.w3.org/2001/XMLSchema-instance"); switch (schema) { case "DDDSchema_4_1.xsd": adapter = new Adapters.DDD4_1_Importer(vsgController); break; case "DDDSchema_4_1_1.xsd": adapter = new Adapters.DDD4_1_Importer(vsgController); break; case "DDDSchema_4_0_2.xsd": adapter = new Adapters.DDD4_0_2_Importer(vsgController); break; case "DDDSchema_4_2.xsd": adapter = new Adapters.DDD4_2_Importer(vsgController); break; default: adapter = new Adapters.DDD4_0_Importer(vsgController); break; } //document.Schemas. //Adapters.DDD4_0_Importer ddd4_0_Schema = new Adapters.DDD4_0_Importer(); importSuccess = importTool.Import(vsgController, adapter, filename, this, true); if (importSuccess) { // Wait for import to finish. // It will send a component update which will enable this back. this.Enabled = false; scenarioFilename = filename; } break; case 2: // Raw Scenario Files //// The following commented out code is for imported dumped mysql //try //{ // vsgController.ImportSql(filename); // ComponentOptions compOptions = new ComponentOptions(); // compOptions.LevelDown = 1; // IXPathNavigable iNav = projectController.GetRootComponents(compOptions); // XPathNavigator nav = iNav.CreateNavigator(); // if (nav != null) // { // XPathNavigator navScenario = nav.SelectSingleNode(String.Format("Components/Component[@Type='{0}']", projectController.RootComponentType)); // if (navScenario != null) // { // String id = navScenario.GetAttribute("ID", navScenario.NamespaceURI); // openScenario(Int32.Parse(id)); // need to do this better; // } // } //} //catch (Exception e) //{ // MessageBox.Show(e.Message, "Export error"); //} try { vsgController.DropDatabase(); SQLDMO.SQLServer2 sqlServer = new SQLDMO.SQLServer2Class(); sqlServer.Connect(server, username, password); SQLDMO.Restore2 restore = new SQLDMO.Restore2Class(); restore.Devices = restore.Files; restore.Files = "[" + filename + "]"; restore.Database = database; restore.ReplaceDatabase = true; restore.SQLRestore(sqlServer); ComponentOptions compOptions = new ComponentOptions(); compOptions.LevelDown = 1; IXPathNavigable iNav = projectController.GetRootComponents(compOptions); XPathNavigator nav = iNav.CreateNavigator(); if (nav != null) { XPathNavigator navScenario = nav.SelectSingleNode(String.Format("Components/Component[@Type='{0}']", projectController.RootComponentType)); if (navScenario != null) { String id = navScenario.GetAttribute("ID", navScenario.NamespaceURI); openScenario(Int32.Parse(id)); // need to do this better; scenarioFilename = filename; this.Text = "Visual Scenario Generator - " + scenarioFilename; } } } catch (Exception e) { MessageBox.Show(e.Message, "Import error"); } break; } }
public int EndBulkOperations(Boolean clearDatabase, Boolean showDialog, String title, String message) { int returnID = -1; if (idCounter > 0 || linksPresent || parametersPresent) { ImportTool importTool = new ImportTool(); importTool.PutTypeInName = false; importTool.PutNameInDescription = false; Form importForm = Application.OpenForms[0]; // MW may need to fix this, this Form invokes the Dialog waitingForUpdate = true; signaled = false; bool importSuccess = importTool.Import(Controller, iDoc, this, importForm, clearDatabase, showDialog, title, message); while (waitingForUpdate) // pump the import and wait for controller to send UpdateViewComponent - will set updating to false { Application.DoEvents(); if (showDialog) { Thread.Sleep(1); } else { if (!signaled) // if already signaled, but waitingForUpdate is still true, don't wait again { ev.WaitOne(); } else { Thread.Sleep(1); } } } returnID = importTool.RootId; importTool = null; } IController thisConfig = AMEManager.Instance.Get(configurationName); thisConfig.UnregisterForUpdate(this); return returnID; }