/// <summary>
        /// Initializes a new instance of the ScriptExecutor class
        /// </summary>
        /// <param name="server">The server to which the executor must connect</param>
        /// <param name="database">The database against which the scripts must be executed</param>
        /// <param name="config">The configuratoin</param>
        public ScriptExecutor(Server server, Database database, ScriptExecutorConfiguration config)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server", "Server cannot be null");
            }

            if (database == null)
            {
                throw new ArgumentNullException("database", "Database cannot be null");
            }

            if (config == null)
            {
                throw new ArgumentNullException("config", "Config cannot be null");
            }

            if (config.ExecutionSequence.Count < 1)
            {
                throw new ArgumentOutOfRangeException("config", "Connfig.ExecutionSequence cannot be empty. At least one script needs to be defined");
            }

            this.server   = server;
            this.database = database;
            this.config   = config;
        }
        private void SaveConfig(string path, ScriptExecutorConfiguration configToSave)
        {
            StreamWriter  w = new StreamWriter(path);
            XmlSerializer s = new XmlSerializer(configToSave.GetType());

            s.Serialize(w, configToSave);
            w.Close();
        }
        private void Apply_Click(object sender, EventArgs e)
        {
            Server       server   = null;
            Database     database = null;
            ProgressForm progress = null;

            try
            {
                ScriptExecutorConfiguration config = this.LoadDeploymentConfig(this.configPath);

                if (this.ConfigurationIsValid(config))
                {
                    server   = new Server(this.cboServers.Text);
                    database = new Database(server, this.cboDatabases.Text);

                    FileInfo f = new FileInfo(this.configPath);
                    Environment.CurrentDirectory = f.DirectoryName;

                    progress = new ProgressForm(server, database, config);
                    progress.ShowDialog(this);
                }
            }
            catch (FailedOperationException ex)
            {
                SqlException sqlEx = ex.InnerException.InnerException as SqlException;
                MessageBox.Show(sqlEx.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                server   = null;
                database = null;
                if (progress != null)
                {
                    if (progress.Visible)
                    {
                        progress.Hide();
                    }

                    if (!progress.Disposing)
                    {
                        progress.Dispose();
                    }
                }
            }
        }
        private ScriptExecutorConfiguration LoadDeploymentConfig(string path)
        {
            ScriptExecutorConfiguration retval = null;

            if (File.Exists(path))
            {
                using (StreamReader sr = new StreamReader(path))
                {
                    XmlSerializer xs = new XmlSerializer(typeof(ScriptExecutorConfiguration));
                    retval = (ScriptExecutorConfiguration)xs.Deserialize(sr.BaseStream);
                    sr.Close();
                }
            }

            return(retval);
        }
Esempio n. 5
0
        /// <summary>
        /// Initializes a new instance of the ProgressForm class
        /// </summary>
        /// <param name="server">The server to which the class is connected</param>
        /// <param name="database">The database againts which the class is executing</param>
        /// <param name="config">The cofiguration</param>
        public ProgressForm(Server server, Database database, ScriptExecutorConfiguration config)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server", "server cannot be null");
            }

            if (database == null)
            {
                throw new ArgumentNullException("database", "database cannot be null");
            }

            if (config == null)
            {
                throw new ArgumentNullException("config", "config cannot be null");
            }

            this.server   = server;
            this.database = database;
            this.config   = config;
            this.InitializeComponent();
        }
        private bool ConfigurationIsValid(ScriptExecutorConfiguration config)
        {
            if (config == null)
            {
                MessageBox.Show(this, "Unable to load the ScriptExecutorConfiguration.xml file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            if (!string.IsNullOrEmpty(config.TargetServer) && this.cboServers.Text != config.TargetServer)
            {
                MessageBox.Show(this, string.Format("You may only deploy this update against the {0} server", config.TargetServer), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            if (!string.IsNullOrEmpty(config.TargetDatabase) && this.cboDatabases.Text != config.TargetDatabase)
            {
                MessageBox.Show(this, string.Format("You may only deploy this update against the {0} database", config.TargetDatabase), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            return(true);
        }