예제 #1
0
        protected override void Execute(CodeActivityContext context)
        {
            console = context.GetExtension <ActivityConsole>();
            if (console == null)
            {
                console = new ActivityConsole();
            }

            string backupArguments          = string.Format("/p:BackupDatabaseBeforeChanges={0}", BackupBeforeDeploy.Get(context));
            string alwaysCreateNewArguments = string.Format("/p:CreateNewDatabase={0}", AlwaysCreateNewDatabase.Get(context));
            string sqlPackageArguments      = "/a:Publish /tcs:\"{0}\" /sf:\"{1}\" {2} {3} {4}";
            string output         = string.Empty;
            string sqlPackagePath = SqlPackagePath.Get(context);

            if (string.IsNullOrEmpty(sqlPackagePath))
            {
                sqlPackagePath = @"C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin\SqlPackage.exe";
            }

            if (sqlPackagePath.EndsWith("SqlPackage.exe", StringComparison.OrdinalIgnoreCase))
            {
                sqlPackagePath = sqlPackagePath.Substring(0, sqlPackagePath.Length - "SqlPackage.exe".Length);
            }

            sqlPackagePath = Path.Combine(sqlPackagePath, "SqlPackage.exe");

            if (!File.Exists(sqlPackagePath))
            {
                throw new ArgumentException(string.Format("SqlPackage missing : The file '{0}' could not be found.", sqlPackagePath));
            }

            sqlPackageArguments = string.Format(sqlPackageArguments,
                                                ConnectionString.Get(context),
                                                DacpacFilename.Get(context),
                                                (BackupBeforeDeploy.Get(context) ? backupArguments : ""),
                                                (AlwaysCreateNewDatabase.Get(context) ? alwaysCreateNewArguments : ""),
                                                AdditionalArguments.Get(context));

            console.WriteLine("Executing SqlPackage.exe..." + Environment.NewLine);

            if (ShowCommandLine.Get(context))
            {
                console.WriteLine(string.Format("\"{0}\" {1}", sqlPackagePath, sqlPackageArguments));
            }

            CommandLine commandLineHelper = new CommandLine();

            commandLineHelper.ReportProgress += new EventHandler <CommandLineProgressEventArgs>(commandLineHelper_ReportProgress);
            int exitCode = commandLineHelper.Execute(sqlPackagePath, sqlPackageArguments, out output);

            if (exitCode != 0)
            {
                throw new InvalidOperationException(string.Format("SqlPackage returned a exit code : '{0}'.", exitCode));
            }
        }
예제 #2
0
        protected override void Execute(CodeActivityContext context)
        {
            console = context.GetExtension <ActivityConsole>();
            if (console == null)
            {
                console = new ActivityConsole();
            }

            string backupArguments          = string.Format("/p:PerformDatabaseBackup={0}", BackupBeforeDeploy.Get(context));
            string alwaysCreateNewArguments = string.Format("/p:AlwaysCreateNewDatabase={0}", AlwaysCreateNewDatabase.Get(context));
            string vsdbcmdArguments         = "/a:Deploy /dd+ /cs:\"{0}\" /p:TargetDatabase={1}  \"/manifest:{2}\" {3} {4}";
            string output  = string.Empty;
            string vsdbcmd = VsdbcmdPath.Get(context);

            if (string.IsNullOrEmpty(vsdbcmd))
            {
                vsdbcmd = ".\\";
            }

            if (vsdbcmd.EndsWith("vsdbcmd.exe", StringComparison.OrdinalIgnoreCase))
            {
                vsdbcmd = vsdbcmd.Substring(0, vsdbcmd.Length - "vsdbcmd.exe".Length);
            }

            vsdbcmd = Path.Combine(vsdbcmd, "vsdbcmd.exe");

            if (!File.Exists(vsdbcmd))
            {
                throw new ArgumentException(string.Format("Vsdbcmd missing : The file '{0}' could not be found.", vsdbcmd));
            }

            vsdbcmdArguments = string.Format(vsdbcmdArguments,
                                             ConnectionString.Get(context),
                                             TargetDatabase.Get(context),
                                             ManifestFilename.Get(context),
                                             (BackupBeforeDeploy.Get(context) ? backupArguments : ""),
                                             (AlwaysCreateNewDatabase.Get(context) ? alwaysCreateNewArguments : ""));

            console.WriteLine("Executing Vsdbcmd.exe..." + Environment.NewLine);

            CommandLine commandLineHelper = new CommandLine();

            commandLineHelper.ReportProgress += new EventHandler <CommandLineProgressEventArgs>(commandLineHelper_ReportProgress);
            int exitCode = commandLineHelper.Execute(vsdbcmd, vsdbcmdArguments, out output);

            if (exitCode != 0)
            {
                throw new InvalidOperationException(string.Format("Vsdbcmd returned a exit code : '{0}'.", exitCode));
            }
        }