Inheritance: IDisposable
        public FileResult LogFile(string siteName)
        {
            byte[] fileBytes = null;
            using (LogFile logFile = new LogFile(siteName, true))
            {
                // Not calling File.ReadAllBytes because it can cause a sharing violation if
                // the log file is still being written to.
                using (Stream fileStream = FileHelper.FileSystem.File.Open(
                    logFile.FilePath,
                    FileMode.Open,
                    FileAccess.Read,
                    FileShare.ReadWrite))
                {
                    fileBytes = ReadStreamToBytes(fileStream);
                }

                return File(
                    fileBytes,
                    System.Net.Mime.MediaTypeNames.Application.Octet,
                    "deploy.log");
            }
        }
        public DeploymentChangeSummary DeployContentToOneSite(
            IConfigRepository repository,
            string contentPath,
            string publishSettingsFile)
        {
            var sourceBaseOptions = new DeploymentBaseOptions();
            DeploymentBaseOptions destBaseOptions;
            string siteName = SetDestBaseOptions(publishSettingsFile, out destBaseOptions);
            bool success = true;
            DeploymentChangeSummary summary = null;

            AddSkips(repository.Config.SkipRules, sourceBaseOptions, destBaseOptions);

            Trace.TraceInformation("Starting WebDeploy for {0}", Path.GetFileName(publishSettingsFile));

            using (StatusFile status = new StatusFile(siteName))
            using (LogFile logFile = new LogFile(siteName, false))
            {
                sourceBaseOptions.Trace += logFile.LogEventHandler;
                destBaseOptions.Trace += logFile.LogEventHandler;

                try
                {
                    logFile.Log(TraceLevel.Info, "Beginning sync");

                    status.State = Models.DeployState.Deploying;
                    status.Save();

                    // Publish the content to the remote site
                    using (var deploymentObject = DeploymentManager.CreateObject(DeploymentWellKnownProvider.ContentPath, contentPath, sourceBaseOptions))
                    {
                        // Note: would be nice to have an async flavor of this API...
                        summary = deploymentObject.SyncTo(DeploymentWellKnownProvider.ContentPath, siteName, destBaseOptions, new DeploymentSyncOptions());
                    }

                    string summaryString = string.Format("Total Changes: {0} ({1} added, {2} deleted, {3} updated, {4} parameters changed, {5} bytes copied)",
                        summary.TotalChanges,
                        summary.ObjectsAdded,
                        summary.ObjectsDeleted,
                        summary.ObjectsUpdated,
                        summary.ParameterChanges,
                        summary.BytesCopied);

                    status.ObjectsAdded = summary.ObjectsAdded;
                    status.ObjectsDeleted = summary.ObjectsDeleted;
                    status.ObjectsUpdated = summary.ObjectsUpdated;
                    status.ParametersChanged = summary.ParameterChanges;
                    status.BytesCopied = summary.BytesCopied;

                    logFile.Log(TraceLevel.Info, summaryString);
                    logFile.Log(TraceLevel.Info, "Sync completed successfully");
                }
                catch(Exception e)
                {
                    logFile.Log(TraceLevel.Error, e.ToString());
                    success = false;
                    status.State = Models.DeployState.Failed;
                }

                if (success)
                {
                    status.State = Models.DeployState.Succeeded;
                }
            }   // Close log file and status file

            return summary;
        }