public void Run(Deployment deployment, IDeploymentLogger log, dynamic state)
        {
            bool found = false;

            foreach (var extension in Extensions)
            {
                log.Info("Looking for {0}{1}...", FileName, extension);

                string filePath = Path.Combine(deployment.ApplicationPath(), string.Concat(FileName, extension));

                if (File.Exists(filePath))
                {
                    log.Info("Executing {0}{1}...", FileName, extension);

                    found = true;

                    if (_environment.IsUnix)
                    {
                        SetUnixExecPermission(filePath);
                    }

                    ExecuteScript(filePath, log);
                    break;
                }
            }

            if (!found)
            {
                throw new FileNotFoundException("Could not find a deployment script in the application root.");
            }
        }
        private void ExecuteScript(string filePath, IDeploymentLogger log)
        {
            var startInfo = new ProcessStartInfo();
            startInfo.FileName = filePath;
            startInfo.WorkingDirectory = Path.GetDirectoryName(filePath);
            startInfo.UseShellExecute = false;
            startInfo.RedirectStandardOutput = true;
            startInfo.RedirectStandardError = true;
            startInfo.CreateNoWindow = true;

            var process = Process.Start(startInfo);
            var outputStream = process.StandardOutput;
            var errorStream = process.StandardError;

            while (!process.WaitForExit(1000))
            {
                FlushStreamToLog(outputStream, log.Info);
                FlushStreamToLog(errorStream, log.Error);
            }

            FlushStreamToLog(outputStream, log.Info);
            FlushStreamToLog(errorStream, log.Error);

            if (process.ExitCode != 0)
            {
                throw new DeploymentException("The script exited with a non-zero exit code.");
            }
        }
        public void Run(Deployment deployment, IDeploymentLogger log, dynamic state)
        {
            string path = deployment.PackagePath();
            bool download = true;

            log.Info("Checking package cache...", deployment.Url);

            if (File.Exists(path))
            {
                log.Info("Package has already been downloaded, checking hash...");

                using (var stream = File.OpenRead(path))
                {
                    if (_hasher.ValidateHash(stream, deployment.Hash))
                    {
                        log.Info("Hashes match, no need to download the package again.");
                        download = false;
                    }
                    else
                    {
                        log.Info("Hashes do NOT match, the package must be downloaded again.");
                        File.Delete(path);
                    }
                }
            }

            if (download)
            {
                log.Info("Dowloading package @ {0}...", deployment.Url);

                _webClient.DownloadFile(deployment.Url, path);
            }

            using (var stream = File.OpenRead(path))
            {
                if (!_hasher.ValidateHash(stream, deployment.Hash))
                {
                    throw new DeploymentException("The hashes did not match after downloading the package.");
                }
            }
        }