Exemplo n.º 1
0
        private void btnImportData_Click(object sender, EventArgs e)
        {
            Creator c = Creator.GetInstance(new DataConnectionSpec {
                ConnectionString = txtImportToConnectionString.Text, ProviderName = getImportToProviderName(), CommandTimeout = COMMAND_TIMEOUT
            });

            // an import is really a csv parse, dump the data to a dataset in xml,
            // then look up table info and do a normal 'copy' of data

            string tgtDir = Directory.GetParent(txtImportFromFile.Text).FullName;

            DataTable dt = dgvImportTo.DataSource as DataTable;

            if (dt.DataSet == null)
            {
                DataSet ds = new DataSet();
                ds.Tables.Add(dt);
            }
            dt.TableName = ddlImportToTable.Text;
            dt.DataSet.WriteXml(tgtDir + "\\" + ddlImportToTable.Text + "_0.xml", XmlWriteMode.WriteSchema);


            List <string>    tableNames = c.ListTableNames(null);
            List <TableInfo> tables     = c.LoadTableInfo(tgtDir);

            c.CopyDataToDatabase(tgtDir, null, tables);
        }
Exemplo n.º 2
0
        private void btnCopyDataTo_Click(object sender, EventArgs e)
        {
            clearWorker();

            List <string> tableNames = new List <string>();

            foreach (ListViewItem lvi in lvTablesTo.CheckedItems)
            {
                tableNames.Add(lvi.Text);
            }


            backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);
            backgroundWorker1.DoWork          += new DoWorkEventHandler(delegate(object sender2, DoWorkEventArgs evt) {
                _timer    = new HighPrecisionTimer("timer", true);
                Creator c = Creator.GetInstance(new DataConnectionSpec {
                    ConnectionString = txtConnectionStringTo.Text, ProviderName = getToProviderName(), CommandTimeout = COMMAND_TIMEOUT
                });
                c.OnProgress += new ProgressEventHandler(c_OnProgress);

                List <TableInfo> tables = c.LoadTableInfo(txtSourceFolder.Text);
                c.CopyDataToDatabase(txtSourceFolder.Text, null, tables);
            });
            backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);
            backgroundWorker1.RunWorkerAsync();
        }
Exemplo n.º 3
0
        private void btnActionWriteDataGo_Click(object sender, EventArgs e)
        {
            if (rbActionWriteDatabaseData.Checked)
            {
                if (rbToIsDatabase.Checked && (rbFromIsCSV.Checked || rbFromIsDatabase.Checked))
                {
                    MessageBox.Show("Copying data is only allowed from a database to xml file(s), or from xml file(s) to a database.\n");
                    return;
                }

                Creator c = rbFromIsDatabase.Checked ? getFromCreator() : getToCreator(true);
                if (c == null)
                {
                    return;
                }
                // first make sure checkboxes line up with our 'selected' tables
                selectTables();

                background((sentBy, args) => {
                    if (rbFromIsDatabase.Checked)
                    {
                        // copy from database to xml
                        string toFolder = Toolkit.ResolveDirectoryPath(txtToFolderName.Text, true);
                        c.CopyDataFromDatabase(toFolder, txtFromDatabaseName.Text, _tables);
                    }
                    else
                    {
                        // copy from xml to database
                        string fromFolder = new FileInfo(Toolkit.ResolveFilePath(txtFromFileName.Text, false)).DirectoryName;
                        c.CopyDataToDatabase(fromFolder, txtToDatabaseName.Text, _tables, false, false);
                    }
                });
            }
            else if (rbActionWriteMappingData.Checked)
            {
                MessageBox.Show("Dataview data cannot be saved to file.  It must be written directly to a target database.");
                return;
                //Creator c = getToCreator(true);

                //int selectedCount = selectTables();
                //background((sentBy, args) => {

                //    if (rbToIsDatabase.Checked) {
                //        int i = 0;
                //        foreach (TableInfo ti in _tables) {
                //            if (ti.IsSelected) {
                //                i++;
                //                showProgress("Mapping dataview for table " + ti.TableName + "... ", i, selectedCount);
                //                c.CreateDataviewMappings(ti, _tables);
                //            }
                //        }
                //    } else {

                //        // copy sys_* table info to file



                //    }
//				});
            }
            else
            {
                throw new NotImplementedException("Change code here.  btnActionWriteDataGo_Click");
            }
        }
Exemplo n.º 4
0
        static void import(string[] args)
        {
            // /import "c:\cabfile_here" "provider_name_here" "connection_string_here" db_name_here
            string folder = args[1].Replace("\"", "");

            string during = "Connecting to database";

            try {
                // parse the dsc into a DataConnectionSpec object

                DataConnectionSpec dsc = new DataConnectionSpec(args[2].Replace("\"", ""), args[3].Replace("\"", ""));
                if (String.IsNullOrEmpty(dsc.DatabaseName))
                {
                    dsc.DatabaseName = args[4];
                }


                __frmProgress = new frmProgress();
                __frmProgress.Show();
                __frmProgress.Text = "Importing Data to " + args[4] + " Database...";


                updateProgress("Expanding source data files...");
                string targetDir = Toolkit.ResolveDirectoryPath(@".\", false);

                if (args[1].ToLower().EndsWith(".cab"))
                {
                    // they gave us a cab file. extract it, plow into local folder
                    Utility.ExtractCabFile(args[1].Replace(@"""", ""), targetDir, null);
                }
                else
                {
                    // they gave us a folder. mark that as our target dir.
                    targetDir = args[1].Replace(@"""", "");
                }
                //                        Utility.Unzip(args[1].Replace("\"", ""), targetDir);


                // read table info from the given folder\__schema.xml file
                Creator c = Creator.GetInstance(dsc);
                c.OnProgress += new ProgressEventHandler(c_OnProgress);
                during        = "loading table information";
                List <TableInfo> tables = c.LoadTableInfo(targetDir);

                // create tables in the database
                during = "creating tables";
                c.CreateTables(tables, args[4]);

                // copy the data to the database
                during = "copying data";
                c.CopyDataToDatabase(targetDir, args[4].Replace("\"", ""), tables, false, false);

                // create the indexes
                during = "creating indexes";
                foreach (TableInfo ti in tables)
                {
                    ti.IsSelected = true;
                }
                c.CreateIndexes(tables);

                // create the constraints
                during = "creating constraints";
                foreach (TableInfo ti in tables)
                {
                    ti.IsSelected = true;
                }
                c.CreateConstraints(tables, true, true);

                // get all the sequences up to snuff so new inserts work properly (i.e. make sure sequence id's are past the last one currently in each table)
                var dbUtil = DatabaseEngineUtil.CreateInstance(args[2].Replace("\"", ""), null, args[3].Replace("\"", ""));

                if (dsc.ProviderName.ToLower() == "oracle")
                {
                    during = "restarting sequences";
                    foreach (var t in tables)
                    {
                        updateProgress("restarting sequence for " + t.TableName + "...");
                        var ret = ((OracleEngineUtil)dbUtil).RestartSequenceForTable(dsc.Password, dsc.UserName, dsc.Password, t.TableName, t.PrimaryKey.Name);
                        updateProgress(ret);
                    }
                }
                else if (dsc.ProviderName.ToLower() == "postgresql")
                {
                    during = "restarting sequences";
                    foreach (var t in tables)
                    {
                        updateProgress("restarting sequence for " + t.TableName + "...");
                        var ret = ((PostgreSqlEngineUtil)dbUtil).RestartSequenceForTable(dsc.Password, dsc.DatabaseName, dsc.ServerName, t.TableName, t.PrimaryKey.Name);
                        updateProgress(ret);
                    }
                }
                else if (dsc.ProviderName.ToLower() == "mysql")
                {
                    c.RebuildIndexes(tables);
                }
            } catch (Exception ex) {
                updateProgress("Error while " + during + ": " + ex.Message);
                throw;
            }
            __frmProgress.btnDone.Enabled = true;
            __frmProgress.Close();
            //while (__frmProgress.Visible) {
            //    Thread.Sleep(1000);
            //    Application.DoEvents();
            //}
        }
Exemplo n.º 5
0
        private void btnActionScriptGo_Click(object sender, EventArgs e)
        {
            //if ((chkScriptMigrationInserts.Checked && !rbFromIsCSV.Checked) || txtToMigrateFromDatabaseName.Text == "" || txtToMigrateToDatabaseName.Text == "") {
            //    MessageBox.Show("When generating migration scripts, you must specify a csv file as the input source.\nFrom and To Migration database names must also be given.");
            //    return;
            //}


            Creator c = getToCreator(true);

            if (c == null)
            {
                return;
            }

            var updatedByCooperatorID = c.GetSystemCooperatorID();

            // first make sure checkboxes line up with our 'selected' tables
            selectTables();

            // make sure we import things in the proper order :-)
            // _tables = TableInfoComparer.SortByDependencies(_tables);

            background((sentBy, args) => {
                StringBuilder sb = new StringBuilder();

                sb.AppendLine("/************************************************************************/");
                sb.AppendLine("/************************************************************************/");
                sb.AppendLine("/*** This script can be recreated using GrinGlobal.DatabaseCopier.exe ***/");
                sb.AppendLine("/************************************************************************/");
                sb.AppendLine("/************************************************************************/");

                Dictionary <string, string> originalEngines = new Dictionary <string, string>();


                foreach (TableInfo ti in _tables)
                {
                    ti.SchemaName = txtToDatabaseName.Text;
                }

                if (chkScriptCreateTables.Checked)
                {
                    sb.Append(c.ScriptTables(_tables));
                }
                if (chkScriptLoadData.Checked)
                {
                    // generate all necessary LOAD DATA INFILE statements
                    var folder = Toolkit.ResolveParentDirectoryPath(txtFromFileName.Text, false);
                    sb.Append(c.CopyDataToDatabase(folder, txtToDatabaseName.Text, _tables, true, chkScriptOnlyRequiredData.Checked));
                }
                if (chkScriptCreateIndexes.Checked)
                {
                    sb.Append(c.ScriptIndexes(_tables));
                }
                if (chkScriptCreateConstraints.Checked)
                {
                    sb.Append(c.ScriptConstraints(_tables));
                }


                string ret = "SCHEMA: " + sb.ToString();
                showProgress(ret);
            });
        }