Esempio n. 1
0
        private SiteInformation GetSiteInformation(string path)
        {
            var siteInfo        = new SiteInformation();
            var site            = _siteManager.GetSiteByName(path);
            var applicationRoot =
                site.Applications.SingleOrDefault(a => a.Path == "/");
            var virtualRoot =
                applicationRoot.VirtualDirectories.SingleOrDefault(v => v.Path == "/");

            siteInfo.Name = site.Name;
            siteInfo.ApplicationPoolName = applicationRoot.ApplicationPoolName;
            siteInfo.PhysicalPath        = virtualRoot.PhysicalPath;

            foreach (var siteBinding in site.Bindings)
            {
                siteInfo.BindingInformation.Add(new BindingInfo
                {
                    BindingInformation = siteBinding.BindingInformation,
                    Host     = siteBinding.Host,
                    Protocol = siteBinding.Protocol
                });
            }

            return(siteInfo);
        }
Esempio n. 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)
            {
            }
        }