Esempio n. 1
0
        public bool Validate(SolrProfile profile)
        {
            var minVersion = Version.Parse(ConfigurationManager.AppSettings["SolrRequiredVersion"]);

            using (var client = new HttpClient())
            {
                using (var response = client.GetAsync(profile.Url + "/admin/info/system").Result)
                {
                    using (var content = response.Content)
                    {
                        var responseXML = content.ReadAsStringAsync().Result;

                        var responseDoc = new XmlDocument();
                        responseDoc.LoadXml(responseXML);

                        var versionNode =
                            responseDoc.SelectSingleNode("//response/lst[@name='lucene']/str[@name='solr-spec-version']");

                        var versionText = versionNode.InnerText;

                        var runningVersion = Version.Parse(versionText);

                        if (runningVersion < minVersion)
                        {
                            ErrorMessage = $"Invalid Solr Version: [{runningVersion}] (Expected: {minVersion}";
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Esempio n. 2
0
        public bool Validate(SolrProfile profile)
        {
            try
            {
                if (!profile.Url.ToLower().StartsWith("https"))
                {
                    ErrorMessage = "URL should start with 'https'";
                    return(false);
                }

                if (!profile.Url.ToLower().EndsWith("/solr"))
                {
                    ErrorMessage = "Url should end at /solr";
                    return(false);
                }

                var request = WebRequest.Create(profile.Url + "/admin/info/system");

                var response = (HttpWebResponse)request.GetResponse();

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    ErrorMessage = "Non-Ok Response in Url Check: " + response.StatusDescription;
                    return(false);
                }

                return(true);
            }
            catch (Exception ex)
            {
                ErrorMessage = "Error checking URL: " + ex.Message;
                return(false);
            }
        }
Esempio n. 3
0
        public void SetProfile(SolrProfile profile)
        {
            _profile                     = profile;
            profileTextBox.Text          = profile.Name;
            urlTextBox.Text              = profile.Url;
            serviceComboBox.SelectedItem = profile.ServiceName;
            corePathTextBox.Text         = profile.CorePath;

            validateButton.Text = "Update Profile";
        }
Esempio n. 4
0
        public bool Validate(SolrProfile profile)
        {
            using (var sc = new ServiceController(profile.ServiceName))
            {
                if (sc.Status != ServiceControllerStatus.Running)
                {
                    ErrorMessage = $"Service Not in Running State: State={sc.Status.ToString()}";
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 5
0
        public bool Validate(SolrProfile profile)
        {
            if (!Directory.Exists(profile.CorePath))
            {
                ErrorMessage = "Core Directory doesn't exist";
                return(false);
            }

            var solrxmlPath = Path.Combine(profile.CorePath.EnsureEndsWith("\\"), "server\\solr\\solr.xml");

            if (!File.Exists(solrxmlPath))
            {
                ErrorMessage = $"Couldn't find solr.xml in Core Folder: [{solrxmlPath}]";
                return(false);
            }

            return(true);
        }
Esempio n. 6
0
        private static string ReplaceAllBaseBookmarks(string wrapperContents, string prefix, SitecoreProfile scProfile, SqlProfile sqlProfile, SolrProfile solrProfile)
        {
            var input = wrapperContents;

            input = input.Replace("[PREFIX]", prefix);
            input = input.Replace("[DATA_FOLDER]", scProfile.DataFolder);
            input = input.Replace("[LICENSE_FILE]", scProfile.LicenseFile);

            //Solr
            input = input.Replace("[SOLR_URL]", solrProfile.Url);
            input = input.Replace("[SOLR_ROOT]", solrProfile.CorePath);
            input = input.Replace("[SOLR_SERVICE]", solrProfile.ServiceName);

            //sql
            input = input.Replace("[SQL_SERVER]", sqlProfile.ServerName);
            input = input.Replace("[SQL_USER]", sqlProfile.Login);
            input = input.Replace("[SQL_PASSWORD]", sqlProfile.Password);

            return(input);
        }
Esempio n. 7
0
        public static string Generate(string prefix, SitecoreProfile scProfile, SqlProfile sqlProfile, SolrProfile solrProfile, NameValueCollection values)
        {
            var configuration = Utility.GetInstanceConfiguration(scProfile.Topology, scProfile.Version);

            var wrapperPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, configuration.Wrapper);

            if (!ioFile.Exists(wrapperPath))
            {
                //TODO
                throw new Exception("Couldn't find Wrapper: " + wrapperPath);
            }

            var wrapper = ioFile.ReadAllText(wrapperPath);


            var allMaps = new Dictionary <string, List <ScriptMap> >();

            foreach (var mapType in configuration.ScriptMapNames.Split('|'))
            {
                allMaps.Add(mapType, new List <ScriptMap>());
            }

            var configScriptMaps = configuration.ScriptMaps;

            foreach (var scriptMap in configScriptMaps.ScriptMapList)
            {
                allMaps[scriptMap.Location].Add(scriptMap);
            }

            foreach (var file in configuration.Files.Where(f => f.Type == "config"))
            {
                foreach (var scriptMap in file.ScriptMaps.ScriptMapList)
                {
                    allMaps[scriptMap.Location].Add(scriptMap);
                }
            }

            foreach (var mapType in allMaps)
            {
                var scriptText = new StringBuilder();
                allMaps[mapType.Key].ForEach(st => scriptText.Append(st.Text));
                wrapper = wrapper.Replace($"[{mapType.Key}]", scriptText.ToString());
            }

            var wrapperWithBaseBooks = ReplaceAllBaseBookmarks(wrapper, prefix, scProfile, sqlProfile, solrProfile);

            foreach (string key in values.Keys)
            {
                wrapperWithBaseBooks = wrapperWithBaseBooks.Replace($"[{key}]", values[key]);
            }

            return(wrapperWithBaseBooks);
        }
Esempio n. 8
0
        private void validateButton_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(profileTextBox.Text))
            {
                MessageBox.Show("Enter a Profile Name!");
                return;
            }

            if (string.IsNullOrWhiteSpace(urlTextBox.Text))
            {
                MessageBox.Show("Enter a Url");
                return;
            }

            if (serviceComboBox.SelectedItem == null)
            {
                MessageBox.Show("Select a Service");
                return;
            }

            if (string.IsNullOrWhiteSpace(corePathTextBox.Text))
            {
                MessageBox.Show("Enter a Core Path");
                return;
            }

            var solrProfile = new SolrProfile
            {
                Name        = profileTextBox.Text,
                Url         = urlTextBox.Text,
                ServiceName = serviceComboBox.SelectedItem.ToString(),
                CorePath    = corePathTextBox.Text
            };

            for (var i = 0; i < _validators.Count; i++)
            {
                var validator = _validators[i];

                var isValid = validator.Validate(solrProfile);

                if (isValid)
                {
                    _validatorLabels[i].ForeColor = Color.Green;
                }
                else
                {
                    _validatorLabels[i].ForeColor = Color.Red;

                    MessageBox.Show(validator.ErrorMessage, "Validation Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    //Stop.
                    return;
                }
            }


            var currentProfiles = _profileManager.Fetch();

            if (_profile == null)
            {
                solrProfile.Id = Guid.NewGuid();

                currentProfiles.SolrProfiles.Add(solrProfile);
            }
            else
            {
                var profile = currentProfiles.SolrProfiles.Find(p => p.Id == _profile.Id);

                profile.Name        = profileTextBox.Text;
                profile.Url         = urlTextBox.Text;
                profile.ServiceName = serviceComboBox.SelectedItem.ToString();
                profile.CorePath    = corePathTextBox.Text;
            }


            _profileManager.Update(currentProfiles);

            this.Close();
        }