public string GetConfigurationTemplate(string template, IDictionary <string, string> parameters) { var settings = Settings.Parse(template); new Populator(parameters).Populate(settings); TextBox SQLServer = settings.Find("SQLServer") as TextBox; SQLServer.HelpText = string.Empty; TextBox SQLUser = settings.Find("SQLUser") as TextBox; CheckBox SQLUseSQLAuth = settings.Find("SQLUseSQLAuth") as CheckBox; TextBox SQLPassword = settings.Find("SQLPassword") as TextBox; SQLPassword.Visible = SQLUseSQLAuth.Value; string errorMessage = ""; IList <string> databases = SQLHelpers.GetDatabases(SQLServer, SQLUser, SQLUseSQLAuth, this.decrypt(SQLPassword.Value), out errorMessage); DropDown SQLDatabase = settings.Find("SQLDatabase") as DropDown; SQLDatabase.Options = databases.Select(i => new Option() { DisplayMemeber = i, ValueMemeber = i }).ToList(); if (!String.IsNullOrWhiteSpace(SQLDatabase.Value)) { IList <string> tables = SQLHelpers.GetTables(SQLServer, SQLUser, SQLUseSQLAuth, this.decrypt(SQLPassword.Value), SQLDatabase, out errorMessage); DropDown SQLTable = settings.Find("SQLTable") as DropDown; SQLTable.Options = tables.Select(i => new Option() { DisplayMemeber = i, ValueMemeber = i }).ToList(); if (tables.Contains(SQLTable.Value) == false) { SQLTable.Value = ""; } if (!String.IsNullOrWhiteSpace(SQLTable.Value)) { IList <DataColumn> columns = SQLHelpers.GetColumns(SQLServer.Value, SQLUser.Value, SQLUseSQLAuth.Value, this.decrypt(SQLPassword.Value), SQLDatabase.Value, SQLTable.Value); DropDown SQLTimestampColumn = settings.Find("SQLTimestampColumn") as DropDown; SQLTimestampColumn.Options = columns.Select(i => new Option() { DisplayMemeber = i.ColumnName, ValueMemeber = i.ColumnName }).ToList(); if (columns.Any(c => c.ColumnName == SQLTimestampColumn.Value) == false) { SQLTimestampColumn.Value = ""; } } } if (!String.IsNullOrWhiteSpace(errorMessage)) { SQLServer.HelpText = errorMessage; } return(settings.ToString()); }
public string[] Validate(IDictionary <string, string> parameters) { int i = 1; var errors = new List <string>(); this.config = new Configuration() { Parameters = parameters }; if (String.IsNullOrWhiteSpace(this.SQLServer)) { errors.Add($"Error {i++}: SQL Server is not specified."); } if (String.IsNullOrWhiteSpace(this.SQLUser)) { errors.Add($"Error {i++}: Username is not specified."); } if (this.SQLUseSQLAuth && String.IsNullOrWhiteSpace(this.SQLPassword)) { errors.Add($"Error {i++}: Password is not specified."); } if (String.IsNullOrWhiteSpace(this.SQLDatabase)) { errors.Add($"Error {i++}: Database is not specified."); } if (this.UsingStoredProc && String.IsNullOrWhiteSpace(this.StoredProc)) { errors.Add($"Error {i++}: Stored Procedure is not specified."); } if (!this.UsingStoredProc && String.IsNullOrWhiteSpace(this.SQLTable)) { errors.Add($"Error {i++}: Table is not specified."); } if (errors.Any() == false) { var errorMessage = ""; var server = new TextBox() { Value = this.SQLServer }; if (!this.UsingStoredProc && this.CreateTable == false) { IList <string> tables = SQLHelpers.GetTables(server, new TextBox() { Value = this.SQLUser }, new CheckBox() { Value = this.SQLUseSQLAuth }, this.SQLPassword, new DropDown() { Value = this.SQLDatabase }, out errorMessage); if (string.IsNullOrWhiteSpace(errorMessage) == false) { errors.Add($"Error {i++}: {errorMessage}"); return(errors.ToArray()); } if (tables.Any(d => d == this.SQLTable) == false) { errors.Add($"Error {i++}: Table '{this.SQLTable}' cannot be found in {this.SQLDatabase}."); } } } return(errors.ToArray()); }
public string GetConfigurationTemplate(string template, IDictionary <string, string> parameters) { var settings = Settings.Parse(template); new Populator(parameters).Populate(settings); CheckBox UseConnectionVariables = (CheckBox)settings.Find("UseConnectionVariables"); TextBox SQLServer = settings.Find("SQLServer") as TextBox; SQLServer.HelpText = string.Empty; TextBox SQLUser = settings.Find("SQLUser") as TextBox; SQLServer.Visible = SQLUser.Visible = (UseConnectionVariables.Value == false); CheckBox SQLUseSQLAuth = settings.Find("SQLUseSQLAuth") as CheckBox; TextBox SQLPassword = settings.Find("SQLPassword") as TextBox; SQLPassword.Visible = !UseConnectionVariables.Value && SQLUseSQLAuth.Value; VariableBox vSQLServer = settings.Find("vSQLServer") as VariableBox; vSQLServer.HelpText = string.Empty; VariableBox vSQLUser = settings.Find("vSQLUser") as VariableBox; vSQLServer.Visible = vSQLUser.Visible = (UseConnectionVariables.Value == true); VariableBox vSQLPassword = settings.Find("vSQLPassword") as VariableBox; vSQLPassword.Visible = UseConnectionVariables.Value && SQLUseSQLAuth.Value; string errorMessage = ""; TextBox sqlServer = SQLServer; TextBox sqlUser = SQLUser; TextBox sqlPassword = SQLPassword; if (UseConnectionVariables.Value) { sqlServer = new TextBox() { Value = GetVariableValue(vSQLServer.Value) }; sqlUser = new TextBox() { Value = GetVariableValue(vSQLUser.Value) }; if (SQLUseSQLAuth.Value) { sqlPassword = new TextBox() { Value = GetVariableValue(vSQLPassword.Value) } } ; } IList <string> databases = SQLHelpers.GetDatabases(sqlServer, sqlUser, SQLUseSQLAuth, this.decrypt(sqlPassword.Value), out errorMessage); DropDown SQLDatabase = settings.Find("SQLDatabase") as DropDown; SQLDatabase.Options = databases.Select(i => new Option() { DisplayMemeber = i, ValueMemeber = i }).ToList(); CheckBox UsingStoredProc = settings.Find("UsingStoredProc") as CheckBox; DropDown StoredProc = settings.Find("StoredProc") as DropDown; CheckBox CreateTable = settings.Find("CreateTable") as CheckBox; TextBox SQLTableNew = settings.Find("SQLTableNew") as TextBox; DropDown SQLTable = settings.Find("SQLTable") as DropDown; CheckBox AllowTriggers = settings.Find("AllowTriggers") as CheckBox; if (UsingStoredProc.Value == true) { StoredProc.Visible = true; CreateTable.Visible = SQLTableNew.Visible = SQLTable.Visible = AllowTriggers.Visible = false; } else { StoredProc.Visible = false; CreateTable.Visible = AllowTriggers.Visible = true; SQLTableNew.Visible = (CreateTable.Value == true); SQLTable.Visible = (CreateTable.Value == false); } if (!String.IsNullOrWhiteSpace(SQLDatabase.Value)) { IList <string> tables = SQLHelpers.GetTables(sqlServer, sqlUser, SQLUseSQLAuth, this.decrypt(sqlPassword.Value), SQLDatabase, out errorMessage); SQLTable.Options = tables.Select(i => new Option() { DisplayMemeber = i, ValueMemeber = i }).ToList(); if (tables.Contains(SQLTable.Value) == false) { SQLTable.Value = ""; } var storedprocs = SQLHelpers.GetStoredProcs(sqlServer, sqlUser, SQLUseSQLAuth, this.decrypt(sqlPassword.Value), SQLDatabase, out errorMessage); StoredProc.Options = storedprocs.Select(i => new Option() { DisplayMemeber = i, ValueMemeber = i }).ToList(); if (storedprocs.Contains(StoredProc.Value) == false) { StoredProc.Value = ""; } } if (!String.IsNullOrWhiteSpace(errorMessage)) { SQLServer.HelpText = vSQLServer.HelpText = errorMessage; } return(settings.ToString()); }
public string GetConfigurationTemplate(string template, IDictionary <string, string> parameters) { var settings = Settings.Parse(template); new Populator(parameters).Populate(settings); CheckBox UseConnectionVariables = (CheckBox)settings.Find("UseConnectionVariables"); TextBox SQLServer = settings.Find("SQLServer") as TextBox; SQLServer.HelpText = string.Empty; TextBox SQLUser = settings.Find("SQLUser") as TextBox; SQLServer.Visible = SQLUser.Visible = (UseConnectionVariables.Value == false); CheckBox SQLUseSQLAuth = settings.Find("SQLUseSQLAuth") as CheckBox; TextBox SQLPassword = settings.Find("SQLPassword") as TextBox; SQLPassword.Visible = !UseConnectionVariables.Value && SQLUseSQLAuth.Value; VariableBox vSQLServer = settings.Find("vSQLServer") as VariableBox; vSQLServer.HelpText = string.Empty; VariableBox vSQLUser = settings.Find("vSQLUser") as VariableBox; vSQLServer.Visible = vSQLUser.Visible = (UseConnectionVariables.Value == true); VariableBox vSQLPassword = settings.Find("vSQLPassword") as VariableBox; vSQLPassword.Visible = UseConnectionVariables.Value && SQLUseSQLAuth.Value; string errorMessage = ""; TextBox sqlServer = SQLServer; TextBox sqlUser = SQLUser; TextBox sqlPassword = SQLPassword; if (UseConnectionVariables.Value) { sqlServer = new TextBox() { Value = GetVariableValue(vSQLServer.Value) }; sqlUser = new TextBox() { Value = GetVariableValue(vSQLUser.Value) }; if (SQLUseSQLAuth.Value) { sqlPassword = new TextBox() { Value = GetVariableValue(vSQLPassword.Value) } } ; } IList <string> databases = SQLHelpers.GetDatabases(sqlServer, sqlUser, SQLUseSQLAuth, this.decrypt(sqlPassword.Value), out errorMessage); DropDown SQLDatabase = settings.Find("SQLDatabase") as DropDown; SQLDatabase.Options = databases.Select(i => new Option() { DisplayMemeber = i, ValueMemeber = i }).ToList(); if (!String.IsNullOrWhiteSpace(SQLDatabase.Value)) { IList <string> tables = SQLHelpers.GetTables(sqlServer, sqlUser, SQLUseSQLAuth, this.decrypt(sqlPassword.Value), SQLDatabase, out errorMessage); DropDown SQLTable = settings.Find("SQLTable") as DropDown; SQLTable.Options = tables.Select(i => new Option() { DisplayMemeber = i, ValueMemeber = i }).ToList(); if (tables.Contains(SQLTable.Value) == false) { SQLTable.Value = ""; } if (!String.IsNullOrWhiteSpace(SQLTable.Value)) { IList <DataColumn> columns = SQLHelpers.GetColumns(sqlServer.Value, sqlUser.Value, SQLUseSQLAuth.Value, this.decrypt(sqlPassword.Value), SQLDatabase.Value, SQLTable.Value); DropDown SQLTimestampColumn = settings.Find("SQLTimestampColumn") as DropDown; SQLTimestampColumn.Options = columns.Select(i => new Option() { DisplayMemeber = i.ColumnName, ValueMemeber = i.ColumnName }).ToList(); if (columns.Any(c => c.ColumnName == SQLTimestampColumn.Value) == false) { SQLTimestampColumn.Value = ""; } TokenBox SQLColumns = settings.Find("SQLColumns") as TokenBox; SQLColumns.Options = columns.Select(c => new Option() { DisplayMemeber = c.ColumnName, ValueMemeber = c.ColumnName }).ToList(); if (columns.Count > 0 && !String.IsNullOrEmpty(SQLColumns.Value)) { SQLColumns.Value = String.Join(",", SQLColumns.Value.Split(',').Where(c => columns.Any(col => c == col.ColumnName))); } } } if (!String.IsNullOrWhiteSpace(errorMessage)) { SQLServer.HelpText = vSQLServer.HelpText = errorMessage; } return(settings.ToString()); }
public string[] Validate(IDictionary <string, string> parameters) { int i = 1; var errors = new List <string>(); this.config = new Configuration() { Parameters = parameters }; if (String.IsNullOrWhiteSpace(this.SQLServer)) { errors.Add($"Error {i++}: SQL Server is not specified."); } if (String.IsNullOrWhiteSpace(this.SQLUser)) { errors.Add($"Error {i++}: Username is not specified."); } if (this.SQLUseSQLAuth && String.IsNullOrWhiteSpace(this.SQLPassword)) { errors.Add($"Error {i++}: Password is not specified."); } if (String.IsNullOrWhiteSpace(this.SQLDatabase)) { errors.Add($"Error {i++}: Database is not specified."); } if (String.IsNullOrWhiteSpace(this.SQLTable)) { errors.Add($"Error {i++}: Table is not specified."); } if (String.IsNullOrWhiteSpace(this.SQLTimestampColumn)) { errors.Add($"Error {i++}: Timestamp Column is not specified."); } if (errors.Any() == false) { var errorMessage = ""; var server = new TextBox() { Value = this.SQLServer }; IList <string> tables = SQLHelpers.GetTables(server, new TextBox() { Value = this.SQLUser }, new CheckBox() { Value = this.SQLUseSQLAuth }, this.SQLPassword, new DropDown() { Value = this.SQLDatabase }, out errorMessage); if (string.IsNullOrWhiteSpace(errorMessage) == false) { errors.Add($"Error {i++}: {errorMessage}"); return(errors.ToArray()); } if (tables.Any(d => d == this.SQLTable) == false) { errors.Add($"Error {i++}: Table '{this.SQLTable}' cannot be found in {this.SQLDatabase}."); } try { var cols = SQLHelpers.GetColumns(this.SQLServer, this.SQLUser, this.SQLUseSQLAuth, this.SQLPassword, this.SQLDatabase, this.SQLTable); if (cols.Any(d => d.ColumnName == this.SQLTimestampColumn) == false) { errors.Add($"Error {i++}: Timestamp Column '{this.SQLTimestampColumn}' cannot be found in {this.SQLTable}."); } } catch (Exception ex) { errors.Add($"Error {i++}: Could not retrieve the list of colmuns for '{this.SQLTable}' - {ex.Message}"); } } return(errors.ToArray()); }
public string GetConfigurationTemplate(string template, IDictionary <string, string> parameters) { var settings = Settings.Parse(template); new Populator(parameters).Populate(settings); CheckBox UseConnectionVariables = (CheckBox)settings.Find("UseConnectionVariables"); TextBox SQLServer = settings.Find("SQLServer") as TextBox; SQLServer.HelpText = string.Empty; TextBox SQLUser = settings.Find("SQLUser") as TextBox; SQLServer.Visible = SQLUser.Visible = (UseConnectionVariables.Value == false); CheckBox SQLUseSQLAuth = settings.Find("SQLUseSQLAuth") as CheckBox; TextBox SQLPassword = settings.Find("SQLPassword") as TextBox; SQLPassword.Visible = !UseConnectionVariables.Value && SQLUseSQLAuth.Value; VariableBox vSQLServer = settings.Find("vSQLServer") as VariableBox; vSQLServer.HelpText = string.Empty; VariableBox vSQLUser = settings.Find("vSQLUser") as VariableBox; vSQLServer.Visible = vSQLUser.Visible = (UseConnectionVariables.Value == true); VariableBox vSQLPassword = settings.Find("vSQLPassword") as VariableBox; vSQLPassword.Visible = UseConnectionVariables.Value && SQLUseSQLAuth.Value; string errorMessage = ""; TextBox sqlServer = SQLServer; TextBox sqlUser = SQLUser; TextBox sqlPassword = SQLPassword; if (UseConnectionVariables.Value) { sqlServer = new TextBox() { Value = GetVariableValue(vSQLServer.Value) }; sqlUser = new TextBox() { Value = GetVariableValue(vSQLUser.Value) }; if (SQLUseSQLAuth.Value) { sqlPassword = new TextBox() { Value = GetVariableValue(vSQLPassword.Value) } } ; } IList <string> databases = SQLHelpers.GetDatabases(sqlServer, sqlUser, SQLUseSQLAuth, this.decrypt(sqlPassword.Value), out errorMessage); DropDown SQLDatabase = settings.Find("SQLDatabase") as DropDown; SQLDatabase.Options = databases.Select(i => new Option() { DisplayMemeber = i, ValueMemeber = i }).ToList(); if (!String.IsNullOrWhiteSpace(SQLDatabase.Value)) { IList <string> tables = SQLHelpers.GetTables(sqlServer, sqlUser, SQLUseSQLAuth, this.decrypt(sqlPassword.Value), SQLDatabase, out errorMessage); DropDown SQLTable = settings.Find("SQLTable") as DropDown; SQLTable.Options = tables.Select(i => new Option() { DisplayMemeber = i, ValueMemeber = i }).ToList(); if (tables.Contains(SQLTable.Value) == false) { SQLTable.Value = ""; } if (!String.IsNullOrWhiteSpace(SQLTable.Value)) { IList <DataColumn> columns = SQLHelpers.GetColumns(sqlServer.Value, sqlUser.Value, SQLUseSQLAuth.Value, this.decrypt(sqlPassword.Value), SQLDatabase.Value, SQLTable.Value); TokenBox SQLColumns = settings.Find("SQLColumns") as TokenBox; SQLColumns.Options = columns.Select(c => new Option() { DisplayMemeber = c.ColumnName, ValueMemeber = c.ColumnName }).ToList(); if (columns.Count > 0 && !String.IsNullOrEmpty(SQLColumns.Value)) { SQLColumns.Value = String.Join(",", SQLColumns.Value.Split(',').Where(c => columns.Any(col => c == col.ColumnName))); } XMIoT.Framework.Settings.Filter Filters = settings.Find("Filters") as XMIoT.Framework.Settings.Filter; Filters.Fields = columns.Select(i => new TypedOption() { Type = i.DataType.GetIoTType(), DisplayMemeber = i.ColumnName, ValueMemeber = i.ColumnName }).ToList(); Grid SortGrid = settings.Find("SortGrid") as Grid; DropDown SortColumn = SortGrid.Columns.First(s => s.Key == "SortColumn") as DropDown; SortColumn.Options = columns.Select(i => new Option() { DisplayMemeber = i.ColumnName, ValueMemeber = i.ColumnName }).ToList(); var newRows = new JArray(); var rows = SortGrid.Rows?.ToList() ?? new List <IDictionary <string, object> >(); foreach (var row in rows) { if (columns.Select(c => c.ColumnName).Contains(row["SortColumn"].ToString()) == true) { newRows.Add(JObject.FromObject(row)); } } SortGrid.Value = newRows.ToString(); } } if (!String.IsNullOrWhiteSpace(errorMessage)) { SQLServer.HelpText = vSQLServer.HelpText = errorMessage; } return(settings.ToString()); }