Exemplo n.º 1
0
        public static SiteStartResult StartSite(IisSite site)
        {
            using (var manager = new ServerManager())
            {
                var iisSite = manager.Sites.SingleOrDefault(x => x.Id == site.IisId);
                if (iisSite == null)
                {
                    throw new SiteNotFoundException("Site " + site.Name + " was not found on IIS");
                }

                try
                {
                    iisSite.Start();
                    return(SiteStartResult.Started);
                }
                catch (ServerManagerException)
                {
                    return(SiteStartResult.BindingIsAlreadyInUse);
                }
                catch (FileLoadException e)
                {
                    if (e.Message.Contains("being used by another"))
                    {
                        return(SiteStartResult.PortInUseByAnotherService);
                    }

                    return(SiteStartResult.CannotAccessSitePath);
                }
            }
        }
Exemplo n.º 2
0
        private static IisSite ParseSite(Microsoft.Web.Administration.Site site, bool excludeAppPools = false, List <Microsoft.Web.Administration.ApplicationPool> applicationPools = null)
        {
            if (site == null)
            {
                return(null);
            }

            var servantSite = new IisSite
            {
                IisId            = (int)site.Id,
                Name             = site.Name,
                ApplicationPool  = site.Applications[0].ApplicationPoolName,
                SitePath         = site.Applications[0].VirtualDirectories[0].PhysicalPath,
                SiteState        = site.State,
                LogFileDirectory = site.LogFile.Directory,
                Bindings         = GetBindings(site).ToList(),
                Applications     = new List <UnionSoftSiteApplication>()
            };

            if (!excludeAppPools)
            {
                if (applicationPools == null)
                {
                    using (var manager = new ServerManager())
                    {
                        applicationPools = manager.ApplicationPools.ToList();
                    }
                }

                ObjectState applicationPoolState = applicationPools.Single(x => x.Name == site.Applications[0].ApplicationPoolName).State;
                //servantSite.ApplicationPoolState = (InstanceState)Enum.Parse(typeof(InstanceState), applicationPoolState.ToString());
            }

            foreach (var directory in site.Applications[0].VirtualDirectories.Skip(1))
            {
                servantSite.Applications.Add(new UnionSoftSiteApplication
                {
                    ApplicationPool = "",
                    Path            = directory.Path,
                    DiskPath        = directory.PhysicalPath,
                    IsApplication   = false
                });
            }

            if (site.Applications.Count > 1)
            {
                foreach (var application in site.Applications.Skip(1))
                {
                    servantSite.Applications.Add(new UnionSoftSiteApplication
                    {
                        ApplicationPool = application.ApplicationPoolName,
                        Path            = application.Path,
                        DiskPath        = application.VirtualDirectories[0].PhysicalPath,
                        IsApplication   = true
                    });
                }
            }

            return(servantSite);
        }
Exemplo n.º 3
0
        public static void StopSite(IisSite site)
        {
            using (var manager = new ServerManager())
            {
                var iisSite = manager.Sites.SingleOrDefault(x => x.Id == site.IisId);
                if (iisSite == null)
                {
                    throw new SiteNotFoundException("Site " + site.Name + " was not found on IIS");
                }

                iisSite.Stop();
            }
        }