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

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

                if (defaultRootFolder != null)
                {
                    instancesFolder = defaultRootFolder.ToLower();
                }

                IEnumerable <Site> sites   = context.Sites;
                var detectEverywhereResult = detectEverywhere ?? Settings.CoreInstancesDetectEverywhere.Value;
                if (!detectEverywhereResult)
                {
                    if (string.IsNullOrEmpty(instancesFolder))
                    {
                        Log.Warn("Since the 'Detect.Instances.Everywhere' setting is disabled and the instances root isn't set in the Settings dialog, the 'C:\\inetpub\\wwwroot' will be used instead", typeof(InstanceManager));

                        instancesFolder = @"C:\inetpub\wwwroot";
                    }

                    instancesFolder = instancesFolder.ToLower();
                    sites           = sites.Where(s => WebServerManager.GetWebRootPath(s).ToLower().Contains(instancesFolder));
                }

                return(ProfileSection.Result(sites));
            }
        }
        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));
            }
        }
        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);
        }
Ejemplo n.º 4
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);
        }