@@ -15,14 +15,14 @@ namespace DotNetCore.CAP.InMemoryStorage | |||||
{ | { | ||||
internal class InMemoryMonitoringApi : IMonitoringApi | internal class InMemoryMonitoringApi : IMonitoringApi | ||||
{ | { | ||||
public Task<MediumMessage> GetPublishedMessageAsync(long id) | |||||
public Task<MediumMessage?> GetPublishedMessageAsync(long id) | |||||
{ | { | ||||
return Task.FromResult((MediumMessage)InMemoryStorage.PublishedMessages.Values.FirstOrDefault(x => x.DbId == id.ToString(CultureInfo.InvariantCulture))); | |||||
return Task.FromResult<MediumMessage?>(InMemoryStorage.PublishedMessages.Values.FirstOrDefault(x => x.DbId == id.ToString(CultureInfo.InvariantCulture))); | |||||
} | } | ||||
public Task<MediumMessage> GetReceivedMessageAsync(long id) | |||||
public Task<MediumMessage?> GetReceivedMessageAsync(long id) | |||||
{ | { | ||||
return Task.FromResult((MediumMessage)InMemoryStorage.ReceivedMessages.Values.FirstOrDefault(x => x.DbId == id.ToString(CultureInfo.InvariantCulture))); | |||||
return Task.FromResult<MediumMessage?>(InMemoryStorage.ReceivedMessages.Values.FirstOrDefault(x => x.DbId == id.ToString(CultureInfo.InvariantCulture))); | |||||
} | } | ||||
public StatisticsDto GetStatistics() | public StatisticsDto GetStatistics() | ||||
@@ -18,7 +18,7 @@ namespace DotNetCore.CAP | |||||
/// <summary> | /// <summary> | ||||
/// EF db context type. | /// EF db context type. | ||||
/// </summary> | /// </summary> | ||||
internal Type DbContextType { get; set; } | |||||
internal Type? DbContextType { get; set; } | |||||
/// <summary> | /// <summary> | ||||
/// Data version | /// Data version | ||||
@@ -13,7 +13,7 @@ namespace DotNetCore.CAP | |||||
/// <summary> | /// <summary> | ||||
/// Gets or sets the database's connection string that will be used to store database entities. | /// Gets or sets the database's connection string that will be used to store database entities. | ||||
/// </summary> | /// </summary> | ||||
public string ConnectionString { get; set; } | |||||
public string ConnectionString { get; set; } = default!; | |||||
} | } | ||||
internal class ConfigureMySqlOptions : IConfigureOptions<MySqlOptions> | internal class ConfigureMySqlOptions : IConfigureOptions<MySqlOptions> | ||||
@@ -2,15 +2,9 @@ | |||||
<PropertyGroup> | <PropertyGroup> | ||||
<TargetFrameworks>net6.0;netstandard2.1</TargetFrameworks> | <TargetFrameworks>net6.0;netstandard2.1</TargetFrameworks> | ||||
<AssemblyName>DotNetCore.CAP.MySql</AssemblyName> | |||||
<Nullable>enable</Nullable> | |||||
<PackageTags>$(PackageTags);MySQL</PackageTags> | <PackageTags>$(PackageTags);MySQL</PackageTags> | ||||
</PropertyGroup> | </PropertyGroup> | ||||
<PropertyGroup> | |||||
<DocumentationFile>bin\$(Configuration)\netstandard2.1\DotNetCore.CAP.MySql.xml</DocumentationFile> | |||||
<NoWarn>1701;1702;1705;CS1591</NoWarn> | |||||
</PropertyGroup> | |||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' "> | <ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' "> | ||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" /> | <PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" /> | ||||
@@ -46,7 +46,7 @@ namespace DotNetCore.CAP.MySql | |||||
public async Task ChangeReceiveStateAsync(MediumMessage message, StatusName state) => | public async Task ChangeReceiveStateAsync(MediumMessage message, StatusName state) => | ||||
await ChangeMessageStateAsync(_recName, message, state); | await ChangeMessageStateAsync(_recName, message, state); | ||||
public MediumMessage StoreMessage(string name, Message content, object dbTransaction = null) | |||||
public MediumMessage StoreMessage(string name, Message content, object? dbTransaction = null) | |||||
{ | { | ||||
var sql = $"INSERT INTO `{_pubName}`(`Id`,`Version`,`Name`,`Content`,`Retries`,`Added`,`ExpiresAt`,`StatusName`)" + | var sql = $"INSERT INTO `{_pubName}`(`Id`,`Version`,`Name`,`Content`,`Retries`,`Added`,`ExpiresAt`,`StatusName`)" + | ||||
$" VALUES(@Id,'{_options.Value.Version}',@Name,@Content,@Retries,@Added,@ExpiresAt,@StatusName);"; | $" VALUES(@Id,'{_options.Value.Version}',@Name,@Content,@Retries,@Added,@ExpiresAt,@StatusName);"; | ||||
@@ -68,7 +68,7 @@ namespace DotNetCore.CAP.MySql | |||||
new MySqlParameter("@Content", message.Content), | new MySqlParameter("@Content", message.Content), | ||||
new MySqlParameter("@Retries", message.Retries), | new MySqlParameter("@Retries", message.Retries), | ||||
new MySqlParameter("@Added", message.Added), | new MySqlParameter("@Added", message.Added), | ||||
new MySqlParameter("@ExpiresAt", message.ExpiresAt.HasValue ? (object)message.ExpiresAt.Value : DBNull.Value), | |||||
new MySqlParameter("@ExpiresAt", message.ExpiresAt.HasValue ? message.ExpiresAt.Value : DBNull.Value), | |||||
new MySqlParameter("@StatusName", nameof(StatusName.Scheduled)), | new MySqlParameter("@StatusName", nameof(StatusName.Scheduled)), | ||||
}; | }; | ||||
@@ -85,7 +85,7 @@ namespace DotNetCore.CAP.MySql | |||||
dbTrans = dbContextTrans.GetDbTransaction(); | dbTrans = dbContextTrans.GetDbTransaction(); | ||||
} | } | ||||
var conn = dbTrans?.Connection; | |||||
var conn = dbTrans!.Connection!; | |||||
conn.ExecuteNonQuery(sql, dbTrans, sqlParams); | conn.ExecuteNonQuery(sql, dbTrans, sqlParams); | ||||
} | } | ||||
@@ -128,7 +128,7 @@ namespace DotNetCore.CAP.MySql | |||||
new MySqlParameter("@Content", _serializer.Serialize(mdMessage.Origin)), | new MySqlParameter("@Content", _serializer.Serialize(mdMessage.Origin)), | ||||
new MySqlParameter("@Retries", mdMessage.Retries), | new MySqlParameter("@Retries", mdMessage.Retries), | ||||
new MySqlParameter("@Added", mdMessage.Added), | new MySqlParameter("@Added", mdMessage.Added), | ||||
new MySqlParameter("@ExpiresAt", mdMessage.ExpiresAt.HasValue ? (object) mdMessage.ExpiresAt.Value : DBNull.Value), | |||||
new MySqlParameter("@ExpiresAt", mdMessage.ExpiresAt.HasValue ? mdMessage.ExpiresAt.Value : DBNull.Value), | |||||
new MySqlParameter("@StatusName", nameof(StatusName.Scheduled)) | new MySqlParameter("@StatusName", nameof(StatusName.Scheduled)) | ||||
}; | }; | ||||
@@ -198,7 +198,7 @@ namespace DotNetCore.CAP.MySql | |||||
messages.Add(new MediumMessage | messages.Add(new MediumMessage | ||||
{ | { | ||||
DbId = reader.GetInt64(0).ToString(), | DbId = reader.GetInt64(0).ToString(), | ||||
Origin = _serializer.Deserialize(reader.GetString(1)), | |||||
Origin = _serializer.Deserialize(reader.GetString(1))!, | |||||
Retries = reader.GetInt32(2), | Retries = reader.GetInt32(2), | ||||
Added = reader.GetDateTime(3) | Added = reader.GetDateTime(3) | ||||
}); | }); | ||||
@@ -9,7 +9,7 @@ namespace DotNetCore.CAP.MySql | |||||
{ | { | ||||
internal static class DbConnectionExtensions | internal static class DbConnectionExtensions | ||||
{ | { | ||||
public static int ExecuteNonQuery(this IDbConnection connection, string sql, IDbTransaction transaction = null, | |||||
public static int ExecuteNonQuery(this IDbConnection connection, string sql, IDbTransaction? transaction = null, | |||||
params object[] sqlParams) | params object[] sqlParams) | ||||
{ | { | ||||
if (connection.State == ConnectionState.Closed) | if (connection.State == ConnectionState.Closed) | ||||
@@ -33,7 +33,7 @@ namespace DotNetCore.CAP.MySql | |||||
return command.ExecuteNonQuery(); | return command.ExecuteNonQuery(); | ||||
} | } | ||||
public static T ExecuteReader<T>(this IDbConnection connection, string sql, Func<IDataReader, T> readerFunc, | |||||
public static T ExecuteReader<T>(this IDbConnection connection, string sql, Func<IDataReader, T>? readerFunc, | |||||
params object[] sqlParams) | params object[] sqlParams) | ||||
{ | { | ||||
if (connection.State == ConnectionState.Closed) | if (connection.State == ConnectionState.Closed) | ||||
@@ -51,7 +51,7 @@ namespace DotNetCore.CAP.MySql | |||||
var reader = command.ExecuteReader(); | var reader = command.ExecuteReader(); | ||||
T result = default; | |||||
T result = default!; | |||||
if (readerFunc != null) | if (readerFunc != null) | ||||
{ | { | ||||
result = readerFunc(reader); | result = readerFunc(reader); | ||||
@@ -77,14 +77,14 @@ namespace DotNetCore.CAP.MySql | |||||
var objValue = command.ExecuteScalar(); | var objValue = command.ExecuteScalar(); | ||||
T result = default; | |||||
T result = default!; | |||||
if (objValue != null) | if (objValue != null) | ||||
{ | { | ||||
var returnType = typeof(T); | var returnType = typeof(T); | ||||
var converter = TypeDescriptor.GetConverter(returnType); | var converter = TypeDescriptor.GetConverter(returnType); | ||||
if (converter.CanConvertFrom(objValue.GetType())) | if (converter.CanConvertFrom(objValue.GetType())) | ||||
{ | { | ||||
result = (T)converter.ConvertFrom(objValue); | |||||
result = (T)converter.ConvertFrom(objValue)!; | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
@@ -19,7 +19,7 @@ namespace Microsoft.EntityFrameworkCore.Storage | |||||
public CapEFDbTransaction(ICapTransaction transaction) | public CapEFDbTransaction(ICapTransaction transaction) | ||||
{ | { | ||||
_transaction = transaction; | _transaction = transaction; | ||||
var dbContextTransaction = (IDbContextTransaction)_transaction.DbTransaction; | |||||
var dbContextTransaction = (IDbContextTransaction)_transaction.DbTransaction!; | |||||
TransactionId = dbContextTransaction.TransactionId; | TransactionId = dbContextTransaction.TransactionId; | ||||
} | } | ||||
@@ -60,7 +60,7 @@ namespace Microsoft.EntityFrameworkCore.Storage | |||||
{ | { | ||||
get | get | ||||
{ | { | ||||
var dbContextTransaction = (IDbContextTransaction)_transaction.DbTransaction; | |||||
var dbContextTransaction = (IDbContextTransaction)_transaction.DbTransaction!; | |||||
return dbContextTransaction.GetDbTransaction(); | return dbContextTransaction.GetDbTransaction(); | ||||
} | } | ||||
} | } | ||||
@@ -247,18 +247,18 @@ WHERE `Key` >= @minKey | |||||
return result; | return result; | ||||
} | } | ||||
public async Task<MediumMessage> GetPublishedMessageAsync(long id) => await GetMessageAsync(_pubName, id); | |||||
public async Task<MediumMessage?> GetPublishedMessageAsync(long id) => await GetMessageAsync(_pubName, id); | |||||
public async Task<MediumMessage> GetReceivedMessageAsync(long id) => await GetMessageAsync(_recName, id); | |||||
public async Task<MediumMessage?> GetReceivedMessageAsync(long id) => await GetMessageAsync(_recName, id); | |||||
private async Task<MediumMessage> GetMessageAsync(string tableName, long id) | |||||
private async Task<MediumMessage?> GetMessageAsync(string tableName, long id) | |||||
{ | { | ||||
var sql = $@"SELECT `Id` as DbId, `Content`,`Added`,`ExpiresAt`,`Retries` FROM `{tableName}` WHERE Id={id};"; | var sql = $@"SELECT `Id` as DbId, `Content`,`Added`,`ExpiresAt`,`Retries` FROM `{tableName}` WHERE Id={id};"; | ||||
await using var connection = new MySqlConnection(_options.ConnectionString); | await using var connection = new MySqlConnection(_options.ConnectionString); | ||||
var mediumMessage = connection.ExecuteReader(sql, reader => | var mediumMessage = connection.ExecuteReader(sql, reader => | ||||
{ | { | ||||
MediumMessage message = null; | |||||
MediumMessage? message = null; | |||||
while (reader.Read()) | while (reader.Read()) | ||||
{ | { | ||||
@@ -11,9 +11,9 @@ namespace DotNetCore.CAP.Monitoring | |||||
{ | { | ||||
public interface IMonitoringApi | public interface IMonitoringApi | ||||
{ | { | ||||
Task<MediumMessage> GetPublishedMessageAsync(long id); | |||||
Task<MediumMessage?> GetPublishedMessageAsync(long id); | |||||
Task<MediumMessage> GetReceivedMessageAsync(long id); | |||||
Task<MediumMessage?> GetReceivedMessageAsync(long id); | |||||
StatisticsDto GetStatistics(); | StatisticsDto GetStatistics(); | ||||