/// <summary> /// Delete application and related files/site/database. /// </summary> /// <param name="dto">Delete params</param> /// <returns>async task</returns> public async Task DeleteApplicationAsync(DeleteApplicationDto dto) { var rootPath = ""; var applicationPoolName = ""; if (dto.DeleteStates.NeedDeleteApplication) { var siteManager = new SitesManager(); switch (dto.SiteType) { case IISSiteType.Site: var site = siteManager.GetSiteByName(dto.Name); var applicationRoot = site.Applications.SingleOrDefault(a => a.Path == "/"); var virtualRoot = applicationRoot?.VirtualDirectories.SingleOrDefault(v => v.Path == "/"); rootPath = virtualRoot?.PhysicalPath; applicationPoolName = applicationRoot?.ApplicationPoolName; siteManager.DeleteSite(dto.Name); break; case IISSiteType.Application: var app = siteManager.GetApplicationByPath(dto.Name, dto.SiteName); applicationPoolName = app.ApplicationPoolName; rootPath = app.VirtualDirectories.SingleOrDefault(v => v.Path == "/")?.PhysicalPath; siteManager.DeleteApplication(app.Path, dto.SiteName); break; } siteManager.Dispose(); } if (dto.DeleteStates.NeedDeleteApplicationPool) { DeleteApplicationPool(applicationPoolName); } if (dto.DeleteStates.NeedDeleteDatabase && !string.IsNullOrEmpty(dto.Database)) { await DeleteDatabase(dto.Database); } if (dto.DeleteStates.NeedDeleteFiles) { DeleteFolder(rootPath); } if (dto.DeleteStates.NeedDeleteChildApplications) { } }