Пример #1
0
        public JsonResult DeleteApplication(DeleteApplicationDto dto)
        {
            if ((string.IsNullOrEmpty(dto.SiteName) && dto.SiteType == IISSiteType.Application) || string.IsNullOrEmpty(dto.Name))
            {
                throw new NullReferenceException("Site name or application path is null");
            }

            ApplicationPoolService.DeleteApplicationAsync(dto).GetAwaiter();

            var redirectUrl = Url.Action("Index", "IIS");

            return(Json(new { success = true, responseText = "Success", redirectUrl }, JsonRequestBehavior.AllowGet));
        }
Пример #2
0
        /// <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)
            {
            }
        }
        public async Task <IActionResult> DeleteApplication([FromBody] DeleteApplicationDto deleteDto)
        {
            var response = await _mediator.Send(new DeleteApplicationCommand(deleteDto));

            return(Ok(response));
        }
 public DeleteApplicationCommand(DeleteApplicationDto deleteDto)
 {
     ApplicationDeleteDto = deleteDto;
 }