Browse Source

cleanup

master
Savorboard 7 years ago
parent
commit
e76a4299d1
14 changed files with 39 additions and 28 deletions
  1. +1
    -1
      src/DotNetCore.CAP.Kafka/CAP.KafkaOptions.cs
  2. +1
    -4
      src/DotNetCore.CAP.Kafka/KafkaConsumerClientFactory.cs
  3. +1
    -1
      src/DotNetCore.CAP.MySql/CAP.MySqlCapOptionsExtension.cs
  4. +4
    -3
      src/DotNetCore.CAP.MySql/CapPublisher.cs
  5. +1
    -1
      src/DotNetCore.CAP.PostgreSql/CAP.PostgreSqlCapOptionsExtension.cs
  6. +5
    -5
      src/DotNetCore.CAP.PostgreSql/CapPublisher.cs
  7. +1
    -1
      src/DotNetCore.CAP.PostgreSql/IAdditionalProcessor.Default.cs
  8. +3
    -3
      src/DotNetCore.CAP.SqlServer/CapPublisher.cs
  9. +1
    -1
      src/DotNetCore.CAP/Abstractions/CapPublisherBase.cs
  10. +7
    -1
      src/DotNetCore.CAP/Infrastructure/ObjectId.cs
  11. +1
    -1
      src/DotNetCore.CAP/Internal/ConsumerInvokerFactory.cs
  12. +0
    -1
      src/DotNetCore.CAP/Internal/IModelBinder.ComplexType.cs
  13. +12
    -4
      src/DotNetCore.CAP/Internal/MethodBindException.cs
  14. +1
    -1
      src/DotNetCore.CAP/Models/Message.cs

+ 1
- 1
src/DotNetCore.CAP.Kafka/CAP.KafkaOptions.cs View File

@@ -42,7 +42,7 @@ namespace DotNetCore.CAP
{ {
throw new ArgumentNullException(nameof(Servers)); throw new ArgumentNullException(nameof(Servers));
} }
MainConfig.Add("bootstrap.servers", Servers); MainConfig.Add("bootstrap.servers", Servers);


MainConfig["queue.buffering.max.ms"] = "10"; MainConfig["queue.buffering.max.ms"] = "10";


+ 1
- 4
src/DotNetCore.CAP.Kafka/KafkaConsumerClientFactory.cs View File

@@ -1,7 +1,4 @@
using System;
using Microsoft.Extensions.Options;

namespace DotNetCore.CAP.Kafka
namespace DotNetCore.CAP.Kafka
{ {
internal sealed class KafkaConsumerClientFactory : IConsumerClientFactory internal sealed class KafkaConsumerClientFactory : IConsumerClientFactory
{ {


+ 1
- 1
src/DotNetCore.CAP.MySql/CAP.MySqlCapOptionsExtension.cs View File

@@ -34,7 +34,7 @@ namespace DotNetCore.CAP
var dbContext = (DbContext)x.GetService(mysqlOptions.DbContextType); var dbContext = (DbContext)x.GetService(mysqlOptions.DbContextType);
mysqlOptions.ConnectionString = dbContext.Database.GetDbConnection().ConnectionString; mysqlOptions.ConnectionString = dbContext.Database.GetDbConnection().ConnectionString;
return mysqlOptions; return mysqlOptions;
});
});
} }
else else
{ {


+ 4
- 3
src/DotNetCore.CAP.MySql/CapPublisher.cs View File

@@ -37,7 +37,7 @@ namespace DotNetCore.CAP.MySql
DbConnection = _dbContext.Database.GetDbConnection(); DbConnection = _dbContext.Database.GetDbConnection();
var dbContextTransaction = _dbContext.Database.CurrentTransaction; var dbContextTransaction = _dbContext.Database.CurrentTransaction;
var dbTrans = dbContextTransaction?.GetDbTransaction(); var dbTrans = dbContextTransaction?.GetDbTransaction();
//DbTransaction is dispose in original
//DbTransaction is dispose in original
if (dbTrans?.Connection == null) if (dbTrans?.Connection == null)
{ {
IsCapOpenedTrans = true; IsCapOpenedTrans = true;
@@ -58,7 +58,7 @@ namespace DotNetCore.CAP.MySql
protected override async Task ExecuteAsync(IDbConnection dbConnection, IDbTransaction dbTransaction, CapPublishedMessage message) protected override async Task ExecuteAsync(IDbConnection dbConnection, IDbTransaction dbTransaction, CapPublishedMessage message)
{ {
await dbConnection.ExecuteAsync(PrepareSql(), message, dbTransaction); await dbConnection.ExecuteAsync(PrepareSql(), message, dbTransaction);
_logger.LogInformation("Published Message has been persisted in the database. name:" + message.ToString()); _logger.LogInformation("Published Message has been persisted in the database. name:" + message.ToString());
} }


@@ -69,7 +69,8 @@ namespace DotNetCore.CAP.MySql
await conn.ExecuteAsync(PrepareSql(), message); await conn.ExecuteAsync(PrepareSql(), message);
} }
} }
#region private methods

#region private methods


private string PrepareSql() private string PrepareSql()
{ {


+ 1
- 1
src/DotNetCore.CAP.PostgreSql/CAP.PostgreSqlCapOptionsExtension.cs View File

@@ -1,6 +1,6 @@
using System; using System;
using DotNetCore.CAP.Processor;
using DotNetCore.CAP.PostgreSql; using DotNetCore.CAP.PostgreSql;
using DotNetCore.CAP.Processor;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;




+ 5
- 5
src/DotNetCore.CAP.PostgreSql/CapPublisher.cs View File

@@ -2,8 +2,8 @@
using System.Data; using System.Data;
using System.Threading.Tasks; using System.Threading.Tasks;
using Dapper; using Dapper;
using DotNetCore.CAP.Models;
using DotNetCore.CAP.Abstractions; using DotNetCore.CAP.Abstractions;
using DotNetCore.CAP.Models;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@@ -28,7 +28,7 @@ namespace DotNetCore.CAP.PostgreSql
if (_options.DbContextType != null) if (_options.DbContextType != null)
{ {
IsUsingEF = true; IsUsingEF = true;
_dbContext = (DbContext)ServiceProvider.GetService(_options.DbContextType);
_dbContext = (DbContext)ServiceProvider.GetService(_options.DbContextType);
} }
} }


@@ -37,7 +37,7 @@ namespace DotNetCore.CAP.PostgreSql
DbConnection = _dbContext.Database.GetDbConnection(); DbConnection = _dbContext.Database.GetDbConnection();
var dbContextTransaction = _dbContext.Database.CurrentTransaction; var dbContextTransaction = _dbContext.Database.CurrentTransaction;
var dbTrans = dbContextTransaction?.GetDbTransaction(); var dbTrans = dbContextTransaction?.GetDbTransaction();
//DbTransaction is dispose in original
//DbTransaction is dispose in original
if (dbTrans?.Connection == null) if (dbTrans?.Connection == null)
{ {
IsCapOpenedTrans = true; IsCapOpenedTrans = true;
@@ -75,8 +75,8 @@ namespace DotNetCore.CAP.PostgreSql
private string PrepareSql() private string PrepareSql()
{ {
return $"INSERT INTO \"{_options.Schema}\".\"published\" (\"Name\",\"Content\",\"Retries\",\"Added\",\"ExpiresAt\",\"StatusName\")VALUES(@Name,@Content,@Retries,@Added,@ExpiresAt,@StatusName)"; return $"INSERT INTO \"{_options.Schema}\".\"published\" (\"Name\",\"Content\",\"Retries\",\"Added\",\"ExpiresAt\",\"StatusName\")VALUES(@Name,@Content,@Retries,@Added,@ExpiresAt,@StatusName)";
}
}


#endregion
#endregion private methods
} }
} }

+ 1
- 1
src/DotNetCore.CAP.PostgreSql/IAdditionalProcessor.Default.cs View File

@@ -44,7 +44,7 @@ namespace DotNetCore.CAP.PostgreSql
using (var connection = new NpgsqlConnection(_options.ConnectionString)) using (var connection = new NpgsqlConnection(_options.ConnectionString))
{ {
removedCount = await connection.ExecuteAsync($"DELETE FROM \"{_options.Schema}\".\"{table}\" WHERE \"ExpiresAt\" < @now AND \"Id\" IN (SELECT \"Id\" FROM \"{_options.Schema}\".\"{table}\" LIMIT @count);", removedCount = await connection.ExecuteAsync($"DELETE FROM \"{_options.Schema}\".\"{table}\" WHERE \"ExpiresAt\" < @now AND \"Id\" IN (SELECT \"Id\" FROM \"{_options.Schema}\".\"{table}\" LIMIT @count);",
new { now = DateTime.Now, count = MaxBatch });
new { now = DateTime.Now, count = MaxBatch });
} }


if (removedCount != 0) if (removedCount != 0)


+ 3
- 3
src/DotNetCore.CAP.SqlServer/CapPublisher.cs View File

@@ -37,7 +37,7 @@ namespace DotNetCore.CAP.SqlServer
DbConnection = _dbContext.Database.GetDbConnection(); DbConnection = _dbContext.Database.GetDbConnection();
var dbContextTransaction = _dbContext.Database.CurrentTransaction; var dbContextTransaction = _dbContext.Database.CurrentTransaction;
var dbTrans = dbContextTransaction?.GetDbTransaction(); var dbTrans = dbContextTransaction?.GetDbTransaction();
//DbTransaction is dispose in original
//DbTransaction is dispose in original
if (dbTrans?.Connection == null) if (dbTrans?.Connection == null)
{ {
IsCapOpenedTrans = true; IsCapOpenedTrans = true;
@@ -66,8 +66,8 @@ namespace DotNetCore.CAP.SqlServer
{ {
using (var conn = new SqlConnection(_options.ConnectionString)) using (var conn = new SqlConnection(_options.ConnectionString))
{ {
await conn.ExecuteAsync(PrepareSql(), message);
}
await conn.ExecuteAsync(PrepareSql(), message);
}
} }


#region private methods #region private methods


+ 1
- 1
src/DotNetCore.CAP/Abstractions/CapPublisherBase.cs View File

@@ -160,4 +160,4 @@ namespace DotNetCore.CAP.Abstractions


#endregion private methods #endregion private methods
} }
}
}

+ 7
- 1
src/DotNetCore.CAP/Infrastructure/ObjectId.cs View File

@@ -16,12 +16,14 @@ namespace DotNetCore.CAP
{ {
// private static fields // private static fields
private static readonly DateTime __unixEpoch; private static readonly DateTime __unixEpoch;

private static readonly long __dateTimeMaxValueMillisecondsSinceEpoch; private static readonly long __dateTimeMaxValueMillisecondsSinceEpoch;
private static readonly long __dateTimeMinValueMillisecondsSinceEpoch; private static readonly long __dateTimeMinValueMillisecondsSinceEpoch;
private static ObjectId __emptyInstance = default(ObjectId); private static ObjectId __emptyInstance = default(ObjectId);
private static int __staticMachine; private static int __staticMachine;
private static short __staticPid; private static short __staticPid;
private static int __staticIncrement; // high byte will be masked out when generating new ObjectId private static int __staticIncrement; // high byte will be masked out when generating new ObjectId

private static uint[] _lookup32 = Enumerable.Range(0, 256).Select(i => private static uint[] _lookup32 = Enumerable.Range(0, 256).Select(i =>
{ {
string s = i.ToString("x2"); string s = i.ToString("x2");
@@ -32,6 +34,7 @@ namespace DotNetCore.CAP
// the extra two bytes are not visible to anyone outside of this class and they buy us considerable simplification // the extra two bytes are not visible to anyone outside of this class and they buy us considerable simplification
// an additional advantage of this representation is that it will serialize to JSON without any 64 bit overflow problems // an additional advantage of this representation is that it will serialize to JSON without any 64 bit overflow problems
private int _timestamp; private int _timestamp;

private int _machine; private int _machine;
private short _pid; private short _pid;
private int _increment; private int _increment;
@@ -475,6 +478,7 @@ namespace DotNetCore.CAP


return arr; return arr;
} }

/// <summary> /// <summary>
/// Converts a byte array to a hex string. /// Converts a byte array to a hex string.
/// </summary> /// </summary>
@@ -495,6 +499,7 @@ namespace DotNetCore.CAP
} }
return new string(result); return new string(result);
} }

/// <summary> /// <summary>
/// Converts a DateTime to number of milliseconds since Unix epoch. /// Converts a DateTime to number of milliseconds since Unix epoch.
/// </summary> /// </summary>
@@ -505,6 +510,7 @@ namespace DotNetCore.CAP
var utcDateTime = ToUniversalTime(dateTime); var utcDateTime = ToUniversalTime(dateTime);
return (utcDateTime - __unixEpoch).Ticks / 10000; return (utcDateTime - __unixEpoch).Ticks / 10000;
} }

/// <summary> /// <summary>
/// Converts a DateTime to UTC (with special handling for MinValue and MaxValue). /// Converts a DateTime to UTC (with special handling for MinValue and MaxValue).
/// </summary> /// </summary>
@@ -537,4 +543,4 @@ namespace DotNetCore.CAP
return val - (val < 58 ? 48 : (val < 97 ? 55 : 87)); return val - (val < 58 ? 48 : (val < 97 ? 55 : 87));
} }
} }
}
}

+ 1
- 1
src/DotNetCore.CAP/Internal/ConsumerInvokerFactory.cs View File

@@ -23,7 +23,7 @@ namespace DotNetCore.CAP.Internal


public IConsumerInvoker CreateInvoker(ConsumerContext consumerContext) public IConsumerInvoker CreateInvoker(ConsumerContext consumerContext)
{ {
using(var scope = _serviceProvider.CreateScope())
using (var scope = _serviceProvider.CreateScope())
{ {
var context = new ConsumerInvokerContext(consumerContext) var context = new ConsumerInvokerContext(consumerContext)
{ {


+ 0
- 1
src/DotNetCore.CAP/Internal/IModelBinder.ComplexType.cs View File

@@ -3,7 +3,6 @@ using System.Reflection;
using System.Threading.Tasks; using System.Threading.Tasks;
using DotNetCore.CAP.Abstractions.ModelBinding; using DotNetCore.CAP.Abstractions.ModelBinding;
using DotNetCore.CAP.Infrastructure; using DotNetCore.CAP.Infrastructure;
using DotNetCore.CAP.Models;


namespace DotNetCore.CAP.Internal namespace DotNetCore.CAP.Internal
{ {


+ 12
- 4
src/DotNetCore.CAP/Internal/MethodBindException.cs View File

@@ -5,8 +5,16 @@ namespace DotNetCore.CAP.Internal
[Serializable] [Serializable]
public class MethodBindException : Exception public class MethodBindException : Exception
{ {
public MethodBindException() { }
public MethodBindException(string message) : base(message) { }
public MethodBindException(string message, Exception inner) : base(message, inner) { }
public MethodBindException()
{
}

public MethodBindException(string message) : base(message)
{
}

public MethodBindException(string message, Exception inner) : base(message, inner)
{
}
} }
}
}

+ 1
- 1
src/DotNetCore.CAP/Models/Message.cs View File

@@ -23,4 +23,4 @@ namespace DotNetCore.CAP.Models
Content = content; Content = content;
} }
} }
}
}

Loading…
Cancel
Save