private static void BeginQuery(object sender, QueryTraceEventArgs e) { var store = Store; var metadata = MakeMetadata(e); store.List.Enqueue(metadata); store.Dictionary.TryAdd(e.Token, metadata); metadata.Stopwatch.Start(); }
/// <summary> /// Invokes the query end event. /// </summary> /// <param name="e">The <see cref="Passive.Diagnostics.QueryTraceEventArgs"/> instance containing the event data.</param> internal static void InvokeQueryEnd(QueryTraceEventArgs e) { var handler = QueryEnd; if (handler != null) { handler(null, e); } }
private static GlimpsePassiveMetadata MakeMetadata(QueryTraceEventArgs e) { return new GlimpsePassiveMetadata { Sql = e.Sql, Arguments = e.Arguments.ToArray(), Context = e.Context, Stopwatch = new Stopwatch() }; }
/// <summary> /// Returns a single result /// </summary> public object Scalar(DynamicCommand command) { var queryTraceEventArgs = new QueryTraceEventArgs(command.Sql, command.Arguments, command.Context); QueryTrace.InvokeQueryBegin(queryTraceEventArgs); using (var conn = this.OpenConnection()) { var scalar = this.CreateDbCommand(command, connection: conn).ExecuteScalar(); QueryTrace.InvokeQueryEnd(queryTraceEventArgs); return scalar; } }
/// <summary> /// Enumerates the reader yielding the results /// </summary> public IEnumerable<object> Query(DynamicCommand command) { var queryTraceEventArgs = new QueryTraceEventArgs(command.Sql, command.Arguments, command.Context); QueryTrace.InvokeQueryBegin(queryTraceEventArgs); using (var conn = this.OpenConnection()) { var dbCommand = this.CreateDbCommand(command, connection: conn); using (var rdr = dbCommand.ExecuteReader(CommandBehavior.CloseConnection)) { QueryTrace.InvokeQueryEnd(queryTraceEventArgs); while (rdr.Read()) { var d = (IDictionary<string, object>) new ExpandoObject(); for (var i = 0; i < rdr.FieldCount; i++) { var value = rdr[i]; d.Add(rdr.GetName(i), DBNull.Value.Equals(value) ? null : value); } yield return d; } } } }
private static void EndQuery(object sender, QueryTraceEventArgs e) { var metadata = Store.Dictionary[e.Token]; metadata.Stopwatch.Stop(); }