Esempio n. 1
0
        /// <summary>
        /// Creates a new telemetry event item in the backing store.
        /// </summary>
        /// <param name="telemetry">The telemetry event to write to the backing store.</param>
        public async Task CreateDataAsync(TelemetryEvent <TContext> telemetry)
        {
            try
            {
                using (MySqlConnection connection = new MySqlConnection(this.sqlConnectionString))
                {
                    using (MySqlCommand command = this.CreateTelemetryInsertCommand(connection, telemetry))
                    {
                        await connection.OpenAsync().ConfigureAwait(false);

                        await command.ExecuteNonQueryAsync().ConfigureAwait(false);
                    }
                }
            }
            catch
            {
                throw;
            }
        }
 private static string SerializeItem(TelemetryEvent <TContext> item)
 {
     return(JsonConvert.SerializeObject(item, TelemetryEvent <TContext> .SerializationSettings));
 }
Esempio n. 3
0
        protected MySqlCommand CreateTelemetryInsertCommand(MySqlConnection connection, TelemetryEvent <TContext> telemetry)
        {
            MySqlCommand command = connection.CreateCommand();

            command.CommandType = System.Data.CommandType.Text;
            command.CommandText =
                @"INSERT INTO TelemetryEvents
                (Timestamp, EventName, CorrelationId, Context)
                VALUES (@Timestamp, @EventName, @CorrelationId, @Context)";

            string eventContext = null;

            if (telemetry.Context != null)
            {
                eventContext = JsonConvert.SerializeObject(telemetry.Context, TelemetryEvent <TContext> .SerializationSettings);
            }

            command.Parameters.Add(new MySqlParameter("@Timestamp", telemetry.Timestamp));
            command.Parameters.Add(new MySqlParameter("@EventName", telemetry.EventName));
            command.Parameters.Add(new MySqlParameter("@CorrelationId", telemetry.CorrelationId));
            command.Parameters.Add(new MySqlParameter("@Context", eventContext));

            return(command);
        }