public override IEnumerable<Row> Execute(IEnumerable<Row> rows)
        {
            foreach (var row in rows) {
                var connectionString = row["connectionstring"].ToString();
                var sqlConnectionChecker = new SqlConnectionChecker(new[] { connectionString });

                if (!sqlConnectionChecker.AllGood())
                    continue;

                foreach (var subRow in new InternalOperation(connectionString).Execute(null)) {
                    foreach (var column in row.Columns)
                        subRow.Add(column, row[column]);
                    yield return subRow;
                }
            }
        }
Example #2
0
        public override IEnumerable <Row> Execute(IEnumerable <Row> rows)
        {
            foreach (var row in rows)
            {
                var connectionString     = row["connectionstring"].ToString();
                var sqlConnectionChecker = new SqlConnectionChecker(new[] { connectionString });

                if (!sqlConnectionChecker.AllGood())
                {
                    continue;
                }

                foreach (var subRow in new InternalOperation(connectionString).Execute(null))
                {
                    foreach (var column in row.Columns)
                    {
                        subRow.Add(column, row[column]);
                    }
                    yield return(subRow);
                }
            }
        }
        public override IEnumerable<Row> Execute(IEnumerable<Row> rows)
        {
            var counter = 0;
            foreach (var row in rows) {
                counter++;
                if (counter == 1) {
                    Guard.Against(!row.Contains(CONNECTION_STRING_KEY), "Row must contain connectionstring key.");
                }

                _connectionStringBuilder = new SqlConnectionStringBuilder(row[CONNECTION_STRING_KEY].ToString());
                var sqlConnectionChecker = new SqlConnectionChecker(new[] { _connectionStringBuilder.ConnectionString });

                if (!sqlConnectionChecker.AllGood())
                    continue;

                var results = new Database();
                var subRows = new List<Row>();
                var generator = new Generate() { ConnectionString = _connectionStringBuilder.ConnectionString };

                Debug("Started generating definitions on {0} for {1}", _connectionStringBuilder.DataSource, _connectionStringBuilder.InitialCatalog);

                try {
                    results = generator.Process();
                }
                catch (Exception e) {
                    Warn("Trouble processing objects from {0}.{1}.\nError Message: {2}.", _connectionStringBuilder.DataSource, _connectionStringBuilder.InitialCatalog, e.Message);
                }

                Debug("Finished generating defs on {0} for {1}", _connectionStringBuilder.DataSource, _connectionStringBuilder.InitialCatalog);

                subRows.AddRange(ToRows(results.Procedures, "StoredProcedures", "Stored Procedure"));
                subRows.AddRange(ToRows(results.Functions, "Functions", "Function"));
                subRows.AddRange(ToRows(results.Tables, "Tables", "Table"));
                subRows.AddRange(ToRows(results.Views, "Views", "View"));
                subRows.AddRange(ToRows(results.Schemas, "Schemas", "Schema"));
                subRows.AddRange(ToRows(results.Synonyms, "Synonyms", "Synonym"));
                subRows.AddRange(ToRows(results.FullText, "FullTextCatalogs", "Full Text Catalog"));

                foreach (var table in results.Tables) {
                    subRows.AddRange(ToRows(table.Indexes, "Indexes", "Index", true));
                    subRows.AddRange(ToRows(table.Triggers, "Triggers", "Trigger", true));
                    foreach (var constraint in table.Constraints) {
                        switch (constraint.Type) {
                            case Constraint.ConstraintType.Check:
                                subRows.AddRange(ToRows(Enumerable.Repeat(constraint, 1), "CheckConstraints", "Check Constraint", true, true));
                                break;
                            case Constraint.ConstraintType.Default:
                                subRows.AddRange(ToRows(Enumerable.Repeat(constraint, 1), "DefaultConstraints", "Default Constraint", true, true));
                                break;
                            case Constraint.ConstraintType.ForeignKey:
                                subRows.AddRange(ToRows(Enumerable.Repeat(constraint, 1), "ForeignKeys", "Foreign Key", true, true));
                                break;
                            case Constraint.ConstraintType.PrimaryKey:
                                subRows.AddRange(ToRows(Enumerable.Repeat(constraint, 1), "PrimaryKeys", "Primary Key", true, true));
                                break;
                            case Constraint.ConstraintType.Unique:
                                subRows.AddRange(ToRows(Enumerable.Repeat(constraint, 1), "UniqueConstraints", "Unique Constraint", true, true));
                                break;
                        }
                    }

                    foreach (var index in table.FullTextIndex)
                        subRows.AddRange(ToRows(Enumerable.Repeat(index, 1), "FullTextIndexes", "Full Text Index", true));
                }

                Info("Found {0} in {1}.", subRows.Count, _connectionStringBuilder.InitialCatalog);

                foreach (var subRow in subRows) {
                    yield return subRow;
                }

            }
        }
Example #4
0
        public override IEnumerable <Row> Execute(IEnumerable <Row> rows)
        {
            var counter = 0;

            foreach (var row in rows)
            {
                counter++;
                if (counter == 1)
                {
                    Guard.Against(!row.Contains(CONNECTION_STRING_KEY), "Row must contain connectionstring key.");
                }

                _connectionStringBuilder = new SqlConnectionStringBuilder(row[CONNECTION_STRING_KEY].ToString());
                var sqlConnectionChecker = new SqlConnectionChecker(new[] { _connectionStringBuilder.ConnectionString });

                if (!sqlConnectionChecker.AllGood())
                {
                    continue;
                }

                var results   = new Database();
                var subRows   = new List <Row>();
                var generator = new Generate()
                {
                    ConnectionString = _connectionStringBuilder.ConnectionString
                };

                Debug("Started generating definitions on {0} for {1}", _connectionStringBuilder.DataSource, _connectionStringBuilder.InitialCatalog);

                try {
                    results = generator.Process();
                } catch (Exception e) {
                    Warn("Trouble processing objects from {0}.{1}.\nError Message: {2}.", _connectionStringBuilder.DataSource, _connectionStringBuilder.InitialCatalog, e.Message);
                }

                Debug("Finished generating defs on {0} for {1}", _connectionStringBuilder.DataSource, _connectionStringBuilder.InitialCatalog);

                subRows.AddRange(ToRows(results.Procedures, "StoredProcedures", "Stored Procedure"));
                subRows.AddRange(ToRows(results.Functions, "Functions", "Function"));
                subRows.AddRange(ToRows(results.Tables, "Tables", "Table"));
                subRows.AddRange(ToRows(results.Views, "Views", "View"));
                subRows.AddRange(ToRows(results.Schemas, "Schemas", "Schema"));
                subRows.AddRange(ToRows(results.Synonyms, "Synonyms", "Synonym"));
                subRows.AddRange(ToRows(results.FullText, "FullTextCatalogs", "Full Text Catalog"));

                foreach (var table in results.Tables)
                {
                    subRows.AddRange(ToRows(table.Indexes, "Indexes", "Index", true));
                    subRows.AddRange(ToRows(table.Triggers, "Triggers", "Trigger", true));
                    foreach (var constraint in table.Constraints)
                    {
                        switch (constraint.Type)
                        {
                        case Constraint.ConstraintType.Check:
                            subRows.AddRange(ToRows(Enumerable.Repeat(constraint, 1), "CheckConstraints", "Check Constraint", true, true));
                            break;

                        case Constraint.ConstraintType.Default:
                            subRows.AddRange(ToRows(Enumerable.Repeat(constraint, 1), "DefaultConstraints", "Default Constraint", true, true));
                            break;

                        case Constraint.ConstraintType.ForeignKey:
                            subRows.AddRange(ToRows(Enumerable.Repeat(constraint, 1), "ForeignKeys", "Foreign Key", true, true));
                            break;

                        case Constraint.ConstraintType.PrimaryKey:
                            subRows.AddRange(ToRows(Enumerable.Repeat(constraint, 1), "PrimaryKeys", "Primary Key", true, true));
                            break;

                        case Constraint.ConstraintType.Unique:
                            subRows.AddRange(ToRows(Enumerable.Repeat(constraint, 1), "UniqueConstraints", "Unique Constraint", true, true));
                            break;
                        }
                    }

                    foreach (var index in table.FullTextIndex)
                    {
                        subRows.AddRange(ToRows(Enumerable.Repeat(index, 1), "FullTextIndexes", "Full Text Index", true));
                    }
                }

                Info("Found {0} in {1}.", subRows.Count, _connectionStringBuilder.InitialCatalog);

                foreach (var subRow in subRows)
                {
                    yield return(subRow);
                }
            }
        }