예제 #1
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);
            }
        }