private static void DeployToAzure(RunningDeployment deployment, AzureTargetSite targetSite,
                                          CalamariVariableDictionary variables,
                                          WebDeployPublishSettings publishSettings)
        {
            var retry = AzureRetryTracker.GetDefaultRetryTracker();

            while (retry.Try())
            {
                try
                {
                    Log.Verbose($"Using site '{targetSite.Site}'");
                    Log.Verbose($"Using slot '{targetSite.Slot}'");
                    var changeSummary = DeploymentManager
                                        .CreateObject("contentPath", deployment.CurrentDirectory)
                                        .SyncTo(
                        "contentPath",
                        BuildPath(targetSite, variables),
                        DeploymentOptions(publishSettings),
                        DeploymentSyncOptions(variables)
                        );

                    Log.Info(
                        "Successfully deployed to Azure. {0} objects added. {1} objects updated. {2} objects deleted.",
                        changeSummary.ObjectsAdded, changeSummary.ObjectsUpdated, changeSummary.ObjectsDeleted);
                    break;
                }
                catch (DeploymentDetailedException ex)
                {
                    if (retry.CanRetry())
                    {
                        if (retry.ShouldLogWarning())
                        {
                            Log.VerboseFormat("Retry #{0} on Azure deploy. Exception: {1}", retry.CurrentTry,
                                              ex.Message);
                        }

                        Thread.Sleep(retry.Sleep());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }
        private static DeploymentBaseOptions DeploymentOptions(WebDeployPublishSettings settings)
        {
            var publishProfile = settings.PublishProfile;
            var deploySite     = settings.DeploymentSite;

            var options = new DeploymentBaseOptions
            {
                AuthenticationType = "Basic",
                RetryAttempts      = 3,
                RetryInterval      = 1000,
                TraceLevel         = TraceLevel.Verbose,
                UserName           = publishProfile.UserName,
                Password           = publishProfile.Password,
                UserAgent          = "OctopusDeploy/1.0",
                ComputerName       = new Uri(publishProfile.Uri, $"/msdeploy.axd?site={deploySite}").ToString()
            };

            options.Trace += (sender, eventArgs) => LogDeploymentEvent(eventArgs);

            return(options);
        }