Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,28 +78,32 @@ public async ValueTask PersistAsync(MessageEnvelope envelope, CancellationToken

var connection = (NpgsqlConnection)_originalDbContext.Database.GetDbConnection();

if (connection.State != System.Data.ConnectionState.Open)
try
{
await connection.OpenAsync(cancellationToken);
}
await _originalDbContext.Database.OpenConnectionAsync(cancellationToken);

await using var writer = new Utf8JsonWriter(_arrayWriter);
writer.WriteEnvelope(envelope);
writer.Flush(); // we know it's not async
await using var writer = new Utf8JsonWriter(_arrayWriter);
writer.WriteEnvelope(envelope);
writer.Flush(); // we know it's not async

// Execute the INSERT command
await using var command = connection.CreateCommand();
command.CommandText = _insertSql;
command.Parameters.AddWithValue("@id", NewVersion());
command.Parameters.Add(
new NpgsqlParameter("@envelope", NpgsqlDbType.Json) { Value = _arrayWriter.WrittenMemory });
await command.PrepareAsync(cancellationToken);
// Execute the INSERT command
await using var command = connection.CreateCommand();
command.CommandText = _insertSql;
command.Parameters.AddWithValue("@id", NewVersion());
command.Parameters.Add(
new NpgsqlParameter("@envelope", NpgsqlDbType.Json) { Value = _arrayWriter.WrittenMemory });
await command.PrepareAsync(cancellationToken);

await command.ExecuteNonQueryAsync(cancellationToken);
await command.ExecuteNonQueryAsync(cancellationToken);

if (_originalDbContext.Database.CurrentTransaction?.GetDbTransaction() is not NpgsqlTransaction)
if (_originalDbContext.Database.CurrentTransaction?.GetDbTransaction() is not NpgsqlTransaction)
{
_signal.Set();
}
}
finally
{
_signal.Set();
await _originalDbContext.Database.CloseConnectionAsync();
}
}
finally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
<ProjectReference Include="..\..\src\Mocha\Mocha.csproj" />
<ProjectReference Include="..\..\src\Mocha.Outbox\Mocha.Outbox.csproj" />
<ProjectReference Include="..\..\src\Mocha.Inbox\Mocha.Inbox.csproj" />
<ProjectReference Include="..\..\..\CookieCrumble\src\CookieCrumble\CookieCrumble.csproj" />
<ProjectReference Include="..\..\..\CookieCrumble\src\CookieCrumble.Xunit3\CookieCrumble.Xunit3.csproj" />
<ProjectReference
Include="..\..\..\CookieCrumble\src\CookieCrumble.Analyzers\CookieCrumble.Analyzers.csproj"
OutputItemType="Analyzer"
/>
<ProjectReference Include="..\..\..\CookieCrumble\src\CookieCrumble.Resources.PostgreSql\CookieCrumble.Resources.PostgreSql.csproj" />
</ItemGroup>
</Project>
Loading
Loading