private void GetSettingsFromIISFiles(ImportArgs args)
        {
            using (WebServerManager.WebServerContext context = WebServerManager.CreateContext("ImportSolution.Initialization"))
            {
                string        appPoolFilePath         = FileSystem.FileSystem.Local.Zip.ZipUnpackFile(args.PathToExportedInstance, args.temporaryPathToUnpack, ImportArgs.appPoolSettingsFileName);
                string        websiteSettingsFilePath = FileSystem.FileSystem.Local.Zip.ZipUnpackFile(args.PathToExportedInstance, args.temporaryPathToUnpack, ImportArgs.websiteSettingsFileName);
                XmlDocumentEx appPool = new XmlDocumentEx();
                appPool.Load(appPoolFilePath);

                XmlDocumentEx websiteSettings = new XmlDocumentEx();
                websiteSettings.Load(websiteSettingsFilePath);
                args.oldSiteName = websiteSettings.GetElementAttributeValue("/appcmd/SITE/site", "name");
                if (args.siteName == string.Empty)
                {
                    args.siteName = websiteSettings.GetElementAttributeValue("/appcmd/SITE/site", "name");
                }

                args.virtualDirectoryPath = websiteSettings.GetElementAttributeValue("/appcmd/SITE/site/application/virtualDirectory", "path");

                if (args.virtualDirectoryPhysicalPath == string.Empty)
                {
                    args.virtualDirectoryPhysicalPath = websiteSettings.GetElementAttributeValue("/appcmd/SITE/site/application/virtualDirectory", "physicalPath");
                }

                args.appPoolName = appPool.GetElementAttributeValue("/appcmd/APPPOOL", "APPPOOL.NAME"); // need to set appPoolName in both files
                if (args.appPoolName != args.siteName)
                {
                    args.appPoolName = args.siteName;
                }

                args.appPoolName = SetupWebsiteHelper.ChooseAppPoolName(args.appPoolName, context.ApplicationPools);
                args.siteID      = long.Parse(websiteSettings.GetElementAttributeValue("/appcmd/SITE", "SITE.ID"));
            }
        }
        public string CreateNewAppPoolName(string oldName)
        {
            List <string> poolsNames = new List <string>();

            foreach (var appPool in WebServerManager.CreateContext(string.Empty).ApplicationPools)
            {
                poolsNames.Add(appPool.Name);
            }

            bool flag = false;

            while (!flag)
            {
                if ((from t in poolsNames
                     where t == oldName
                     select t).FirstOrDefault() == null)
                {
                    return(oldName);
                }
                else
                {
                    oldName += "_imported";
                }
            }

            return(null);
        }
        public 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())
                {
                    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)
                                               .Where(IsNotHidden)
                                               .ToArray();

                    Instances = PartiallyCachedInstances.Select(x => GetInstance(x.ID)).ToArray();
                }
            }
        }
 public long?CreateNewID(long?oldID)
 {
     using (WebServerManager.WebServerContext context = WebServerManager.CreateContext("InstanceMgr.Init"))
     {
         var instances = context.Sites;
         return(oldID == null || instances.Any(x => x.Id == oldID) ? instances.Max(x => x.Id) + 1 : oldID);
     }
 }
        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();
            }
        }
예제 #6
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));
            }
        }
예제 #7
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();
            }
        }
        private string GetValidWebsiteName()
        {
            var instanceName = InstanceName;

            Assert.IsNotNull(instanceName, nameof(instanceName));

            var name = instanceName.Text.EmptyToNull();

            Assert.IsNotNull(name, @"Instance name isn't set");

            var websiteExists = WebServerManager.WebsiteExists(name);

            if (websiteExists)
            {
                using (var context = WebServerManager.CreateContext())
                {
                    var site = context.Sites.Single(s => s != null && s.Name.EqualsIgnoreCase(name));
                    var path = WebServerManager.GetWebRootPath(site);
                    if (FileSystem.FileSystem.Local.Directory.Exists(path))
                    {
                        Alert("The website with the same name already exists, please choose another instance name.");
                        return(null);
                    }

                    if (
                        WindowHelper.ShowMessage(
                            $"A website with the name {name} already exists. Would you like to remove it?",
                            MessageBoxButton.OKCancel, MessageBoxImage.Asterisk) != MessageBoxResult.OK)
                    {
                        return(null);
                    }

                    site.Delete();
                    context.CommitChanges();
                }
            }

            websiteExists = WebServerManager.WebsiteExists(name);
            Assert.IsTrue(!websiteExists, "The website with the same name already exists, please choose another instance name.");
            return(name);
        }
        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);
        }
예제 #10
0
        public bool OnMovingNext(WizardArgs wizardArgs)
        {
            var productRevision = this.ProductRevision;

            Assert.IsNotNull(productRevision, "productRevision");

            Product product = productRevision.SelectedValue as Product;

            Assert.IsNotNull(product, "product");

            var instanceName = this.InstanceName;

            Assert.IsNotNull(instanceName, "instanceName");

            string name = instanceName.Text.EmptyToNull();

            Assert.IsNotNull(name, @"Instance name isn't set");

            var hostName = this.HostName;

            Assert.IsNotNull(hostName, "hostName");

            string host = hostName.Text.EmptyToNull();

            Assert.IsNotNull(host, "Hostname must not be emoty");

            var rootName = this.RootName;

            Assert.IsNotNull(rootName, "rootName");

            string root = rootName.Text.EmptyToNull();

            Assert.IsNotNull(rootName, "Root folder name must not be emoty");

            string location = this.locationFolder.Text.EmptyToNull();

            Assert.IsNotNull(location, @"The location folder isn't set");

            string rootPath           = Path.Combine(location, root);
            bool   locationIsPhysical = FileSystem.FileSystem.Local.Directory.HasDriveLetter(rootPath);

            Assert.IsTrue(locationIsPhysical, "The location folder path must be physical i.e. contain a drive letter. Please choose another location folder");

            string webRootPath = Path.Combine(rootPath, "Website");

            bool websiteExists = WebServerManager.WebsiteExists(name);

            if (websiteExists)
            {
                using (var context = WebServerManager.CreateContext("InstanceDetails.OnMovingNext('{0}')".FormatWith(name)))
                {
                    var site = context.Sites.Single(s => s != null && s.Name.EqualsIgnoreCase(name));
                    var path = WebServerManager.GetWebRootPath(site);
                    if (FileSystem.FileSystem.Local.Directory.Exists(path))
                    {
                        this.Alert("The website with the same name already exists, please choose another instance name.");
                        return(false);
                    }

                    if (
                        WindowHelper.ShowMessage("There website with the same name already exists, but points to non-existing location. Would you like to delete it?",
                                                 MessageBoxButton.OKCancel, MessageBoxImage.Asterisk) != MessageBoxResult.OK)
                    {
                        return(false);
                    }

                    site.Delete();
                    context.CommitChanges();
                }
            }

            websiteExists = WebServerManager.WebsiteExists(name);
            Assert.IsTrue(!websiteExists, "The website with the same name already exists, please choose another instance name.");

            bool hostExists = WebServerManager.HostBindingExists(host);

            Assert.IsTrue(!hostExists, "Website with the same host name already exists");

            bool rootFolderExists = FileSystem.FileSystem.Local.Directory.Exists(rootPath);

            if (rootFolderExists && InstanceManager.Instances != null)
            {
                if (InstanceManager.Instances.Any(i => i != null && i.WebRootPath.EqualsIgnoreCase(webRootPath)))
                {
                    this.Alert("There is another instance with the same root path, please choose another folder");
                    return(false);
                }

                if (WindowHelper.ShowMessage("The folder with the same name already exists. Would you like to delete it?", MessageBoxButton.OKCancel, MessageBoxImage.Question, MessageBoxResult.OK) != MessageBoxResult.OK)
                {
                    return(false);
                }

                FileSystem.FileSystem.Local.Directory.DeleteIfExists(rootPath);
            }

            var connectionString = ProfileManager.GetConnectionString();

            SqlServerManager.Instance.ValidateConnectionString(connectionString);

            string licensePath = ProfileManager.Profile.License;

            Assert.IsNotNull(licensePath, @"The license file isn't set in the Settings window");
            FileSystem.FileSystem.Local.File.AssertExists(licensePath, "The {0} file is missing".FormatWith(licensePath));

            var netFramework = this.NetFramework;

            Assert.IsNotNull(netFramework, "netFramework");

            var framework    = netFramework.SelectedValue.ToString();
            var frameworkArr = framework.Split(' ');

            Assert.IsTrue(frameworkArr.Length > 0, "impossible");

            var force32Bit = frameworkArr.Length == 2;
            var mode       = this.Mode;

            Assert.IsNotNull(mode, "mode");

            var modeItem = (ListBoxItem)mode.SelectedValue;

            Assert.IsNotNull(modeItem, "modeItem");

            var isClassic = ((string)modeItem.Content).EqualsIgnoreCase("Classic");

            var args = (InstallWizardArgs)wizardArgs;

            args.InstanceName             = name;
            args.InstanceHost             = host;
            args.InstanceWebRootPath      = webRootPath;
            args.InstanceRootName         = root;
            args.InstanceRootPath         = rootPath;
            args.InstanceProduct          = product;
            args.InstanceConnectionString = connectionString;
            args.LicenseFileInfo          = new FileInfo(licensePath);
            args.InstanceAppPoolInfo      = new AppPoolInfo
            {
                FrameworkVersion      = frameworkArr[0].EmptyToNull() ?? "v2.0",
                Enable32BitAppOnWin64 = force32Bit,
                ManagedPipelineMode   = !isClassic
            };
            args.Product = product;

            return(true);
        }