Esempio n. 1
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);
        }
        public void SetProfile(SitecoreProfile profile)
        {
            _profile = profile;

            profileTextBox.Text        = profile.Name;
            topologyList.SelectedIndex = topologyList.FindStringExact(profile.Topology);
            versionList.SelectedIndex  = versionList.FindStringExact(profile.Version);
            dataRepoTextBox.Text       = profile.DataFolder;
            licenseFileTextBox.Text    = profile.LicenseFile;

            RebuildFiles();

            validateButton.Text = "Update Profile";
        }
        private void validateButton_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(profileTextBox.Text))
            {
                MessageBox.Show("Need a Profile Name!");
                return;
            }

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

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

            if (string.IsNullOrWhiteSpace(licenseFileTextBox.Text))
            {
                MessageBox.Show("Select a License File");
                return;
            }

            if (string.IsNullOrWhiteSpace(dataRepoTextBox.Text) || !Directory.Exists(dataRepoTextBox.Text))
            {
                MessageBox.Show("Invalid Data File Repo");
                return;
            }

            bool allFilesGood = true;

            foreach (var ctrl in fileGroupBox.Controls)
            {
                if (ctrl is Label lbl)
                {
                    var fullPath = Path.Combine(dataRepoTextBox.Text, lbl.Text);

                    if (File.Exists(fullPath))
                    {
                        lbl.ForeColor = Color.Green;
                    }
                    else
                    {
                        lbl.ForeColor = Color.Red;
                        allFilesGood  = false;
                    }
                }
            }

            if (!allFilesGood)
            {
                MessageBox.Show("One or more required files are missing");
                return;
            }

            //Save our profile
            var currentProfiles = _profileManager.Fetch();

            if (_profile == null)
            {
                var newProfile = new SitecoreProfile
                {
                    Name        = profileTextBox.Text,
                    Topology    = topologyList.SelectedItem.ToString(),
                    Version     = versionList.SelectedItem.ToString(),
                    DataFolder  = dataRepoTextBox.Text,
                    LicenseFile = licenseFileTextBox.Text,
                    Id          = Guid.NewGuid()
                };

                foreach (var ctrl in fileGroupBox.Controls)
                {
                    if (ctrl is Label lbl)
                    {
                        newProfile.Files.Add(lbl.Text);
                    }
                }

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

                profile.Name        = profileTextBox.Text;
                profile.Topology    = topologyList.SelectedItem.ToString();
                profile.Version     = versionList.SelectedItem.ToString();
                profile.DataFolder  = dataRepoTextBox.Text;
                profile.LicenseFile = licenseFileTextBox.Text;

                profile.Files.Clear();

                foreach (var ctrl in fileGroupBox.Controls)
                {
                    if (ctrl is Label lbl)
                    {
                        profile.Files.Add(lbl.Text);
                    }
                }
            }

            _profileManager.Update(currentProfiles);

            this.Close();
        }
Esempio n. 4
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);
        }