public static void Initialize([CanBeNull] string defaultRootFolder = null)
        {
            using (WebServerManager.WebServerContext context = WebServerManager.CreateContext("Initialize instance manager"))
            {
                ProfileSection.Argument("defaultRootFolder", defaultRootFolder);

                IEnumerable <Site> sites = GetOperableSites(context, defaultRootFolder);
                PartiallyCachedInstances = GetPartiallyCachedInstances(sites);
                Instances = GetInstances();
            }
        }
Ejemplo n.º 2
0
        private IEnumerable <Instance> GetIISInstances([CanBeNull] string defaultRootFolder = null)
        {
            using (WebServerManager.WebServerContext context = WebServerManager.CreateContext())
            {
                ProfileSection.Argument("defaultRootFolder", defaultRootFolder);

                IEnumerable <Site> sites = GetOperableSites(context, defaultRootFolder);

                return(GetPartiallyCachedInstances(sites));
            }
        }
Ejemplo n.º 3
0
        public void Initialize([CanBeNull] string defaultRootFolder = null)
        {
            SitecoreEnvironmentHelper.RefreshEnvironments();

            using (WebServerManager.WebServerContext context = WebServerManager.CreateContext())
            {
                ProfileSection.Argument("defaultRootFolder", defaultRootFolder);

                IEnumerable <Site> sites = GetOperableSites(context, defaultRootFolder);
                PartiallyCachedInstances = GetPartiallyCachedInstances(sites);
                Instances = GetInstances();
            }
        }
Ejemplo n.º 4
0
        protected override void Process(ExportArgs args)
        {
            var websiteName = args.Instance.Name;

            using (var context = new WebServerManager.WebServerContext())
            {
                var appPoolName = new Website(args.Instance.ID).GetPool(context).Name;

                var websiteSettingsCommand = string.Format(@"%windir%\system32\inetsrv\appcmd list site {0}{1}{0} /config /xml > {2}", '"', websiteName, Path.Combine(args.Folder, "WebsiteSettings.xml"));
                var appPoolSettingsCommand = string.Format(@"%windir%\system32\inetsrv\appcmd list apppool {0}{1}{0} /config /xml > {2}", '"', appPoolName, Path.Combine(args.Folder, "AppPoolSettings.xml"));

                ExecuteCommand(websiteSettingsCommand);
                ExecuteCommand(appPoolSettingsCommand);
            }
        }
        private static IEnumerable <Site> GetOperableSites([NotNull] WebServerManager.WebServerContext context, [CanBeNull] string defaultRootFolder = null)
        {
            Assert.IsNotNull(context, "Context cannot be null");

            using (new ProfileSection("Getting operable sites"))
            {
                ProfileSection.Argument("context", context);
                ProfileSection.Argument("defaultRootFolder", defaultRootFolder);

                IEnumerable <Site> sites = context.Sites;
                if (defaultRootFolder != null)
                {
                    instancesFolder = defaultRootFolder.ToLower();
                    sites           = sites.Where(s => WebServerManager.GetWebRootPath(s).ToLower().Contains(instancesFolder));
                }

                return(ProfileSection.Result(sites));
            }
        }
        public static void InitializeWithSoftListRefresh([CanBeNull] string defaultRootFolder = null)
        {
            using (new ProfileSection("Initialize with soft list refresh"))
            {
                // Add check that this isn't an initial initialization
                if (Instances == null)
                {
                    Initialize(defaultRootFolder);
                }

                using (WebServerManager.WebServerContext context = WebServerManager.CreateContext("Initialize with soft list refresh"))
                {
                    IEnumerable <Site> sites = GetOperableSites(context, defaultRootFolder);

                    // The trick is in reused PartiallyCachedInstances. We use site ID as identificator that cached instance may be reused. If we can't fetch instance from cache, we create new.
                    PartiallyCachedInstances = sites
                                               .Select(site => PartiallyCachedInstances.FirstOrDefault(cachedInst => cachedInst.ID == site.Id) ?? GetPartiallyCachedInstance(site))
                                               .Where(IsSitecore)
                                               .ToArray();

                    Instances = PartiallyCachedInstances.Select(x => GetInstance(x.ID)).ToArray();
                }
            }
        }
        public static long SetupWebsite(bool enable32BitAppOnWin64, string webRootPath, bool forceNetFramework4, bool isClassic,
                                        IEnumerable <BindingInfo> bindings, string name)
        {
            long siteId;

            using (WebServerManager.WebServerContext context = WebServerManager.CreateContext())
            {
                ApplicationPool appPool = context.ApplicationPools.Add(ChooseAppPoolName(name, context.ApplicationPools));
                appPool.ManagedRuntimeVersion = NetFrameworkV2;
                var id = Settings.CoreInstallWebServerIdentity.Value;
                ProcessModelIdentityType type = GetIdentityType(id);
                appPool.ProcessModel.IdentityType   = type;
                appPool.ProcessModel.PingingEnabled = false;
                if (forceNetFramework4)
                {
                    appPool.SetAttributeValue("managedRuntimeVersion", "v4.0");
                }

                appPool.Enable32BitAppOnWin64 = enable32BitAppOnWin64;
                appPool.ManagedPipelineMode   = isClassic ? ManagedPipelineMode.Classic : ManagedPipelineMode.Integrated;

                if (type == ProcessModelIdentityType.SpecificUser)
                {
                    var password = Settings.CoreInstallWebServerIdentityPassword.Value;
                    appPool.ProcessModel.UserName = id;
                    appPool.ProcessModel.Password = password;
                }

                Product product = Product.Parse(ProductHelper.DetectProductFullName(webRootPath));

                if (product.Name.EqualsIgnoreCase("Sitecore CMS"))
                {
                    var ver = product.TwoVersion;
                    if (ver.StartsWith("6.0") || ver.StartsWith("6.1"))
                    {
                        appPool.Enable32BitAppOnWin64 = true;
                        appPool.ManagedPipelineMode   = ManagedPipelineMode.Classic;
                    }
                    else if (ver.StartsWith("6.2"))
                    {
                        appPool.Enable32BitAppOnWin64 = true;
                    }
                }

                Site site = null;
                foreach (BindingInfo binding in bindings)
                {
                    var bindingInformation = $"{binding.IP}:{binding.Port}:{binding.Host}";
                    if (site == null)
                    {
                        site = context.Sites.Add(name, binding.Protocol, bindingInformation, webRootPath);
                    }
                    else
                    {
                        site.Bindings.Add(bindingInformation, binding.Protocol);
                    }
                }

                Assert.IsNotNull(site, nameof(site));
                siteId = site.Id;
                site.ApplicationDefaults.ApplicationPoolName = name;
                context.CommitChanges();
            }

            return(siteId);
        }