Ejemplo n.º 1
0
        static void export(string[] args)
        {
            // /export "target folder 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 {
                    ProviderName     = args[2].Replace("\"", ""),
                    ConnectionString = args[3].Replace("\"", ""),
                };

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


                // read table info from database
                Creator c = Creator.GetInstance(dsc);
                c.OnProgress += new ProgressEventHandler(c_OnProgress);
                updateProgress("Loading table information...");
                during = "loading table information";
                List <TableInfo> tables = c.LoadTableInfo(args[4], null, false, int.MaxValue);

                // save table schema to file
                c.SaveTableInfoToXml((folder + @"\__schema.xml").Replace(@"\\", @"\"), tables);

                // copy the data from the database
                during = "copying data";
                c.CopyDataFromDatabase(folder, args[4], tables);
                updateProgress("Done");
            } catch (Exception ex) {
                updateProgress("Error while " + during + ": " + ex.Message);
                //                MessageBox.Show("Error while " + during + ": " + ex.Message);
                throw;
            }
            __frmProgress.btnDone.Enabled = true;
            __frmProgress.Close();
            //while (__frmProgress.Visible) {
            //    Thread.Sleep(1000);
            //    Application.DoEvents();
            //}
        }
Ejemplo n.º 2
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();
            //}
        }