|
|
@@ -36,22 +36,20 @@ namespace DotNetCore.CAP.Abstractions |
|
|
|
return PublishWithTransAsync(name, content); |
|
|
|
} |
|
|
|
|
|
|
|
public void Publish<T>(string name, T contentObj, IDbConnection dbConnection, |
|
|
|
string callbackName = null, IDbTransaction dbTransaction = null) |
|
|
|
public void Publish<T>(string name, T contentObj, IDbTransaction dbTransaction, string callbackName = null) |
|
|
|
{ |
|
|
|
CheckIsAdoNet(name); |
|
|
|
PrepareConnectionForAdo(dbConnection, dbTransaction); |
|
|
|
PrepareConnectionForAdo(dbTransaction); |
|
|
|
|
|
|
|
var content = Serialize(contentObj, callbackName); |
|
|
|
|
|
|
|
PublishWithTrans(name, content); |
|
|
|
} |
|
|
|
|
|
|
|
public Task PublishAsync<T>(string name, T contentObj, IDbConnection dbConnection, |
|
|
|
string callbackName = null, IDbTransaction dbTransaction = null) |
|
|
|
public Task PublishAsync<T>(string name, T contentObj, IDbTransaction dbTransaction, string callbackName = null) |
|
|
|
{ |
|
|
|
CheckIsAdoNet(name); |
|
|
|
PrepareConnectionForAdo(dbConnection, dbTransaction); |
|
|
|
PrepareConnectionForAdo(dbTransaction); |
|
|
|
|
|
|
|
var content = Serialize(contentObj, callbackName); |
|
|
|
|
|
|
@@ -69,16 +67,22 @@ namespace DotNetCore.CAP.Abstractions |
|
|
|
protected virtual string Serialize<T>(T obj, string callbackName = null) |
|
|
|
{ |
|
|
|
var packer = (IMessagePacker)ServiceProvider.GetService(typeof(IMessagePacker)); |
|
|
|
|
|
|
|
string content = string.Empty; |
|
|
|
if (Helper.IsComplexType(obj.GetType())) |
|
|
|
string content; |
|
|
|
if (obj != null) |
|
|
|
{ |
|
|
|
var serializer = (IContentSerializer)ServiceProvider.GetService(typeof(IContentSerializer)); |
|
|
|
content = serializer.Serialize(obj); |
|
|
|
if (Helper.IsComplexType(obj.GetType())) |
|
|
|
{ |
|
|
|
var serializer = (IContentSerializer)ServiceProvider.GetService(typeof(IContentSerializer)); |
|
|
|
content = serializer.Serialize(obj); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
content = obj.ToString(); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
content = obj?.ToString(); |
|
|
|
content = string.Empty; |
|
|
|
} |
|
|
|
|
|
|
|
var message = new CapMessageDto(content) |
|
|
@@ -91,20 +95,15 @@ namespace DotNetCore.CAP.Abstractions |
|
|
|
|
|
|
|
#region private methods |
|
|
|
|
|
|
|
private void PrepareConnectionForAdo(IDbConnection dbConnection, IDbTransaction dbTransaction) |
|
|
|
private void PrepareConnectionForAdo(IDbTransaction dbTransaction) |
|
|
|
{ |
|
|
|
DbConnection = dbConnection ?? throw new ArgumentNullException(nameof(dbConnection)); |
|
|
|
DbTransaction = dbTransaction ?? throw new ArgumentNullException(nameof(dbTransaction)); |
|
|
|
DbConnection = DbTransaction.Connection; |
|
|
|
if (DbConnection.State != ConnectionState.Open) |
|
|
|
{ |
|
|
|
IsCapOpenedConn = true; |
|
|
|
DbConnection.Open(); |
|
|
|
} |
|
|
|
DbTransaction = dbTransaction; |
|
|
|
if (DbTransaction == null) |
|
|
|
{ |
|
|
|
IsCapOpenedTrans = true; |
|
|
|
DbTransaction = dbConnection.BeginTransaction(IsolationLevel.ReadCommitted); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void CheckIsUsingEF(string name) |
|
|
|