public bool Validate(SqlProfile profile) { var sqlBuilder = new SqlConnectionStringBuilder { DataSource = profile.ServerName, UserID = profile.Login, Password = profile.Password }; using (var connection = new SqlConnection(sqlBuilder.ConnectionString)) { try { connection.Open(); var command = new SqlCommand("SELECT @@VERSION", connection); var result = command.ExecuteScalar().ToString(); if (result.IndexOf("SQL Server 2016") >= 0 || result.IndexOf("SQL Server 2017") >= 0) { return(true); } ErrorMessage = $"Invalid Version: {result}"; return(false); } catch (Exception ex) { ErrorMessage = ex.Message; return(false); } } }
public bool Validate(SqlProfile profile) { var sqlBuilder = new SqlConnectionStringBuilder { DataSource = profile.ServerName, UserID = profile.Login, Password = profile.Password }; using (var connection = new SqlConnection(sqlBuilder.ConnectionString)) { try { connection.Open(); var command = new SqlCommand("SELECT has_perms_by_name(null, null, 'CREATE ANY DATABASE')", connection); var result = command.ExecuteScalar().ToString(); if (result != "1") { ErrorMessage = "Unable to create databases"; return(false); } return(true); } catch (Exception ex) { ErrorMessage = "Error testing database creation: " + ex.Message; return(false); } } }
public void SetProfile(SqlProfile profile) { _profile = profile; profileTextBox.Text = profile.Name; connectionNameTextBox.Text = profile.ServerName; loginTextBox.Text = profile.Login; passwordTextBox.Text = profile.Password; validateButton.Text = "Update Profile"; }
protected void btnSubmit_Click(object sender, EventArgs e) { int n = SqlProfile.Update(); if (n == 1) { Response.Write("<script>alert('Profile Updated Successfully...')</script>"); PanelFixed.Visible = false; PanelProfile.Visible = true; } }
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 bool Validate(SqlProfile profile) { var sqlBuilder = new SqlConnectionStringBuilder { DataSource = profile.ServerName, UserID = profile.Login, Password = profile.Password }; using (var connection = new SqlConnection(sqlBuilder.ConnectionString)) { try { connection.Open(); return(true); } catch (Exception ex) { ErrorMessage = ex.Message; return(false); } } }
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); }
private void validateButton_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(profileTextBox.Text)) { MessageBox.Show("Need a Profile Name!"); return; } if (string.IsNullOrWhiteSpace(connectionNameTextBox.Text)) { MessageBox.Show("Enter a Server"); return; } if (string.IsNullOrWhiteSpace(loginTextBox.Text)) { MessageBox.Show("Enter a Login"); return; } if (string.IsNullOrWhiteSpace(passwordTextBox.Text)) { MessageBox.Show("Enter a Password"); return; } var sqlProfile = new SqlProfile { Name = profileTextBox.Text, ServerName = connectionNameTextBox.Text, Login = loginTextBox.Text, Password = passwordTextBox.Text }; for (var i = 0; i < _validators.Count; i++) { var validator = _validators[i]; var isValid = validator.Validate(sqlProfile); 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 sifProfiles = _profileManager.Fetch(); if (_profile == null) { sqlProfile.Id = Guid.NewGuid(); sifProfiles.SqlProfiles.Add(sqlProfile); } else { var profile = sifProfiles.SqlProfiles.Find(p => p.Id == _profile.Id); profile.Name = profileTextBox.Text; profile.ServerName = connectionNameTextBox.Text; profile.Login = loginTextBox.Text; profile.Password = passwordTextBox.Text; } _profileManager.Update(sifProfiles); this.Close(); }