Exemplo n.º 1
0
        public static Message MsSqlSelect(this Message message, MsSqlConnectionConfig config, string selectStatement)
        {
            Logger.Debug("Step");

            var adapter = new SqlDataAdapter(selectStatement, config.ToConnectionString());
            var dataSet = new DataSet();
            adapter.Fill(dataSet, "ResultTable");
            var result = new XDocument(new XElement("MsSqlSelectResult"));
            foreach (DataTable table in dataSet.Tables)
            {
                var doc = new XElement(table.TableName);
                foreach (DataRow row in table.Rows)
                {
                    var xmlRow = new XElement("Row");
                    foreach (DataColumn column in table.Columns)
                    {
                        xmlRow.Add(new XElement(column.ColumnName, row[column.Ordinal].ToString()));
                    }
                    doc.Add(xmlRow);
                }
                result.Root.Add(doc);
            }
            message.SetPayload(result.ToString());
            return message;
        }
Exemplo n.º 2
0
        public static Message MsSqlSelect(this Message message, MsSqlConnectionConfig config, string selectStatement)
        {
            Logger.Debug("Step");

            var adapter = new SqlDataAdapter(selectStatement, config.ToConnectionString());
            var dataSet = new DataSet();

            adapter.Fill(dataSet, "ResultTable");
            var result = new XDocument(new XElement("MsSqlSelectResult"));

            foreach (DataTable table in dataSet.Tables)
            {
                var doc = new XElement(table.TableName);
                foreach (DataRow row in table.Rows)
                {
                    var xmlRow = new XElement("Row");
                    foreach (DataColumn column in table.Columns)
                    {
                        xmlRow.Add(new XElement(column.ColumnName, row[column.Ordinal].ToString()));
                    }
                    doc.Add(xmlRow);
                }
                result.Root.Add(doc);
            }
            message.SetPayload(result.ToString());
            return(message);
        }
Exemplo n.º 3
0
        public static Message MsSqlSelect(this Message message, string selectStatement)
        {
            if (!message.Variables.ContainsKey("Db.Host") ||
                !message.Variables.ContainsKey("Db.Port") ||
                !message.Variables.ContainsKey("Db.Username") ||
                !message.Variables.ContainsKey("Db.Password") ||
                !message.Variables.ContainsKey("Db.Database"))
                throw new InvalidOperationException("Configuration incorrect");

            var config = new MsSqlConnectionConfig
            {
                Host = message.Variables["Db.Host"].ToString(),
                Port = int.Parse(message.Variables["Db.Port"].ToString()),
                Username = message.Variables["Db.Username"].ToString(),
                Password = message.Variables["Db.Password"].ToString(),
                Database = message.Variables["Db.Database"].ToString()
            };
            return message.MsSqlSelect(config, selectStatement);
        }
Exemplo n.º 4
0
        public static Message MsSqlSelect(this Message message, string selectStatement)
        {
            if (!message.Variables.ContainsKey("Db.Host") ||
                !message.Variables.ContainsKey("Db.Port") ||
                !message.Variables.ContainsKey("Db.Username") ||
                !message.Variables.ContainsKey("Db.Password") ||
                !message.Variables.ContainsKey("Db.Database"))
            {
                throw new InvalidOperationException("Configuration incorrect");
            }

            var config = new MsSqlConnectionConfig
            {
                Host     = message.Variables["Db.Host"].ToString(),
                Port     = int.Parse(message.Variables["Db.Port"].ToString()),
                Username = message.Variables["Db.Username"].ToString(),
                Password = message.Variables["Db.Password"].ToString(),
                Database = message.Variables["Db.Database"].ToString()
            };

            return(message.MsSqlSelect(config, selectStatement));
        }