Exemple #1
0
        public IEnumerable <XMIoT.Framework.Attribute> GetOutputAttributes(string endpoint, IDictionary <string, string> parameters)
        {
            this.config = new Configuration()
            {
                Parameters = parameters
            };
            string connectionStr = SQLHelpers.GetConnectionString(this.SQLServer, this.SQLUser, this.SQLPassword, this.SQLUseSQLAuth, this.SQLDatabase);

            if (string.IsNullOrWhiteSpace(connectionStr))
            {
                return(new XMIoT.Framework.Attribute[0]);
            }
            else
            {
                IList <DataColumn> columns = SQLHelpers.GetColumns(this.SQLServer, this.SQLUser, this.SQLUseSQLAuth, this.SQLPassword, this.SQLDatabase, this.SQLTable);
                if (!String.IsNullOrWhiteSpace(this.SQLColumns))
                {
                    return(columns.Where(c => this.SQLColumns.Split(',').Contains(c.ColumnName)).Select(c => new XMIoT.Framework.Attribute(c.ColumnName, c.DataType.GetIoTType())));
                }
                else
                {
                    return(columns.Select(c => new XMIoT.Framework.Attribute(c.ColumnName, c.DataType.GetIoTType())));
                }
            }
        }
        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 IEnumerable <XMIoT.Framework.Attribute> GetOutputAttributes(string endpoint, IDictionary <string, string> parameters)
 {
     this.config = new Configuration()
     {
         Parameters = parameters
     };
     return(SQLHelpers.GetColumns(this.SQLServer, this.SQLUser, this.SQLUseSQLAuth, this.SQLPassword, this.SQLDatabase, this.SQLTable)
            .Select(col => new XMIoT.Framework.Attribute(col.ColumnName, col.DataType.GetIoTType())));
 }
Exemple #4
0
 public IEnumerable <XMIoT.Framework.Attribute> GetInputAttributes(string endpoint, IDictionary <string, string> parameters)
 {
     this.config = new Configuration()
     {
         Parameters = parameters
     };
     if (CreateTable == false)
     {
         return(SQLHelpers.GetColumns(this.SQLServer, this.SQLUser, this.SQLUseSQLAuth, this.SQLPassword, this.SQLDatabase, this.SQLTable)
                .Where(c => !c.AutoIncrement && !c.ReadOnly)
                .Select(col => new XMIoT.Framework.Attribute(col.ColumnName, col.DataType.GetIoTType())));
     }
     else
     {
         return(new XMIoT.Framework.Attribute[0]);
     }
 }
 public IEnumerable <XMIoT.Framework.Attribute> GetOutputAttributes(string endpoint, IDictionary <string, string> parameters)
 {
     this.config = new Configuration()
     {
         Parameters = parameters
     };
     if (UsingStoredProc)
     {
         return(SQLHelpers.GetStoredProcParams(this.SQLServer, this.SQLUser, this.SQLUseSQLAuth, this.SQLPassword, this.SQLDatabase, this.StoredProc)
                .Select(p => new XMIoT.Framework.Attribute(p.ParameterName.TrimStart(new char[] { '@' }), SQLHelpers.GetSystemType(p.DbType).GetIoTType())));
     }
     else if (CreateTable == false)
     {
         return(SQLHelpers.GetColumns(this.SQLServer, this.SQLUser, this.SQLUseSQLAuth, this.SQLPassword, this.SQLDatabase, this.SQLTable)
                .Select(col => new XMIoT.Framework.Attribute(col.ColumnName, col.DataType.GetIoTType())));
     }
     else
     {
         return(ParentOutputs);
     }
 }
Exemple #6
0
        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());
        }
Exemple #7
0
        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());
        }
Exemple #8
0
        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());
        }