using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; namespace Roblox.ClientTools { public class WebsiteConfiguration { private static SqlConnection OpenConnection(string dbServer, string dbPassword) { SqlConnnection myConnection = new SqlConnnection(String.Format("user id=roblox;" + "password={0};server={1};" + "Trusted_Connection=no;" + "database=RobloxReporting;" + "connection timeout=30;", dbPassword, dbServer)); try { myConnection.Open(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); throw; } return myConnection; } public static void GetStringWebsiteConfig(string dbServer, string dbPassword, string group, string setting, out string value, ref string comment) { using (SqlConnection connection = OpenConnection(dbServer, dbPassword)) { SqlCommand command = new SqlCommand( String.Format(@"SELECT Type, Value, Comment FROM Settings WHERE GroupName='{0}' AND Setting='{1}'", group, setting), connection); command.CommandTimeout = 600; SqlDataReader reader = null; try { reader = command.ExecuteReader(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); throw new Exception("Exception when trying to fetch data"); } try { if (!reader.Read()) throw new Exception("Can't find setting in DB"); if (reader["Type"].ToString() != "System.String") throw new Exception("Value is not string"); if (comment != null) comment = (string)reader["Comment"]; value = (string)reader["Value"]; } finally { reader.Close(); } } } public static void UpdateWebsiteConfig(string dbServer, string dbPassword, string group, string setting, string value, string comment) { using (SqlConnection connection = OpenConnection(dbServer, dbPassword)) { SqlCommand command = new SqlCommand( String.Format(@"UPDATE Settings SET Value='{0}', Comment='{1}', WHERE GroupName='{2}' AND Setting='{3}' AND Type='System.String'", value, comment, group, setting), connection); int rows = command.ExecuteNonQuery(); if (rows != 1) throw new Exception(String.Format("Update unsuccessful: {0} rows updated", rows)); } } } }