Procházet zdrojové kódy

Enable #nullable for mysql storage.

master
Savorboard před 3 roky
rodič
revize
2e2b45f833
9 změnil soubory, kde provedl 25 přidání a 31 odebrání
  1. +4
    -4
      src/DotNetCore.CAP.InMemoryStorage/IMonitoringApi.InMemory.cs
  2. +1
    -1
      src/DotNetCore.CAP.MySql/CAP.EFOptions.cs
  3. +1
    -1
      src/DotNetCore.CAP.MySql/CAP.MySqlOptions.cs
  4. +1
    -7
      src/DotNetCore.CAP.MySql/DotNetCore.CAP.MySql.csproj
  5. +5
    -5
      src/DotNetCore.CAP.MySql/IDataStorage.MySql.cs
  6. +5
    -5
      src/DotNetCore.CAP.MySql/IDbConnection.Extensions.cs
  7. +2
    -2
      src/DotNetCore.CAP.MySql/IDbContextTransaction.CAP.cs
  8. +4
    -4
      src/DotNetCore.CAP.MySql/IMonitoringApi.MySql.cs
  9. +2
    -2
      src/DotNetCore.CAP/Monitoring/IMonitoringApi.cs

+ 4
- 4
src/DotNetCore.CAP.InMemoryStorage/IMonitoringApi.InMemory.cs Zobrazit soubor

@@ -15,14 +15,14 @@ namespace DotNetCore.CAP.InMemoryStorage
{
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()


+ 1
- 1
src/DotNetCore.CAP.MySql/CAP.EFOptions.cs Zobrazit soubor

@@ -18,7 +18,7 @@ namespace DotNetCore.CAP
/// <summary>
/// EF db context type.
/// </summary>
internal Type DbContextType { get; set; }
internal Type? DbContextType { get; set; }

/// <summary>
/// Data version


+ 1
- 1
src/DotNetCore.CAP.MySql/CAP.MySqlOptions.cs Zobrazit soubor

@@ -13,7 +13,7 @@ namespace DotNetCore.CAP
/// <summary>
/// Gets or sets the database's connection string that will be used to store database entities.
/// </summary>
public string ConnectionString { get; set; }
public string ConnectionString { get; set; } = default!;
}

internal class ConfigureMySqlOptions : IConfigureOptions<MySqlOptions>


+ 1
- 7
src/DotNetCore.CAP.MySql/DotNetCore.CAP.MySql.csproj Zobrazit soubor

@@ -2,15 +2,9 @@

<PropertyGroup>
<TargetFrameworks>net6.0;netstandard2.1</TargetFrameworks>
<AssemblyName>DotNetCore.CAP.MySql</AssemblyName>
<Nullable>enable</Nullable>
<PackageTags>$(PackageTags);MySQL</PackageTags>
</PropertyGroup>

<PropertyGroup>
<DocumentationFile>bin\$(Configuration)\netstandard2.1\DotNetCore.CAP.MySql.xml</DocumentationFile>
<NoWarn>1701;1702;1705;CS1591</NoWarn>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />


+ 5
- 5
src/DotNetCore.CAP.MySql/IDataStorage.MySql.cs Zobrazit soubor

@@ -46,7 +46,7 @@ namespace DotNetCore.CAP.MySql
public async Task ChangeReceiveStateAsync(MediumMessage message, StatusName 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`)" +
$" 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("@Retries", message.Retries),
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)),
};

@@ -85,7 +85,7 @@ namespace DotNetCore.CAP.MySql
dbTrans = dbContextTrans.GetDbTransaction();
}

var conn = dbTrans?.Connection;
var conn = dbTrans!.Connection!;
conn.ExecuteNonQuery(sql, dbTrans, sqlParams);
}

@@ -128,7 +128,7 @@ namespace DotNetCore.CAP.MySql
new MySqlParameter("@Content", _serializer.Serialize(mdMessage.Origin)),
new MySqlParameter("@Retries", mdMessage.Retries),
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))
};

@@ -198,7 +198,7 @@ namespace DotNetCore.CAP.MySql
messages.Add(new MediumMessage
{
DbId = reader.GetInt64(0).ToString(),
Origin = _serializer.Deserialize(reader.GetString(1)),
Origin = _serializer.Deserialize(reader.GetString(1))!,
Retries = reader.GetInt32(2),
Added = reader.GetDateTime(3)
});


+ 5
- 5
src/DotNetCore.CAP.MySql/IDbConnection.Extensions.cs Zobrazit soubor

@@ -9,7 +9,7 @@ namespace DotNetCore.CAP.MySql
{
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)
{
if (connection.State == ConnectionState.Closed)
@@ -33,7 +33,7 @@ namespace DotNetCore.CAP.MySql
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)
{
if (connection.State == ConnectionState.Closed)
@@ -51,7 +51,7 @@ namespace DotNetCore.CAP.MySql

var reader = command.ExecuteReader();

T result = default;
T result = default!;
if (readerFunc != null)
{
result = readerFunc(reader);
@@ -77,14 +77,14 @@ namespace DotNetCore.CAP.MySql

var objValue = command.ExecuteScalar();

T result = default;
T result = default!;
if (objValue != null)
{
var returnType = typeof(T);
var converter = TypeDescriptor.GetConverter(returnType);
if (converter.CanConvertFrom(objValue.GetType()))
{
result = (T)converter.ConvertFrom(objValue);
result = (T)converter.ConvertFrom(objValue)!;
}
else
{


+ 2
- 2
src/DotNetCore.CAP.MySql/IDbContextTransaction.CAP.cs Zobrazit soubor

@@ -19,7 +19,7 @@ namespace Microsoft.EntityFrameworkCore.Storage
public CapEFDbTransaction(ICapTransaction transaction)
{
_transaction = transaction;
var dbContextTransaction = (IDbContextTransaction)_transaction.DbTransaction;
var dbContextTransaction = (IDbContextTransaction)_transaction.DbTransaction!;
TransactionId = dbContextTransaction.TransactionId;
}

@@ -60,7 +60,7 @@ namespace Microsoft.EntityFrameworkCore.Storage
{
get
{
var dbContextTransaction = (IDbContextTransaction)_transaction.DbTransaction;
var dbContextTransaction = (IDbContextTransaction)_transaction.DbTransaction!;
return dbContextTransaction.GetDbTransaction();
}
}


+ 4
- 4
src/DotNetCore.CAP.MySql/IMonitoringApi.MySql.cs Zobrazit soubor

@@ -247,18 +247,18 @@ WHERE `Key` >= @minKey
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};";

await using var connection = new MySqlConnection(_options.ConnectionString);
var mediumMessage = connection.ExecuteReader(sql, reader =>
{
MediumMessage message = null;
MediumMessage? message = null;

while (reader.Read())
{


+ 2
- 2
src/DotNetCore.CAP/Monitoring/IMonitoringApi.cs Zobrazit soubor

@@ -11,9 +11,9 @@ namespace DotNetCore.CAP.Monitoring
{
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();



Načítá se…
Zrušit
Uložit