/// <summary>
 /// You can delete a web site by issuing an HTTP DELETE request. If the
 /// web site being deleted is the only site remaining in a server
 /// farm, you can optionally delete the server farm as well by using
 /// the deleteEmptyServerFarm parameter.  (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/dn236430.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.WebSites.IWebSiteOperations.
 /// </param>
 /// <param name='webSpaceName'>
 /// Required. The name of the web space.
 /// </param>
 /// <param name='webSiteName'>
 /// Required. The name of the web site.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Delete Web Site operation.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static Task<AzureOperationResponse> DeleteAsync(this IWebSiteOperations operations, string webSpaceName, string webSiteName, WebSiteDeleteParameters parameters)
 {
     return operations.DeleteAsync(webSpaceName, webSiteName, parameters, CancellationToken.None);
 }
 /// <summary>
 /// You can delete a web site by issuing an HTTP DELETE request. If the
 /// web site being deleted is the only site remaining in a server
 /// farm, you can optionally delete the server farm as well by using
 /// the deleteEmptyServerFarm parameter.  (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/dn236430.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.WebSites.IWebSiteOperations.
 /// </param>
 /// <param name='webSpaceName'>
 /// Required. The name of the web space.
 /// </param>
 /// <param name='webSiteName'>
 /// Required. The name of the web site.
 /// </param>
 /// <param name='parameters'>
 /// Required. Parameters supplied to the Delete Web Site operation.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static AzureOperationResponse Delete(this IWebSiteOperations operations, string webSpaceName, string webSiteName, WebSiteDeleteParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IWebSiteOperations)s).DeleteAsync(webSpaceName, webSiteName, parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
 /// <summary>
 /// Delete a website slot.
 /// </summary>
 /// <param name="webspaceName">webspace the site is in.</param>
 /// <param name="websiteName">website name.</param>
 /// <param name="slot">The website slot name</param>
 public void DeleteWebsite(string webspaceName, string websiteName, string slot)
 {
     slot = slot ?? GetSlotName(websiteName) ?? WebsiteSlotName.Production.ToString();
     websiteName = SetWebsiteName(websiteName, slot);
     WebSiteDeleteParameters input = new WebSiteDeleteParameters()
     {
         /**
          * DeleteAllSlots is set to true in case that:
          * 1) We are trying to delete a production slot and,
          * 2) The website has more than one slot.
          */
         DeleteAllSlots = IsProductionSlot(slot) && GetWebsiteSlots(websiteName).Count != 1,
         DeleteEmptyServerFarm = false,
         DeleteMetrics = false
     };
     WebsiteManagementClient.WebSites.Delete(webspaceName, websiteName, input);
 }
 /// <summary>
 /// Delete a website.
 /// </summary>
 /// <param name="webspaceName">webspace the site is in.</param>
 /// <param name="websiteName">website name.</param>
 /// <param name="deleteMetrics">pass true to delete stored metrics as part of removing site.</param>
 /// <param name="deleteEmptyServerFarm">Pass true to delete server farm is this was the last website in it.</param>
 public void DeleteWebsite(string webspaceName, string websiteName, bool deleteMetrics = false, bool deleteEmptyServerFarm = false)
 {
     WebSiteDeleteParameters input = new WebSiteDeleteParameters()
     {
         DeleteAllSlots = true,
         DeleteEmptyServerFarm = deleteEmptyServerFarm,
         DeleteMetrics = deleteMetrics
     };
     WebsiteManagementClient.WebSites.Delete(webspaceName, websiteName, input);
 }
        private void Cleanup()
        {
            foreach (string profile in _profilesToCleanup)
            {
                try
                {
                    TrafficManagerClient.Profiles.Delete(profile);
                }
                catch { }
            }

            foreach (string service in _servicesToCleanup)
            {
                try
                {
                    ComputeManagementClient.HostedServices.Delete(service);
                }
                catch { }
            }

            foreach (string website in _websitesToCleanup)
            {
                try
                {
                    WebSiteDeleteParameters deleteParams = new WebSiteDeleteParameters();
                    deleteParams.DeleteEmptyServerFarm = true;
                    deleteParams.DeleteMetrics = true;
                    deleteParams.DeleteAllSlots = true;
                    WebsiteManagementClient.WebSites.Delete(WebSpaceName, website, deleteParams);
                }
                catch { }
            }

            TrafficManagerClient.Dispose();
            ComputeManagementClient.Dispose();
            ManagementClient.Dispose();
        }
 /// <summary>
 /// You can delete a web site by issuing an HTTP DELETE request. If the
 /// web site being deleted is the only site remaining in a server
 /// farm, you can optionally delete the server farm as well by using
 /// the deleteEmptyServerFarm parameter.  (see
 /// http://msdn.microsoft.com/en-us/library/windowsazure/dn236430.aspx
 /// for more information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.WebSites.IWebSiteOperations.
 /// </param>
 /// <param name='webSpaceName'>
 /// The name of the web space.
 /// </param>
 /// <param name='webSiteName'>
 /// The name of the web site.
 /// </param>
 /// <param name='parameters'>
 /// The parameters to delete a web site.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static OperationResponse Delete(this IWebSiteOperations operations, string webSpaceName, string webSiteName, WebSiteDeleteParameters parameters)
 {
     try
     {
         return operations.DeleteAsync(webSpaceName, webSiteName, parameters).Result;
     }
     catch (AggregateException ex)
     {
         if (ex.InnerExceptions.Count > 1)
         {
             throw;
         }
         else
         {
             throw ex.InnerException;
         }
     }
 }