Skip to content

Commit

Permalink
Initial batch of nominal types for DiagnosticSource events
Browse files Browse the repository at this point in the history
Issue #7938, #8007

* This covers most of the relational events.
* Namespace is Microsoft.EntityFrameworkCore.DiagnosticSourceData (Didn't use xxx.xxx.DiagnosticSource as a namespace because then there is a namespace with the same name as a class causing resolution niceness issues.)
* Created something of a hierarchy where it made sense so that common code can be used by consumers in some places and to be a bit more DRY.
* Tried to be somewhat consistent in ordering, etc.
* Made sure ConnectionId and CommandId are exposed where available, specifically including on DataReaderDisposing as requested in #8007.
  • Loading branch information
ajcvickers committed May 2, 2017
1 parent e0d3318 commit 302de03
Show file tree
Hide file tree
Showing 36 changed files with 1,490 additions and 421 deletions.
4 changes: 4 additions & 0 deletions src/EFCore.InMemory/Storage/Internal/InMemoryTransaction.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;

namespace Microsoft.EntityFrameworkCore.Storage.Internal
{
public class InMemoryTransaction : IDbContextTransaction
{
public virtual Guid TransactionId { get; } = Guid.NewGuid();

public virtual void Commit()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private enum Id
public static readonly EventId ForeignKeyColumnMissingWarning = MakeScaffoldingId(Id.ForeignKeyColumnMissingWarning);

/// <summary>
/// A foreign key column was not found.
/// A column referenced by a foreign key constraint was not found.
/// This event is in the <see cref="LoggerCategory.Scaffolding" /> category.
/// </summary>
public static readonly EventId ForeignKeyPrincipalColumnMissingWarning = MakeScaffoldingId(Id.ForeignKeyPrincipalColumnMissingWarning);
Expand All @@ -188,7 +188,7 @@ private enum Id
public static readonly EventId IndexNotNamedWarning = MakeScaffoldingId(Id.IndexNotNamedWarning);

/// <summary>
/// The table references by an index was not found.
/// The table referened by an index was not found.
/// This event is in the <see cref="LoggerCategory.Scaffolding" /> category.
/// </summary>
public static readonly EventId IndexTableMissingWarning = MakeScaffoldingId(Id.IndexTableMissingWarning);
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Relational.Design/Metadata/SequenceModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public class SequenceModel : Annotatable
public virtual bool? IsCyclic { get; [param: CanBeNull] set; }

public virtual string DisplayName
=> (!string.IsNullOrEmpty(SchemaName) ? SchemaName + "." : "") + Name;
=> !string.IsNullOrEmpty(SchemaName) ? (SchemaName + "." + Name) : Name;
}
}
2 changes: 1 addition & 1 deletion src/EFCore.Relational.Design/Metadata/TableModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public class TableModel : Annotatable
public virtual ICollection<ForeignKeyModel> ForeignKeys { get; } = new List<ForeignKeyModel>();

public virtual string DisplayName
=> (!string.IsNullOrEmpty(SchemaName) ? SchemaName + "." : "") + Name;
=> !string.IsNullOrEmpty(SchemaName) ? (SchemaName + "." + Name) : Name;
}
}
85 changes: 85 additions & 0 deletions src/EFCore.Relational/DiagnosticSourceData/CommandData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Data.Common;
using System.Diagnostics;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace Microsoft.EntityFrameworkCore.DiagnosticSourceData
{
/// <summary>
/// The <see cref="DiagnosticSource" /> event payload for
/// <see cref="RelationalEventId" /> command events.
/// </summary>
public class CommandData
{
/// <summary>
/// Constructs the event payload.
/// </summary>
/// <param name="command">
/// The <see cref="DbCommand" />.
/// </param>
/// <param name="executeMethod">
/// The <see cref="DbCommand" /> method.
/// </param>
/// <param name="commandId">
/// A correlation ID that identifies the <see cref="DbCommand" /> instance being used.
/// </param>
/// <param name="connectionId">
/// A correlation ID that identifies the <see cref="DbConnection" /> instance being used.
/// </param>
/// <param name="async">
/// Indicates whether or not the command was executed asyncronously.
/// </param>
/// <param name="timestamp">
/// A timestamp from <see cref="Stopwatch.GetTimestamp" /> that can be used for timing.
/// </param>
public CommandData(
[NotNull] DbCommand command,
DbCommandMethod executeMethod,
Guid commandId,
Guid connectionId,
bool async,
long timestamp)
{
Command = command;
CommandId = commandId;
ConnectionId = connectionId;
ExecuteMethod = executeMethod;
Async = async;
Timestamp = timestamp;
}

/// <summary>
/// The <see cref="DbCommand" />.
/// </summary>
public virtual DbCommand Command { get; }

/// <summary>
/// A correlation ID that identifies the <see cref="DbCommand" /> instance being used.
/// </summary>
public virtual Guid CommandId { get; }

/// <summary>
/// A correlation ID that identifies the <see cref="DbConnection" /> instance being used.
/// </summary>
public virtual Guid ConnectionId { get; }

/// <summary>
/// The <see cref="DbCommand" /> method.
/// </summary>
public virtual DbCommandMethod ExecuteMethod { get; }

/// <summary>
/// Indicates whether or not the operation is being executed asyncronously.
/// </summary>
public virtual bool Async { get; }

/// <summary>
/// A timestamp from <see cref="Stopwatch.GetTimestamp" /> that can be used for timing.
/// </summary>
public virtual long Timestamp { get; }
}
}
60 changes: 60 additions & 0 deletions src/EFCore.Relational/DiagnosticSourceData/CommandEndData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Data.Common;
using System.Diagnostics;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace Microsoft.EntityFrameworkCore.DiagnosticSourceData
{
/// <summary>
/// The <see cref="DiagnosticSource" /> event payload for
/// <see cref="RelationalEventId" /> command end events.
/// </summary>
public class CommandEndData : CommandData
{
/// <summary>
/// Constructs the event payload.
/// </summary>
/// <param name="command">
/// The <see cref="DbCommand" />.
/// </param>
/// <param name="executeMethod">
/// The <see cref="DbCommand" /> method.
/// </param>
/// <param name="commandId">
/// A correlation ID that identifies the <see cref="DbCommand" /> instance being used.
/// </param>
/// <param name="connectionId">
/// A correlation ID that identifies the <see cref="DbConnection" /> instance being used.
/// </param>
/// <param name="async">
/// Indicates whether or not the command was executed asyncronously.
/// </param>
/// <param name="timestamp">
/// A timestamp from <see cref="Stopwatch.GetTimestamp" /> that can be used for timing.
/// </param>
/// <param name="duration">
/// The duration of execution as ticks from <see cref="Stopwatch.GetTimestamp" />.
/// </param>
public CommandEndData(
[NotNull] DbCommand command,
DbCommandMethod executeMethod,
Guid commandId,
Guid connectionId,
bool async,
long timestamp,
long duration)
: base(command, executeMethod, commandId, connectionId, async, timestamp)
{
Duration = duration;
}

/// <summary>
/// The duration of execution as ticks from <see cref="Stopwatch.GetTimestamp" />.
/// </summary>
public virtual long Duration { get; }
}
}
64 changes: 64 additions & 0 deletions src/EFCore.Relational/DiagnosticSourceData/CommandErrorData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Data.Common;
using System.Diagnostics;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace Microsoft.EntityFrameworkCore.DiagnosticSourceData
{
/// <summary>
/// The <see cref="DiagnosticSource" /> event payload for <see cref="RelationalEventId.CommandError" />.
/// </summary>
public class CommandErrorData : CommandEndData
{
/// <summary>
/// Constructs the event payload.
/// </summary>
/// <param name="command">
/// The <see cref="DbCommand" /> that was executing when it failed.
/// </param>
/// <param name="executeMethod">
/// The <see cref="DbCommand" /> method that was used to execute the command.
/// </param>
/// <param name="commandId">
/// A correlation ID that identifies the <see cref="DbCommand" /> instance being used.
/// </param>
/// <param name="connectionId">
/// A correlation ID that identifies the <see cref="DbConnection" /> instance being used.
/// </param>
/// <param name="exception">
/// The exception that was thrown when execution failed.
/// </param>
/// <param name="async">
/// Indicates whether or not the command was executed asyncronously.
/// </param>
/// <param name="timestamp">
/// A timestamp from <see cref="Stopwatch.GetTimestamp" /> that can be used
/// with <see cref="RelationalEventId.CommandExecuting" /> to time execution.
/// </param>
/// <param name="duration">
/// The duration of execution as ticks from <see cref="Stopwatch.GetTimestamp" />.
/// </param>
public CommandErrorData(
[NotNull] DbCommand command,
DbCommandMethod executeMethod,
Guid commandId,
Guid connectionId,
[NotNull] Exception exception,
bool async,
long timestamp,
long duration)
: base(command, executeMethod, commandId, connectionId, async, timestamp, duration)
{
Exception = exception;
}

/// <summary>
/// The exception that was thrown when execution failed.
/// </summary>
public virtual Exception Exception { get; }
}
}
64 changes: 64 additions & 0 deletions src/EFCore.Relational/DiagnosticSourceData/CommandExecutedData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Data.Common;
using System.Diagnostics;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace Microsoft.EntityFrameworkCore.DiagnosticSourceData
{
/// <summary>
/// The <see cref="DiagnosticSource" /> event payload for <see cref="RelationalEventId.CommandExecuted" />.
/// </summary>
public class CommandExecutedData : CommandEndData
{
/// <summary>
/// Constructs the event payload.
/// </summary>
/// <param name="command">
/// The <see cref="DbCommand" /> that was executing when it failed.
/// </param>
/// <param name="executeMethod">
/// The <see cref="DbCommand" /> method that was used to execute the command.
/// </param>
/// <param name="commandId">
/// A correlation ID that identifies the <see cref="DbCommand" /> instance being used.
/// </param>
/// <param name="connectionId">
/// A correlation ID that identifies the <see cref="DbConnection" /> instance being used.
/// </param>
/// <param name="result">
/// The result of executing the operation.
/// </param>
/// <param name="async">
/// Indicates whether or not the command was executed asyncronously.
/// </param>
/// <param name="timestamp">
/// A timestamp from <see cref="Stopwatch.GetTimestamp" /> that can be used
/// with <see cref="RelationalEventId.CommandExecuting" /> to time execution.
/// </param>
/// <param name="duration">
/// The duration of execution as ticks from <see cref="Stopwatch.GetTimestamp" />.
/// </param>
public CommandExecutedData(
[NotNull] DbCommand command,
DbCommandMethod executeMethod,
Guid commandId,
Guid connectionId,
[CanBeNull] object result,
bool async,
long timestamp,
long duration)
: base(command, executeMethod, commandId, connectionId, async, timestamp, duration)
{
Result = result;
}

/// <summary>
/// The result of executing the command.
/// </summary>
public virtual object Result { get; }
}
}
65 changes: 65 additions & 0 deletions src/EFCore.Relational/DiagnosticSourceData/ConnectionData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Data.Common;
using System.Diagnostics;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace Microsoft.EntityFrameworkCore.DiagnosticSourceData
{
/// <summary>
/// The <see cref="DiagnosticSource" /> event payload base class for
/// <see cref="RelationalEventId" /> connection events.
/// </summary>
public class ConnectionData
{
/// <summary>
/// Constructs the event payload.
/// </summary>
/// <param name="connection">
/// The <see cref="DbConnection" />.
/// </param>
/// <param name="connectionId">
/// A correlation ID that identifies the <see cref="DbConnection" /> instance being used.
/// </param>
/// <param name="async">
/// Indicates whether or not the operation is happening asyncronously.
/// </param>
/// <param name="timestamp">
/// A timestamp from <see cref="Stopwatch.GetTimestamp" /> that can be used for timing.
/// </param>
public ConnectionData(
[NotNull] DbConnection connection,
Guid connectionId,
bool async,
long timestamp)
{
Connection = connection;
ConnectionId = connectionId;
Async = async;
Timestamp = timestamp;
}

/// <summary>
/// The <see cref="DbConnection" />.
/// </summary>
public virtual DbConnection Connection { get; }

/// <summary>
/// A correlation ID that identifies the <see cref="DbConnection" /> instance being used.
/// </summary>
public virtual Guid ConnectionId { get; }

/// <summary>
/// Indicates whether or not the operation is happening asyncronously.
/// </summary>
public virtual bool Async { get; }

/// <summary>
/// A timestamp from <see cref="Stopwatch.GetTimestamp" /> that can be used for timing.
/// </summary>
public virtual long Timestamp { get; }
}
}
Loading

0 comments on commit 302de03

Please sign in to comment.