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

            string targetArgument        = string.Format("/t:{0}", Target.Get(context));
            string platformArgument      = string.Format("/p:platform={0}", Platform.Get(context));
            string configurationArgument = string.Format("/p:configuration={0}", Configuration.Get(context));
            string msBuildArguments      = "\"{0}\" {1} {2} {3} {4}";
            string msBuildPath           = Microsoft.Win32.Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\4.0", "MSBuildToolsPath", "") + @"\msbuild.exe";
            string output = string.Empty;

            msBuildArguments = string.Format(msBuildArguments,
                                             Project.Get(context),
                                             (!string.IsNullOrWhiteSpace(Target.Get(context)) ? targetArgument : ""),
                                             (!string.IsNullOrWhiteSpace(Platform.Get(context)) ? platformArgument : ""),
                                             (!string.IsNullOrWhiteSpace(Configuration.Get(context)) ? configurationArgument : ""),
                                             AdditionalCommandLineArguments.Get(context));

            console.WriteLine(string.Format("\"{0}\" {1}", msBuildPath, msBuildArguments) + Environment.NewLine);

            CommandLine commandLineHelper = new CommandLine();

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

            if (exitCode != 0)
            {
                throw new InvalidOperationException(string.Format("MsBuild.exe returned an exit code : '{0}'.", exitCode));
            }
        }
Beispiel #2
0
        protected override void Execute(CodeActivityContext context)
        {
            console = ActivityConsole.GetDefaultOrNew(context);

            string machineName = MachineName.Get(context);

            machineName = (string.IsNullOrEmpty(machineName) ? "." : machineName);

            bool throwOnError         = ThrowOnError.Get(context);
            bool treatExistsAsSuccess = TreatExistAsSuccess.Get(context);

            string errorMessage = "An unknown error has occurred.";
            bool   created      = CreateLogSource(machineName, EventLogName.Get(context), EventLogSource.Get(context), out errorMessage, treatExistsAsSuccess);

            if (created)
            {
                console.WriteLine(string.Format("Successfully created or verified event log and source : {0} - {1}", EventLogName.Get(context), EventLogSource.Get(context)));
            }
            else
            {
                if (throwOnError)
                {
                    throw new ArgumentException(errorMessage);
                }
                else
                {
                    console.WriteLine(string.Format("Error : {0}", errorMessage));
                }
            }
        }
Beispiel #3
0
        protected override void Execute(CodeActivityContext context)
        {
            console = context.GetExtension <ActivityConsole>();
            if (console == null)
            {
                console = new ActivityConsole();
            }
            bool   showDetails = ShowDetails.Get(context);
            string path        = Path.Get(context);
            string filter      = Filter.Get(context);

            List <string> fileNames = Directory.EnumerateFiles(path, filter).ToList();

            foreach (string fileName in fileNames)
            {
                File.Delete(fileName);
                if (showDetails)
                {
                    console.WriteLine(string.Format("Deleted file '{0}'.", fileName));
                }
            }

            if (IncludeFolders.Get(context))
            {
                List <string> directoryNames = Directory.EnumerateDirectories(path, filter).ToList();
                foreach (string directoryName in directoryNames)
                {
                    Directory.Delete(directoryName, true);
                    if (showDetails)
                    {
                        console.WriteLine(string.Format("Deleted folder '{0}' and everything in it.", directoryName));
                    }
                }
            }
        }
Beispiel #4
0
        protected override void Execute(CodeActivityContext context)
        {
            console = context.GetExtension <ActivityConsole>();
            if (console == null)
            {
                console = new ActivityConsole();
            }

            if (!string.IsNullOrEmpty(CommandLineArguments.Get(context)))
            {
                console.WriteLine("!!!Warning - This activity currently ignores 'CommandLineArguments' argument. !!!");
            }

            var project = new Project(Project.Get(context));
            StringOutputLogger logger = new StringOutputLogger();

            project.SetGlobalProperty("Configuration", Configuration.Get(context) ?? "");
            project.SetGlobalProperty("Platform", Platform.Get(context) ?? "");
            project.SetProperty("OutDir", OutDir.Get(context) ?? "");
            bool   buildResult = project.Build(Targets.Get(context).ToArray(), new ILogger[] { logger });
            string buildOutput = string.Format(
                "MSBUILD - {0}\nConfiguration : {1}\nPlatform : {2}\nOutput Directory : {3}\n{4}",
                project.FullPath,
                project.GetProperty("Configuration").EvaluatedValue,
                project.GetProperty("Platform").EvaluatedValue,
                project.GetProperty("OutDir").EvaluatedValue,
                logger.GetOutput());

            BuildOutput.Set(context, buildOutput);
            BuildSuccess.Set(context, buildResult);
            ProjectCollection.GlobalProjectCollection.UnloadProject(project);

            console.WriteLine(buildOutput);
        }
Beispiel #5
0
        protected override void Execute(CodeActivityContext context)
        {
            showDetails        = ShowDetails.Get(context);
            excludeFileFilters = ExcludeFileFilters.Get(context);
            if (excludeFileFilters == null)
            {
                excludeFileFilters = new List <Regex>();
            }

            console = context.GetExtension <ActivityConsole>();
            if (console == null)
            {
                console = new ActivityConsole();
            }

            DirectoryInfo sourcePath = new DirectoryInfo(Source.Get(context));
            DirectoryInfo targetPath = new DirectoryInfo(Target.Get(context));

            if (!sourcePath.Exists)
            {
                throw new IOException("The source path does not exist.");
            }

            CopyDirectory(sourcePath, targetPath);
        }
Beispiel #6
0
        protected override void Execute(CodeActivityContext context)
        {
            console = ActivityConsole.GetDefaultOrNew(context);

            showOutput = ShowOutput.Get(context);
            string folder = FolderPath.Get(context);

            DirectoryInfo di = new DirectoryInfo(folder);

            if (!di.Exists)
            {
                throw new ArgumentException(string.Format("The folder '{0}' does not exist.", folder));
            }

            InheritanceFlags inheritance = InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit;

            List <FileSystemAccessRule> accessRules = new List <FileSystemAccessRule>();

            accessRules.Add(new FileSystemAccessRule(UserOrGroup.Get(context), FileSystemRights.Read, inheritance, PropagationFlags.None, (Read.Get(context) ? AccessControlType.Allow : AccessControlType.Deny)));
            accessRules.Add(new FileSystemAccessRule(UserOrGroup.Get(context), FileSystemRights.Write, inheritance, PropagationFlags.None, (Write.Get(context) ? AccessControlType.Allow : AccessControlType.Deny)));
            accessRules.Add(new FileSystemAccessRule(UserOrGroup.Get(context), FileSystemRights.ExecuteFile, inheritance, PropagationFlags.None, (ReadAndExecute.Get(context) ? AccessControlType.Allow : AccessControlType.Deny)));

            DirectorySecurity ds = di.GetAccessControl();

            foreach (FileSystemAccessRule rule in accessRules)
            {
                ds.AddAccessRule(rule);
                WriteLineConsole(string.Format("Adding {0} {1} permission for identity {2} to folder {3}", rule.AccessControlType, rule.FileSystemRights, rule.IdentityReference.Value, folder));
            }

            di.SetAccessControl(ds);
        }
Beispiel #7
0
 protected override void Execute(CodeActivityContext context)
 {
     console = context.GetExtension <ActivityConsole>();
     if (console == null)
     {
         console = new ActivityConsole();
     }
     hideConsoleOutput = SuppressConsoleOutput.Get(context);
     ExecuteInvoke(context);
 }
Beispiel #8
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));
            }
        }
Beispiel #9
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));
            }
        }
Beispiel #10
0
        protected override void Execute(CodeActivityContext context)
        {
            console = context.GetExtension <ActivityConsole>();
            if (console == null)
            {
                console = new ActivityConsole();
            }

            string message = Message.Get(context);

            if (message != null)
            {
                console.WriteLine(message);
            }
        }
        protected override void Execute(CodeActivityContext context)
        {
            console = context.GetExtension <ActivityConsole>();
            if (console == null)
            {
                console = new ActivityConsole();
            }

            if (Exception.Get(context) != null)
            {
                string exceptionMessage = ExceptionManager.GetExceptionMessage(Exception.Get(context));
                Output.Set(context, exceptionMessage);
                console.WriteLine(exceptionMessage);
            }
        }
Beispiel #12
0
        protected override void Execute(CodeActivityContext context)
        {
            Configuration config = null;

            if (IsWebsite.Get(context))
            {
                var configFile = new FileInfo(ConfigFilename.Get(context));
                var vdm        = new VirtualDirectoryMapping(configFile.DirectoryName, true, configFile.Name);
                var wcfm       = new WebConfigurationFileMap();
                wcfm.VirtualDirectories.Add("/", vdm);
                config = WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/");
            }
            else
            {
                config = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap {
                    ExeConfigFilename = ConfigFilename.Get(context)
                }, ConfigurationUserLevel.None);
            }

            ConfigurationSection section = config.GetSection(Section.Get(context));

            section.SectionInformation.ProtectSection("RSAProtectedConfigurationProvider");
            config.Save();

            var console = context.GetExtension <ActivityConsole>();

            if (console == null)
            {
                console = new ActivityConsole();
            }

            console.WriteLine(string.Format("Encrypted section '{0}' in '{1}'", Section.Get(context), ConfigFilename.Get(context)));
            console.WriteLine("");

            string username = Username.Get(context);

            if (!string.IsNullOrEmpty(username))
            {
                Helpers.CommandLine cmdExecutor = new CommandLine();
                string output   = string.Empty;
                int    exitCode = cmdExecutor.Execute(string.Format("{0}\\{1}", Helpers.FrameworkHelper.GetDotNetInstallationFolder(), "aspnet_regiis"), string.Format("-pa \"NetFrameworkConfigurationKey\" \"{0}\"", username), out output);
                if (exitCode != 0 || !output.Contains("Succeeded!"))
                {
                    throw new ArgumentException(string.Format("Failed to set Encryption key security privileges for user '{0}'\n{1}", username, output));
                }
                console.WriteLine(string.Format("Successfully set read access to Encryption key for user '{0}'.", username));
            }
        }
Beispiel #13
0
        protected override void Execute(CodeActivityContext context)
        {
            console           = ActivityConsole.GetDefaultOrNew(context);
            hideConsoleOutput = SuppressConsoleOutput.Get(context);

            string inputFile       = InputFile.Get(context);
            string outputDirectory = OutputDirectory.Get(context);

            using (ZipStorer zipStorer = ZipStorer.Open(inputFile, FileAccess.Read))
            {
                List <ZipStorer.ZipFileEntry> directoryRepository = zipStorer.ReadCentralDir();
                foreach (ZipStorer.ZipFileEntry entry in directoryRepository)
                {
                    string fileName      = Path.GetFileName(entry.FilenameInZip);
                    string directoryName = Path.GetDirectoryName(entry.FilenameInZip);
                    string fullPath      = Path.Combine(outputDirectory, directoryName, fileName);
                    ExtractFile(zipStorer, entry, fullPath);
                }
            }
        }
Beispiel #14
0
        protected override void Execute(CodeActivityContext context)
        {
            showOutput = ShowOutput.Get(context);
            console    = context.GetExtension <ActivityConsole>();
            if (console == null)
            {
                console = new ActivityConsole();
            }

            DirectoryInfo path = new DirectoryInfo(FolderName.Get(context));

            if (!path.Exists)
            {
                WriteLineConsole("Creating Folder : " + path.FullName);
                path.Create();
            }
            else
            {
                WriteLineConsole(string.Format("Folder '{0}' already exists. Skipping folder creation.", path.FullName));
            }
        }
Beispiel #15
0
        protected override void Execute(CodeActivityContext context)
        {
            console           = ActivityConsole.GetDefaultOrNew(context);
            hideConsoleOutput = SuppressConsoleOutput.Get(context);

            List <string> includePaths = IncludePaths.Get(context);
            string        outputFile   = OutputFile.Get(context);
            string        comment      = Comment.Get(context) ?? string.Empty;

            try
            {
                using (ZipStorer zipStorer = ZipStorer.Create(outputFile, comment))
                {
                    foreach (string includePath in includePaths)
                    {
                        FileAttributes attr          = File.GetAttributes(includePath);
                        DirectoryInfo  directoryInfo = new DirectoryInfo(includePath);

                        if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
                        {
                            AddDirectory(zipStorer, directoryInfo, string.Empty, 0);
                        }
                        else
                        {
                            AddFile(zipStorer, includePath, directoryInfo.Name, string.Empty, 0);
                        }
                    }
                }
            }
            catch
            {
                try
                {
                    File.Delete(outputFile);
                }
                catch { }
                throw;
            }
        }
Beispiel #16
0
        public static WorkflowApplication ExecuteWorkflow(Activity workflow,
                                                          Action <WorkflowApplicationCompletedEventArgs> workflowCompleted = null,
                                                          Func <WorkflowApplicationUnhandledExceptionEventArgs, UnhandledExceptionAction> workflowUnhandledException = null,
                                                          Action <WorkflowApplicationAbortedEventArgs> workflowAborted = null,
                                                          bool debug = false)
        {
            var console = new ActivityConsole();

            console.dataArrived += new EventHandler <ConsoleDataArrivedEventArgs>(console_dataArrived);
            var wa = new WorkflowApplication(workflow);

            wa.Extensions.Add(console);
            if (debug)
            {
                wa.Extensions.Add(new ConsoleTrackingParticipant());
            }
            wa.Completed            = workflowCompleted;
            wa.OnUnhandledException = workflowUnhandledException;
            wa.Aborted = workflowAborted;
            wa.Run();
            return(wa);
        }
Beispiel #17
0
        protected override void Execute(CodeActivityContext context)
        {
            var console = context.GetExtension <ActivityConsole>();

            if (console == null)
            {
                console = new ActivityConsole();
            }

            string sqlStatement =
                "USE [{0}]\n" +
                "DECLARE @Username nvarchar(max);\n" +
                "SET @Username = '******' + '{2}';\n" +
                "SET NOCOUNT ON;\n" +
                "DECLARE @SQL NVARCHAR(4000);\n" +
                "SET @SQL = 'CREATE USER [' + @Username + '] FOR LOGIN [' + @Username + '] WITH DEFAULT_SCHEMA=[{3}]';\n" +
                "EXECUTE(@SQL);";

            SqlConnectionStringBuilder connectionStringBuilder = new SqlConnectionStringBuilder(ConnectionString.Get(context));

            string databaseName  = connectionStringBuilder.InitialCatalog;
            string loginName     = LoginName.Get(context);
            string message       = string.Format("Successfully created (or exists) SQL Server database user account '{0}'.", loginName);
            string defaultSchema = DefaultSchema.Get(context);

            if (string.IsNullOrEmpty(defaultSchema))
            {
                defaultSchema = "dbo";
            }

            if (IsWindowsLogin.Get(context))
            {
                if (IsLocalSQLMachineAccount.Get(context))
                {
                    sqlStatement = string.Format(sqlStatement, databaseName, "HOST_NAME()", "\\" + loginName, defaultSchema);
                }
                else
                {
                    if (string.IsNullOrEmpty(DomainName.Get(context)))
                    {
                        throw new ArgumentException("Domain name must be specified for windows domain logins.");
                    }
                    sqlStatement = string.Format(sqlStatement, databaseName, "'" + DomainName.Get(context) + "'", "\\" + loginName, defaultSchema);
                }
            }
            else
            {
                sqlStatement = string.Format(sqlStatement, databaseName, "", loginName, defaultSchema);
            }

            using (SqlConnection connection = new SqlConnection(ConnectionString.Get(context)))
            {
                using (SqlCommand command = new SqlCommand(sqlStatement, connection))
                {
                    connection.Open();
                    try
                    {
                        command.ExecuteNonQuery();
                    }
                    catch (SqlException ex)
                    {
                        if (ex.Number != 15023)                         //Already exists, ignore this error.
                        {
                            throw;
                        }
                    }
                    console.WriteLine(message);
                }
            }
        }
Beispiel #18
0
        protected override void Execute(CodeActivityContext context)
        {
            var console = context.GetExtension <ActivityConsole>();

            if (console == null)
            {
                console = new ActivityConsole();
            }

            string sqlStatement =
                "DECLARE @Username nvarchar(max);\n" +
                "SET @Username = '******' + '{1}';\n" +
                "SET NOCOUNT ON;\n" +
                "DECLARE @SQL NVARCHAR(4000);\n" +
                "SET @SQL = 'CREATE LOGIN [' + @Username + '] {2} WITH {3} DEFAULT_DATABASE=[{4}]';\n" +
                "EXECUTE(@SQL);";

            string loginName       = LoginName.Get(context);
            string message         = string.Format("Successfully created (or exists) SQL Server user login '{0}'.", loginName);
            string defaultDatabase = DefaultDatabase.Get(context);

            if (string.IsNullOrEmpty(defaultDatabase))
            {
                defaultDatabase = "master";
            }

            if (IsWindowsLogin.Get(context))
            {
                if (IsLocalSQLMachineAccount.Get(context))
                {
                    sqlStatement = string.Format(sqlStatement, "HOST_NAME()", "\\" + loginName, "FROM WINDOWS", "", defaultDatabase);
                }
                else
                {
                    if (string.IsNullOrEmpty(DomainName.Get(context)))
                    {
                        throw new ArgumentException("Domain name must be specified for windows domain logins.");
                    }
                    sqlStatement = string.Format(sqlStatement, "'" + DomainName.Get(context) + "'", "\\" + loginName, "FROM WINDOWS", "", defaultDatabase);
                }
            }
            else
            {
                string password = Password.Get(context);
                sqlStatement = string.Format(sqlStatement, "", loginName, "", "PASSWORD=''" + password + "'',", defaultDatabase);
            }

            using (SqlConnection connection = new SqlConnection(ConnectionString.Get(context)))
            {
                using (SqlCommand command = new SqlCommand(sqlStatement, connection))
                {
                    connection.Open();
                    try
                    {
                        command.ExecuteNonQuery();
                    }
                    catch (SqlException ex)
                    {
                        if (ex.Number != 15025)                         //Already exists, ignore error
                        {
                            throw;
                        }
                    }
                    console.WriteLine(message);
                }
            }
        }
Beispiel #19
0
        protected override void Execute(CodeActivityContext context)
        {
            console = context.GetExtension <ActivityConsole>();
            if (console == null)
            {
                console = new ActivityConsole();
            }

            string xamlFile = XamlFileName.Get(context);
            Dictionary <string, object> inputs = Inputs.Get(context);

            try
            {
                Activity workflow     = null;
                string   xamlFileName = XamlFileName.Get(context);

                string password     = null;
                string errorMessage = null;
                if (XamlFileProviderFactory.IsXamlFileEncrypted(xamlFileName))
                {
                    password = Password.Get(context);
                    if (string.IsNullOrEmpty(password))
                    {
                        errorMessage = string.Format("The file '{0}' is protected and requires the correct password to open.", xamlFileName);
                    }
                }

                if (string.IsNullOrEmpty(errorMessage))
                {
                    try
                    {
                        IXamlFileProvider provider = XamlFileProviderFactory.GetXamlFileProvider(xamlFileName, password);
                        provider.LoadXamlFile(xamlFileName, password);
                        workflow = provider.XamlDocument;
                    }
                    catch (Exception ex)
                    {
                        errorMessage = ex.Message;
                        if (errorMessage == "The encrypted string was not in a valid format.")
                        {
                            errorMessage = "The password you specified was incorrect.";
                        }
                        errorMessage = string.Format("The following error occurred while trying to open '{0}' : \n\n{1}", xamlFileName, errorMessage);
                    }
                }
                if (!string.IsNullOrEmpty(errorMessage))
                {
                    throw new ArgumentException(errorMessage);
                }

                WorkflowApplication wa;
                if (inputs != null && inputs.Count > 0)
                {
                    wa = new WorkflowApplication(workflow, Inputs.Get(context));
                }
                else
                {
                    wa = new WorkflowApplication(workflow);
                }
                wa.Extensions.Add(console);
                wa.Completed            = WorkflowCompleted;
                wa.OnUnhandledException = WorkflowUnhandledException;
                wa.Aborted = WorkflowAborted;
                isBusy     = true;
                console.WriteLine(Environment.NewLine + xamlFile + " Executing..." + Environment.NewLine);
                wa.Run();
                while (isBusy)
                {
                    System.Threading.Thread.Sleep(200);
                }
                console.WriteLine(Environment.NewLine + xamlFile + " Execution Complete." + Environment.NewLine);
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #20
0
        protected override void Execute(CodeActivityContext context)
        {
            console = context.GetExtension <ActivityConsole>();
            if (console == null)
            {
                console = new ActivityConsole();
            }

            int version = UseVersion.Get(context);

            if (UseVersion2x.Get(context))
            {
                UseVersion.Set(context, 2);
            }

            string platformKey     = "InstallPath";
            string keyName         = string.Format(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\IIS Extensions\MSDeploy\{0}", version);
            string msdeployExePath = (string)Microsoft.Win32.Registry.GetValue(keyName, platformKey, "");

            if (string.IsNullOrEmpty(msdeployExePath))
            {
                throw new ArgumentException(string.Format("Could not find msdeploy.exe for version '{0}'.", version));
            }
            msdeployExePath = string.Format("\"{0}\"", System.IO.Path.Combine(msdeployExePath, "msdeploy.exe"));

            if (version == 2 && string.IsNullOrEmpty(Environment.GetEnvironmentVariable("MSDeployPath")))
            {
                Environment.SetEnvironmentVariable("MSDeployPath", msdeployExePath);
            }

            string executablePath;
            string arguments;

            if (ExecutionType.Get(context) == MSDeployExecutionType.Exe)
            {
                executablePath = msdeployExePath;
                arguments      = GetExeFileCommandLineArguments(context);
            }
            else
            {
                executablePath = CmdFileName.Get(context);
                arguments      = GetCmdFileCommandLineArguments(context);
            }

            string output = string.Empty;

            CommandLine commandLineHelper = new CommandLine();

            commandLineHelper.ReportProgress += new EventHandler <CommandLineProgressEventArgs>(commandLineHelper_ReportProgress);
            console.WriteLine(string.Format("{0} {1}\r\n", executablePath, arguments));
            int returnValue = commandLineHelper.Execute(executablePath, arguments, out output);

            if (output.Contains("All arguments must begin with \"-\"") && ExecutionType.Get(context) == MSDeployExecutionType.Cmd && !string.IsNullOrEmpty(IISWebApplication.Get(context)))
            {
                console.WriteLine("\n");
                console.WriteLine("**********************************************************************************************************************************************\n");
                console.WriteLine("There is a bug with 2012 versions of the .cmd files generated, which does not allow '=' to be passed on the command line.  Try the Exe method.\n");
                console.WriteLine("**********************************************************************************************************************************************\n\n");
            }

            if (output.Contains("Attempted to perform an unauthorized operation.") || output.Contains("ERROR_USER_UNAUTHORIZED") || output.Contains("ERROR_INSUFFICIENT_ACCESS_TO_SITE_FOLDER"))
            {
                console.WriteLine("\n");
                console.WriteLine("***********************************************************************************************************************\n");
                console.WriteLine("It seems the user account is not allowed to do this.  Try running as administrator or specifying username and password.\n");
                console.WriteLine("***********************************************************************************************************************\n\n");
            }

            if (output.Contains("ERROR_CERTIFICATE_VALIDATION_FAILED"))
            {
                console.WriteLine("\n");
                console.WriteLine("**********************************************************************************************************\n");
                console.WriteLine("The SSL certificate is self signed and untrusted. Tick the 'Allow Untrusted Connection' box and try again. \n");
                console.WriteLine("**********************************************************************************************************\n\n");
            }

            if (returnValue != 0 || (!output.Contains("Total changes:")))
            {
                throw new InvalidOperationException(output);
            }
        }