Forked from jen20/EventStoreDistributedTransaction.cs
Last active
August 29, 2015 14:17
-
-
Save kstrauss/cdd174120a08de4a2668 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace EventStoreDTCFirstTry | |
{ | |
public class EventStoreDistributedTransaction | |
{ | |
private static readonly Guid ResourceManagerId = new Guid("F6049197-5B56-4C90-ACA9-39A2516C547A"); | |
private readonly EventStoreConnection _connection; | |
private readonly EventStoreTransaction _esTransaction; | |
public EventStoreDistributedTransaction(EventStoreConnection connection, string stream, int expectedVersion) | |
{ | |
_connection = connection; | |
_esTransaction = _connection.StartTransaction(stream, expectedVersion); | |
if (Transaction.Current != null) | |
Transaction.Current.EnlistDurable(ResourceManagerId, new InternalEnlistment(this), EnlistmentOptions.None); | |
} | |
public void Write(IEnumerable<IEvent> events) | |
{ | |
_connection.TransactionalWrite(_esTransaction.TransactionId, _esTransaction.Stream, events); | |
} | |
private void Commit() | |
{ | |
_connection.CommitTransaction(_esTransaction.TransactionId, _esTransaction.Stream); | |
} | |
private class InternalEnlistment : IEnlistmentNotification | |
{ | |
private readonly EventStoreDistributedTransaction _transaction; | |
public InternalEnlistment(EventStoreDistributedTransaction transaction) | |
{ | |
_transaction = transaction; | |
} | |
public void Prepare(PreparingEnlistment preparingEnlistment) | |
{ | |
preparingEnlistment.Prepared(); | |
} | |
public void Commit(Enlistment enlistment) | |
{ | |
_transaction.Commit(); | |
enlistment.Done(); | |
} | |
public void Rollback(Enlistment enlistment) | |
{ | |
enlistment.Done(); | |
} | |
public void InDoubt(Enlistment enlistment) | |
{ | |
enlistment.Done(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment