Exemplo n.º 1
0
        public override void Init(IServiceContainer serviceContainer, IDictionary <string, string> jobArgsDictionary)
        {
            var secretInjector = (ISecretInjector)serviceContainer.GetService(typeof(ISecretInjector));
            var statisticsDbConnectionString = JobConfigurationManager.GetArgument(jobArgsDictionary, JobArgumentNames.StatisticsDatabase);

            _statisticsDbConnectionFactory = new AzureSqlConnectionFactory(statisticsDbConnectionString, secretInjector);

            _targetClientName = JobConfigurationManager.TryGetArgument(jobArgsDictionary, "TargetClientName");
            _userAgentFilter  = JobConfigurationManager.TryGetArgument(jobArgsDictionary, "UserAgentFilter");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Test connection early to fail fast, and log connection diagnostics.
        /// </summary>
        private async Task TestConnection(string name, ICoreSqlConnectionFactory connectionFactory)
        {
            try
            {
                using (var connection = await connectionFactory.OpenAsync())
                    using (var cmd = new SqlCommand("SELECT CONCAT(CURRENT_USER, '/', SYSTEM_USER)", connection))
                    {
                        var result = cmd.ExecuteScalar();
                        var user   = result.ToString();
                        Logger.LogInformation("Verified CreateSqlConnectionAsync({name}) connects to database {DataSource}/{InitialCatalog} as {User}",
                                              name, connectionFactory.DataSource, connectionFactory.InitialCatalog, user);
                    }
            }
            catch (Exception e)
            {
                Logger.LogError(0, e, "Failed to connect to database {DataSource}/{InitialCatalog}",
                                connectionFactory.DataSource, connectionFactory.InitialCatalog);

                throw;
            }
        }