diff --git a/src/DotNetCore.CAP.PostgreSql/CAP.PostgreSqlCapOptionsExtension.cs b/src/DotNetCore.CAP.PostgreSql/CAP.PostgreSqlCapOptionsExtension.cs index 128cad9..75d56b5 100644 --- a/src/DotNetCore.CAP.PostgreSql/CAP.PostgreSqlCapOptionsExtension.cs +++ b/src/DotNetCore.CAP.PostgreSql/CAP.PostgreSqlCapOptionsExtension.cs @@ -34,7 +34,7 @@ namespace DotNetCore.CAP using (var scope = x.CreateScope()) { var provider = scope.ServiceProvider; - var dbContext = (DbContext) provider.GetService(postgreSqlOptions.DbContextType); + var dbContext = (DbContext)provider.GetService(postgreSqlOptions.DbContextType); postgreSqlOptions.ConnectionString = dbContext.Database.GetDbConnection().ConnectionString; return postgreSqlOptions; } diff --git a/src/DotNetCore.CAP.PostgreSql/PostgreSqlMonitoringApi.cs b/src/DotNetCore.CAP.PostgreSql/PostgreSqlMonitoringApi.cs index 3306bf3..0f9f469 100644 --- a/src/DotNetCore.CAP.PostgreSql/PostgreSqlMonitoringApi.cs +++ b/src/DotNetCore.CAP.PostgreSql/PostgreSqlMonitoringApi.cs @@ -24,12 +24,12 @@ namespace DotNetCore.CAP.PostgreSql public StatisticsDto GetStatistics() { var sql = string.Format(@" -select count(Id) from ""{0}"".""published"" where ""StatusName"" = N'Succeeded'; -select count(Id) from ""{0}"".""received"" where ""StatusName"" = N'Succeeded'; -select count(Id) from ""{0}"".""published"" where ""StatusName"" = N'Failed'; -select count(Id) from ""{0}"".""received"" where ""StatusName"" = N'Failed'; -select count(Id) from ""{0}"".""published"" where ""StatusName"" in (N'Processing',N'Scheduled',N'Enqueued'); -select count(Id) from ""{0}"".""received"" where ""StatusName"" in (N'Processing',N'Scheduled',N'Enqueued');", +select count(""Id"") from ""{0}"".""published"" where ""StatusName"" = N'Succeeded'; +select count(""Id"") from ""{0}"".""received"" where ""StatusName"" = N'Succeeded'; +select count(""Id"") from ""{0}"".""published"" where ""StatusName"" = N'Failed'; +select count(""Id"") from ""{0}"".""received"" where ""StatusName"" = N'Failed'; +select count(""Id"") from ""{0}"".""published"" where ""StatusName"" in (N'Processing',N'Scheduled',N'Enqueued'); +select count(""Id"") from ""{0}"".""received"" where ""StatusName"" in (N'Processing',N'Scheduled',N'Enqueued');", _options.Schema); var statistics = UseConnection(connection => @@ -130,10 +130,10 @@ select count(Id) from ""{0}"".""received"" where ""StatusName"" in (N'Processin private int GetNumberOfMessage(IDbConnection connection, string tableName, string statusName) { var sqlQuery = statusName == StatusName.Processing - ? $"select count(Id) from \"{_options.Schema}\".\"{tableName}\" where \"StatusName\" in (N'Processing',N'Scheduled',N'Enqueued')" - : $"select count(Id) from \"{_options.Schema}\".\"{tableName}\" where \"StatusName\" = @state"; + ? $"select count(\"Id\") from \"{_options.Schema}\".\"{tableName}\" where \"StatusName\" in (N'Processing',N'Scheduled',N'Enqueued')" + : $"select count(\"Id\") from \"{_options.Schema}\".\"{tableName}\" where \"StatusName\" = @state"; - var count = connection.ExecuteScalar(sqlQuery, new {state = statusName}); + var count = connection.ExecuteScalar(sqlQuery, new { state = statusName }); return count; } @@ -174,12 +174,11 @@ with aggr as ( where ""StatusName"" = N'Processing' group by to_char(""Added"", 'yyyy-MM-dd-HH') ) -select ""Key"",""Count"" from aggr where ""Key"" in @keys;"; +select ""Key"",""Count"" from aggr where ""Key""=Any(@keys);"; - var valuesMap = connection.Query( - sqlQuery, - new {keys = keyMaps.Keys, statusName}) - .ToDictionary(x => (string) x.Key, x => (int) x.Count); + var valuesMap = connection.Query(sqlQuery,new { keys = keyMaps.Keys.ToList(), statusName }) + .ToList() + .ToDictionary(x => (string)x.Key, x => (int)x.Count); foreach (var key in keyMaps.Keys) if (!valuesMap.ContainsKey(key)) valuesMap.Add(key, 0); diff --git a/src/DotNetCore.CAP/IConsumerHandler.Default.cs b/src/DotNetCore.CAP/IConsumerHandler.Default.cs index 63afaa1..5d6fb66 100644 --- a/src/DotNetCore.CAP/IConsumerHandler.Default.cs +++ b/src/DotNetCore.CAP/IConsumerHandler.Default.cs @@ -40,9 +40,9 @@ namespace DotNetCore.CAP public void Start() { - var groupingMatchs = _selector.GetCandidatesMethodsOfGroupNameGrouped(); + var groupingMatches = _selector.GetCandidatesMethodsOfGroupNameGrouped(); - foreach (var matchGroup in groupingMatchs) + foreach (var matchGroup in groupingMatches) Task.Factory.StartNew(() => { using (var client = _consumerClientFactory.Create(matchGroup.Key))