From 764e23fa32e348e281938b6d9301a28cfe26eb77 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Sat, 28 Jul 2018 18:02:33 +0800 Subject: [PATCH] add impl for ICapTransaction --- src/DotNetCore.CAP/ICapTransaction.Base.cs | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/DotNetCore.CAP/ICapTransaction.Base.cs diff --git a/src/DotNetCore.CAP/ICapTransaction.Base.cs b/src/DotNetCore.CAP/ICapTransaction.Base.cs new file mode 100644 index 0000000..3ab5fb2 --- /dev/null +++ b/src/DotNetCore.CAP/ICapTransaction.Base.cs @@ -0,0 +1,41 @@ +using System.Collections.Generic; +using DotNetCore.CAP.Models; + +namespace DotNetCore.CAP +{ + public abstract class CapTransactionBase : ICapTransaction + { + private readonly IDispatcher _dispatcher; + + private readonly IList _bufferList; + + protected CapTransactionBase(IDispatcher dispatcher) + { + _dispatcher = dispatcher; + _bufferList = new List(1); + } + + public bool AutoCommit { get; set; } + + public object DbTransaction { get; set; } + + protected internal void AddToSent(CapPublishedMessage msg) + { + _bufferList.Add(msg); + } + + protected void Flush() + { + foreach (var message in _bufferList) + { + _dispatcher.EnqueueToPublish(message); + } + } + + public abstract void Commit(); + + public abstract void Rollback(); + + public abstract void Dispose(); + } +}