示例#1
0
        /// <summary>
        /// Executes the script file.
        /// </summary>
        /// <param name="sqlScripts">The SQL scripts.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="hash">The hash.</param>
        /// <param name="version">The version.</param>
        public void ExecuteScriptFile(IEnumerable<string> sqlScripts, string fileName, string hash, SchemaVersion version)
        {
            var success = _parachuteCommand.Execute(sqlScripts);
            if (!success) return;

            using (var dc = new ParachuteContext(_connectionString))
            {
                var entry = new ParachuteAppliedScriptsLog
                {
                    SchemaVersion = version.ToString(),
                    ScriptName = fileName,
                    DateApplied = DateTime.Now,
                    Hash = hash
                };

                dc.ParachuteAppliedScriptsLogs.Add(entry);
                try
                {
                    dc.SaveChanges();
                }
                catch (InvalidOperationException invalidOperationEx)
                {

                    TraceHelper.Error(invalidOperationEx.Message);
                    throw;
                }
                catch (Exception ex)
                {
                    TraceHelper.Error(ex.Message);
                    throw;
                }
            }
        }
示例#2
0
        /// <summary>
        /// Executes the schema file.
        /// Executes a number of sql blocks as scripts and subsequently logs the Schema File in the SchemaChangeLog
        /// All blocks are executed as a single transaction.
        /// </summary>
        /// <param name="sqlScripts">The SQL scripts.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="version">The version.</param>
        public void ExecuteSchemaFile(IEnumerable<string> sqlScripts, string fileName, SchemaVersion version)
        {
            var success = _parachuteCommand.Execute(sqlScripts);

            if (!success) return;

            using (var dc = new ParachuteContext(_connectionString))
            {
                var entry = new ParachuteSchemaChangeLog
                    {
                        MajorReleaseNumber = version.MajorVersion,
                        MinorReleaseNumber = version.MinorVersion,
                        PointReleaseNumber = version.PointRelease,
                        ScriptName = fileName
                    };

                dc.ParachuteSchemaChangeLogs.Add(entry);

                try
                {

                    dc.SaveChanges();
                }
                catch (InvalidOperationException invalidOperationEx)
                {
                    TraceHelper.Error(invalidOperationEx.Message);
                    throw;
                }
                catch (Exception ex)
                {
                    TraceHelper.Error(ex.Message);
                    throw;
                }
            }
        }