Example #1
0
        private SiteInformation GetApplicationInformation(string path)
        {
            var siteInfo    = new SiteInformation();
            var app         = _siteManager.GetApplicationByPath(path);
            var virtualRoot =
                app.VirtualDirectories.SingleOrDefault(v => v.Path == "/");

            siteInfo.Name = app.Path.Split('/').FirstOrDefault();
            siteInfo.ApplicationPoolName = app.ApplicationPoolName;
            siteInfo.PhysicalPath        = virtualRoot.PhysicalPath;

            return(siteInfo);
        }
Example #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)
            {
            }
        }