コード例 #1
0
        public async Task ExecuteAsync(AddAliasProperties requestContent, DateTime enqueuedTimeUtc)
        {
            _telemetryClient.GetMetric("MethodUsage", "Method").TrackValue(1, "AddAlias");

            var intentionalDelay = Random.Next(3000);
            await Task.Delay(intentionalDelay);

            _logger.LogInformation("Adding alias to database: {alias}", JsonConvert.SerializeObject(requestContent));
            using (var connection = await _sqlConnectionFactory.CreateConnectionAsync())
            {
                using (var command = new SqlCommand(AddAliasQuery, connection))
                {
                    command.Parameters.AddWithValue("url", requestContent.Url);
                    command.Parameters.AddWithValue("alias", requestContent.Alias);
                    await connection.OpenAsync();

                    await command.ExecuteNonQueryAsync();

                    connection.Close();
                }
            }

            var delay = DateTime.UtcNow - enqueuedTimeUtc;
            var delayInMiliSeconds = (int)delay.TotalMilliseconds;

            _logger.LogTrace("Recording delay of {delay} ms in adding alias", delayInMiliSeconds);

            _telemetryClient.GetMetric("AddAliasProcessingDelay").TrackValue(delayInMiliSeconds);
        }
コード例 #2
0
        public async Task ExecuteAsync()
        {
            using (var connection = await _sqlConnectionFactory.CreateConnectionAsync())
            {
                using (var command = new SqlCommand(CleanUpQuery, connection))
                {
                    await connection.OpenAsync();

                    await command.ExecuteNonQueryAsync();

                    connection.Close();
                }
            }
        }
コード例 #3
0
        public static async Task<SqlConnection> CreateOpenedConnectionAsync(
            this ISqlConnectionFactory factory, string name, CancellationToken cancellationToken)
        {
            // Validate the parameters.
            if (factory == null) throw new ArgumentNullException(nameof(factory));
            if (string.IsNullOrEmpty(name)) throw new ArgumentNullException(nameof(name));

            // The connection.
            SqlConnection connection = await factory.CreateConnectionAsync(name, cancellationToken).
                ConfigureAwait(false);

            // Open the connection.
            await connection.OpenAsync(cancellationToken).ConfigureAwait(false);

            // Return the connection.
            return connection;
        }