Example #1
0
        public static void ConfigureQueries(IWindsorContainer container)
        {
            var queryType  = typeof(IQuery);
            var allQueries = AppDomain.CurrentDomain.GetAssemblies()
                             .SelectMany(s => s.GetTypes())
                             .Where(p => queryType.IsAssignableFrom(p) &&
                                    p.IsClass &&
                                    !p.IsAbstract &&
                                    !p.IsInterface);

            QueryLocator queryLocator = null;

            foreach (var command in allQueries)
            {
                if (queryLocator == null)
                {
                    queryLocator = new QueryLocator
                                       (command.Assembly, command.Namespace);
                }
                else
                {
                    queryLocator.AddQuerySource
                        (command.Assembly, command.Namespace);
                }
            }

            container.Register(
                Component.For <IQueryLocator>()
                .UsingFactoryMethod(() => queryLocator)
                .LifestylePerWebRequest()
                );
            ;
        }
        public void Should_replace_where_with_included_databases()
        {
            var queryType = new SqlServerConnections();

            var sqlServer = new SqlServerEndpoint("foo", "foo", false, new[] {new Database {Name = "bar"},}, null);

            var queryLocator = new QueryLocator(null);
            IEnumerable<SqlQuery> queries = queryLocator.PrepareQueries(new[] {queryType.GetType()}, false);
            foreach (SqlQuery query in queries)
            {
                string actual = queryType.ParameterizeQuery(query.CommandText, sqlServer);
                Assert.That(actual, Is.StringContaining("AND (d.Name IN ('bar')"));
            }
        }
Example #3
0
        public void Start()
        {
            try
            {
                lock (_syncRoot)
                {
                    if (_pollingThread != null)
                    {
                        return;
                    }

                    _log.Info("----------------");
                    _log.Info("Service Starting");

                    var queries = new QueryLocator(new DapperWrapper()).PrepareQueries();
                    _settings.Endpoints.ForEach(e => e.SetQueries(queries));

                    var initialDelaySeconds   = _settings.TestMode ? 0 : _settings.PollIntervalSeconds;
                    var pollingThreadSettings = new PollingThreadSettings
                    {
                        Name = "SqlPoller",
                        // Set to immediate when in TestMode for instant gratification.
                        InitialPollDelaySeconds = initialDelaySeconds,
                        PollIntervalSeconds     = _settings.PollIntervalSeconds,
                        PollAction     = () => _metricCollector.QueryEndpoints(queries),
                        AutoResetEvent = new AutoResetEvent(false),
                    };

                    _pollingThread = new PollingThread(pollingThreadSettings, _log);
                    _pollingThread.ExceptionThrown += e => _log.Error("Polling thread exception", e);

                    _log.Debug("Service Threads Starting...");

                    if (initialDelaySeconds > 0)
                    {
                        _log.InfoFormat("Waiting {0} seconds to begin polling", initialDelaySeconds);
                    }

                    _pollingThread.Start();

                    _log.Debug("Service Threads Started");
                }
            }
            catch (Exception e)
            {
                _log.Fatal("Failed while attempting to start service");
                _log.Warn(e);
                throw;
            }
        }
        public void Start()
        {
            try
            {
                lock (_syncRoot)
                {
                    if (_pollingThread != null)
                    {
                        return;
                    }

                    _log.Info("----------------");
                    _log.Info("Service Starting");

                    var queries = new QueryLocator(new DapperWrapper()).PrepareQueries();
                    _settings.Endpoints.ForEach(e => e.SetQueries(queries));

                    var initialDelaySeconds = _settings.TestMode ? 0 : _settings.PollIntervalSeconds;
                    var pollingThreadSettings = new PollingThreadSettings
                                                {
                                                    Name = "SqlPoller",
                                                    // Set to immediate when in TestMode for instant gratification.
                                                    InitialPollDelaySeconds = initialDelaySeconds,
                                                    PollIntervalSeconds = _settings.PollIntervalSeconds,
                                                    PollAction = () => _metricCollector.QueryEndpoints(queries),
                                                    AutoResetEvent = new AutoResetEvent(false),
                                                };

                    _pollingThread = new PollingThread(pollingThreadSettings, _log);
                    _pollingThread.ExceptionThrown += e => _log.Error("Polling thread exception", e);

                    _log.Debug("Service Threads Starting...");

                    if (initialDelaySeconds > 0)
                    {
                        _log.InfoFormat("Waiting {0} seconds to begin polling", initialDelaySeconds);
                    }

                    _pollingThread.Start();

                    _log.Debug("Service Threads Started");
                }
            }
            catch (Exception e)
            {
                _log.Fatal("Failed while attempting to start service");
                _log.Warn(e);
                throw;
            }
        }
        public void Should_replace_where_with_excluded_databases()
        {
            var queryType = new SqlServerConnections();

            var sqlServer = new SqlServer("foo", "foo", true, null, new[] {"blah"});

            var queryLocator = new QueryLocator(null);
            var queries = queryLocator.PrepareQueries(new[] {queryType.GetType()}, false);
            foreach (var query in queries)
            {
                var actual = queryType.ParameterizeQuery(query.CommandText, sqlServer);
                Assert.That(actual, Is.StringContaining("AND (d.Name NOT IN ('blah')"));
            }
        }
Example #6
0
        public void Should_replace_where_with_excluded_databases()
        {
            var queryType = new SqlServerConnections();

            var sqlServer = new SqlServerEndpoint("foo", "foo", true, null, new[] { "blah" });

            var queryLocator = new QueryLocator(null);
            IEnumerable <SqlQuery> queries = queryLocator.PrepareQueries(new[] { queryType.GetType() }, false);

            foreach (SqlQuery query in queries)
            {
                string actual = queryType.ParameterizeQuery(query.CommandText, sqlServer);
                Assert.That(actual, Is.StringContaining("AND (d.Name NOT IN ('blah')"));
            }
        }
Example #7
0
        public void Should_replace_where_with_excluded_databases()
        {
            var queryType = new TQuery();

            var sqlServer = new SqlServerEndpoint("foo", "foo", true, null, new[] { "exclude" });

            var queryLocator = new QueryLocator(null);
            IEnumerable <SqlQuery> queries = sqlServer.FilterQueries(queryLocator.PrepareQueries(new[] { queryType.GetType() }, false));

            foreach (SqlQuery query in queries)
            {
                string actual = queryType.ParameterizeQuery(query.CommandText, sqlServer);
                Assert.That(actual, Is.StringContaining(ExcludedDatabaseExpectedSql));
            }
        }
Example #8
0
        public void Should_replace_where_with_included_and_system_databases()
        {
            var queryType = new SqlServerConnections();

            var sqlServer = new SqlServerEndpoint("foo", "foo", true, new[] { new Database {
                                                                                  Name = "bar"
                                                                              }, }, null);

            var queryLocator = new QueryLocator(null);
            IEnumerable <SqlQuery> queries = queryLocator.PrepareQueries(new[] { queryType.GetType() }, false);

            foreach (SqlQuery query in queries)
            {
                string actual = queryType.ParameterizeQuery(query.CommandText, sqlServer);
                Assert.That(actual, Is.StringContaining("AND (d.Name IN ('bar', 'tempdb', 'master', 'model', 'msdb')"));
            }
        }
Example #9
0
 // API
 public StandardSetController(QueryLocator queryLocator)
 {
     Self = Implementation.Constructor(queryLocator);
 }