Ejemplo n.º 1
0
        private void backgroundWorker1_DoWork()
        {
            Thread.CurrentThread.Name = "Script Thread";

            try {
                while (dbList.Count > 0)
                {
                    currentDB = dbList[0];

                    Log("-----");
                    Log(currentDB.Database + " on " + currentDB.Server + " to " + currentDB.VssProjectParent + " in " + currentDB.VssIniFile);
                    try {
                        // Force a reconnection so that any recent changes are taken into account
                        if (Connect(currentDB.Server))
                        {
                            m_scriptEngine = new ScriptEngine(SqlServerSelection,
                                                              currentDB, toolStripStatusLabel1, toolStripStatusLabel2, localScriptPath.Text);
                            //m_scriptEngine.ScriptDone += new ScriptingHandler(ScriptAndCheckIn);
                        }
                    } catch (Exception ex) {
                        Log(ex.Message);
                        Log(ex.StackTrace);
                        throw;
                    }
                    dbList.RemoveAt(0);

                    if (m_scriptEngine != null)
                    {
                        m_scriptEngine.DatabaseName = currentDB.Database;
                        toolStripStatusLabel3.Text  = "DB = " + currentDB.Database;

                        // Start the time-consuming operation.
                        Log("Commencing the script of " + currentDB.Database + " on " + currentDB.Server);

                        m_scriptEngine.Script(ServerConn, scriptOnly);
                    }
                    else
                    {
                        Funcs.EmailReport("Database Scriptor Report", currentDB.Database + " on " + currentDB.Server + " has not been scripted.");
                    }
                }

                Maple.ApplicationStatus.SetStatus(Application.ProductName, "OK", "Finished", 1445);
            } catch (Exception ex) {
                Logger.LogError("DoWork", ex);
                Maple.ApplicationStatus.SetStatus(Application.ProductName, "Error", ex.Message, 10);
            }
        }
Ejemplo n.º 2
0
        // constructor
        public ScriptEngine(Server sqlserver, // sql server
                            dbClass currentDB,
                                              // root in VSS under which items are created
                            System.Windows.Forms.ToolStripLabel databasename,
                            System.Windows.Forms.ToolStripLabel objectname,
                            string localScriptPath
                            )
        {
            string vssRootPath = currentDB.VssProjectParent;

            m_vssDatabase = new VSSDatabaseClass();
            m_vssDatabase.Open(currentDB.VssIniFile, currentDB.VssLogin, currentDB.VssPw);

            m_sqlserver   = sqlserver;
            m_vssRootPath = vssRootPath;
            m_vssRoot     = m_vssDatabase.get_VSSItem(vssRootPath, false);

            m_workingFolder  = localScriptPath;
            m_workingFolder += "\\DBScriptManager";
            System.IO.Directory.CreateDirectory(m_workingFolder);
            dname = databasename; oname = objectname;
        }
Ejemplo n.º 3
0
        private void ScriptDBBtn_Click(object sender, EventArgs e)
        {
            if (ScriptDBBtn.Text == "Begin")
            {
                dbList.Clear();

                foreach (ListViewItem lvi in DBListView.Items)
                {
                    if (lvi.Checked)   // selected database
                    {
                        dbClass db = new dbClass();
                        db.Server           = ServerNamesComboBox.Text;
                        db.Database         = lvi.Text;
                        db.VssIniFile       = VSSIniPath.Text;
                        db.VssLogin         = VSSLoginTxt.Text;
                        db.VssPw            = VSSPwdTxt.Text;
                        db.VssProjectParent = VSSProjTxt.Text;
                        db.Server           = SqlServerSelection.Name;

                        dbList.Add(db);
                    }
                }

                if (dbList.Count > 0)
                {
                    scriptOnly = ScriptOnlyCheckbox.Checked;
                    tempPath   = localScriptPath.Text;

                    string ret = ScriptDBs();
                }
            }
            else
            {
                isCancelled = true;
                //backgroundWorker1.CancelAsync();
            }
        }
Ejemplo n.º 4
0
        public CNDBScript(string[] args)
        {
            bool run = true;

            InitializeComponent();
            DBListView.Columns.Add("Select Databases to script", DBListView.Width - 5, HorizontalAlignment.Left);
#if DEBUG
            if (MessageBox.Show("auto run?", "Debug", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No)
            {
                args = new string[0];
            }
#endif

            if (args.Length > 0)
            {
                // Should be the name of the file to process
                if (args.Length == 1)
                {
                    string file = args[0];
                    if (File.Exists(file))
                    {
                        exitWhenFinished = true;

                        // Read file in
                        string[] lines = File.ReadAllLines(file);
                        dbList = new List <dbClass>();

                        foreach (string line in lines)
                        {
                            if (line.Trim() != "" && !line.StartsWith("#"))
                            {
                                if (line.Trim().ToLower().Substring(0, 8) == "temppath")
                                {
                                    tempPath = line.Substring(line.IndexOf("=") + 1).Trim();
                                    if (!tempPath.EndsWith("\\"))
                                    {
                                        tempPath += "\\";
                                    }
                                }
                                else
                                {
                                    string[] fields = line.Split(new char[] { ',' });
                                    if (fields.Length == 5)
                                    {
                                        for (int i = 0; i < fields.Length; i++)
                                        {
                                            fields[i] = fields[i].Trim();
                                        }
                                        if (!fields[0].EndsWith("\\"))
                                        {
                                            fields[0] += "\\";
                                        }
                                        if (!fields[3].EndsWith("/"))
                                        {
                                            fields[3] += "/";
                                        }

                                        fields[0] += "srcsafe.ini";

                                        // Work through all database on that server
                                        List <string> databases = GetDatabaseNames(fields[4]);

                                        foreach (string database in databases)
                                        {
                                            dbClass db = new dbClass();
                                            db.VssIniFile = fields[0];
                                            db.VssLogin   = fields[1];
                                            db.VssPw      = fields[2];
                                            if (db.VssPw.Length > 1)
                                            {
                                                db.VssPw = db.VssPw.Substring(1);
                                            }
                                            db.VssProjectParent = fields[3];
                                            db.Server           = fields[4];
                                            db.Database         = database;

                                            dbList.Add(db);
                                        }
                                    }
                                    else
                                    {
                                        Log("Bad line found in control file. " + line);
                                    }
                                }
                            }
                        }
                        if (dbList.Count > 0)
                        {
                            timer1.Interval = 1000;
                            timer1.Enabled  = true;
                        }
                    }
                    else
                    {
                        run = false;
                    }
                }
            }
            if (!run)
            {
                Environment.Exit(1);
            }
        }