예제 #1
0
        public void Script(ServerConnection ServerConn, bool scriptOnly)
        {
            try
            {
                serverName = ServerConn.ServerInstance;
                serverConn = ServerConn;

                if (m_dbName == null)
                {
                    return;                     // there is no DB to script
                }
                foreach (Database db in m_sqlserver.Databases)
                {
                    if (m_dbName.ToLower() == db.Name.ToLower())
                    {
                        string dest = m_workingFolder + "\\" + m_sqlserver.Name + "\\" + db.Name;
                        if (Directory.Exists(dest))
                        {
                            DeleteDirectory(dest);
                        }

                        System.IO.Directory.CreateDirectory(m_workingFolder);

                        if (scriptOnly == false)
                        {
                            CheckoutFromSourcesafe(db, dest);
                        }

                        ScriptDatabase(db, dest);

                        if (errorsOccurred == false)
                        {
                            if (scriptOnly == false)
                            {
                                AddToSourcesafe(db, dest);

                                // The sourcesafe bit above removes each file but we still need to kill the folder.
                                DeleteDirectory(m_workingFolder);
                            }
                        }
                        break;
                    }
                }
                if (errorsOccurred)
                {
                    string logFile = Maple.Logger.GetLogFilePathAndName(true);

                    Funcs.EmailReport("DB script error",
                                      string.Format("See the log file for more info\r\n\r\n {0}", logFile));
                    ApplicationStatus.SetStatus(string.Format("Scripting of {0}.{1}.", serverName, m_dbName), "Error", "An error occurred", 1450);
                }
                else
                {
                    ApplicationStatus.SetStatus(string.Format("Scripting of {0}.{1}.", serverName, m_dbName), "OK", "", 1450);
                }
            }
            catch (Exception ex) {            //end up here in case of abort
                throw ex;
            }
            if (ScriptDone != null)
            {
                ScriptDone(scriptOnly);
            }
        }