Ejemplo n.º 1
0
        public async Task <IWatcherCheckResult> ExecuteAsync()
        {
            try
            {
                var redis = _configuration.RedisProvider?.Invoke() ?? await _connection.GetDatabaseAsync(_configuration.Database);

                if (redis == null)
                {
                    return(RedisWatcherCheckResult.Create(this, false, _configuration.Database,
                                                          _configuration.ConnectionString, $"Database: '{_configuration.Database}' has not been found."));
                }
                if (string.IsNullOrWhiteSpace(_configuration.Query))
                {
                    return(RedisWatcherCheckResult.Create(this, true, _configuration.Database,
                                                          _configuration.ConnectionString,
                                                          $"Database: {_configuration.Database} has been sucessfully checked."));
                }

                return(await ExecuteForQueryAsync(redis));
            }
            catch (RedisException exception)
            {
                return(RedisWatcherCheckResult.Create(this, false, _configuration.Database,
                                                      _configuration.ConnectionString, exception.Message));
            }
            catch (Exception exception)
            {
                throw new WatcherException("There was an error while trying to access the Redis.", exception);
            }
        }
Ejemplo n.º 2
0
        private async Task <IWatcherCheckResult> ExecuteForQueryAsync(IRedis redis)
        {
            var queryResult = await redis.QueryAsync(_configuration.Query);

            var isValid = true;

            if (_configuration.EnsureThatAsync != null)
            {
                isValid = await _configuration.EnsureThatAsync?.Invoke(queryResult);
            }

            isValid = isValid && (_configuration.EnsureThat?.Invoke(queryResult) ?? true);
            var description = $"Redis check has returned {(isValid ? "valid" : "invalid")} result for " +
                              $"database: '{_configuration.Database}' and given query.";

            return(RedisWatcherCheckResult.Create(this, isValid, _configuration.Database,
                                                  _configuration.ConnectionString, _configuration.Query, queryResult, description));
        }
Ejemplo n.º 3
0
        public async Task <IWatcherCheckResult> ExecuteAsync()
        {
            try
            {
                var database = _configuration.RedisProvider?.Invoke() ?? await _connection.GetDatabaseAsync(_configuration.Database);

                if (database == null)
                {
                    return(RedisWatcherCheckResult.Create(this, false, _configuration.Database,
                                                          _configuration.ConnectionString, $"Database: '{_configuration.Database}' has not been found."));
                }
                if (string.IsNullOrWhiteSpace(_configuration.Query))
                {
                    return(RedisWatcherCheckResult.Create(this, true, _configuration.Database,
                                                          _configuration.ConnectionString,
                                                          $"Database: {_configuration.Database} has been sucessfully checked."));
                }

                var queryResult = await database.QueryAsync(_configuration.Query);

                var isValid = true;
                if (_configuration.EnsureThatAsync != null)
                {
                    isValid = await _configuration.EnsureThatAsync?.Invoke(queryResult);
                }

                isValid = isValid && (_configuration.EnsureThat?.Invoke(queryResult) ?? true);
                var description = $"Redis check has returned {(isValid ? "valid" : "invalid")} result for " +
                                  $"database: '{_configuration.Database}' and given query.";

                return(RedisWatcherCheckResult.Create(this, isValid, _configuration.Database,
                                                      _configuration.ConnectionString, _configuration.Query, queryResult, description));
            }
            catch (RedisException exception)
            {
                return(RedisWatcherCheckResult.Create(this, false, _configuration.Database,
                                                      _configuration.ConnectionString, exception.Message));
            }
            catch (Exception exception)
            {
                throw new WatcherException("There was an error while trying to access the Redis.", exception);
            }
        }