From 591f2c73819cf8e1fe2299f7f1445d11ded91fe8 Mon Sep 17 00:00:00 2001 From: yangxiaodong Date: Fri, 8 Sep 2017 17:47:44 +0800 Subject: [PATCH] add dashboard of sql server storage impl --- .../MySqlStorageConnection.cs | 12 ++++++++++ .../PostgreSqlStorageConnection.cs | 11 ++++++++++ .../SqlServerMonitoringApi.cs | 5 +++++ .../SqlServerStorageConnection.cs | 22 +++++++++++++++++++ 4 files changed, 50 insertions(+) diff --git a/src/DotNetCore.CAP.MySql/MySqlStorageConnection.cs b/src/DotNetCore.CAP.MySql/MySqlStorageConnection.cs index 839ad93..f1121e1 100644 --- a/src/DotNetCore.CAP.MySql/MySqlStorageConnection.cs +++ b/src/DotNetCore.CAP.MySql/MySqlStorageConnection.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using Dapper; using DotNetCore.CAP.Infrastructure; using DotNetCore.CAP.Models; +using DotNetCore.CAP.Processor.States; using MySql.Data.MySqlClient; namespace DotNetCore.CAP.MySql @@ -117,6 +118,7 @@ VALUES(@Name,@Group,@Content,@Retries,@Added,@ExpiresAt,@StatusName);"; } } + public void Dispose() { } @@ -168,5 +170,15 @@ VALUES(@Name,@Group,@Content,@Retries,@Added,@ExpiresAt,@StatusName);"; { throw new NotImplementedException(); } + + public bool ChangePublishedState(int messageId, IState state) + { + throw new NotImplementedException(); + } + + public bool ChangeReceivedState(int messageId, IState state) + { + throw new NotImplementedException(); + } } } \ No newline at end of file diff --git a/src/DotNetCore.CAP.PostgreSql/PostgreSqlStorageConnection.cs b/src/DotNetCore.CAP.PostgreSql/PostgreSqlStorageConnection.cs index 451372a..f79d3de 100644 --- a/src/DotNetCore.CAP.PostgreSql/PostgreSqlStorageConnection.cs +++ b/src/DotNetCore.CAP.PostgreSql/PostgreSqlStorageConnection.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using Dapper; using DotNetCore.CAP.Infrastructure; using DotNetCore.CAP.Models; +using DotNetCore.CAP.Processor.States; using Npgsql; namespace DotNetCore.CAP.PostgreSql @@ -153,5 +154,15 @@ namespace DotNetCore.CAP.PostgreSql { throw new NotImplementedException(); } + + public bool ChangePublishedState(int messageId, IState state) + { + throw new NotImplementedException(); + } + + public bool ChangeReceivedState(int messageId, IState state) + { + throw new NotImplementedException(); + } } } \ No newline at end of file diff --git a/src/DotNetCore.CAP.SqlServer/SqlServerMonitoringApi.cs b/src/DotNetCore.CAP.SqlServer/SqlServerMonitoringApi.cs index 4cfe20c..4959592 100644 --- a/src/DotNetCore.CAP.SqlServer/SqlServerMonitoringApi.cs +++ b/src/DotNetCore.CAP.SqlServer/SqlServerMonitoringApi.cs @@ -94,6 +94,10 @@ _options.Schema); { where += " and name=@Name"; } + if (!string.IsNullOrEmpty(queryDto.Name)) + { + where += " and group=@Group"; + } if (!string.IsNullOrEmpty(queryDto.Content)) { where += " and content like '%@Content%'"; @@ -106,6 +110,7 @@ _options.Schema); return conn.Query(sqlQuery, new { StatusName = queryDto.StatusName, + Group = queryDto.Group, Name = queryDto.Name, Content = queryDto.Content, Offset = queryDto.CurrentPage * queryDto.PageSize, diff --git a/src/DotNetCore.CAP.SqlServer/SqlServerStorageConnection.cs b/src/DotNetCore.CAP.SqlServer/SqlServerStorageConnection.cs index 13b0aba..d106351 100644 --- a/src/DotNetCore.CAP.SqlServer/SqlServerStorageConnection.cs +++ b/src/DotNetCore.CAP.SqlServer/SqlServerStorageConnection.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Dapper; using DotNetCore.CAP.Infrastructure; using DotNetCore.CAP.Models; +using DotNetCore.CAP.Processor.States; namespace DotNetCore.CAP.SqlServer { @@ -65,6 +66,16 @@ OUTPUT DELETED.MessageId,DELETED.[MessageType];"; } } + public bool ChangePublishedState(int messageId, IState state) + { + var sql = $"UPDATE [{_options.Schema}].[Published] SET Retries=Retries+1,StatusName = '{state.Name}' WHERE Id={messageId}"; + + using (var connection = new SqlConnection(_options.ConnectionString)) + { + return connection.Execute(sql) > 0; + } + } + // CapReceviedMessage public async Task StoreReceivedMessageAsync(CapReceivedMessage message) @@ -108,6 +119,16 @@ VALUES(@Name,@Group,@Content,@Retries,@Added,@ExpiresAt,@StatusName);"; } } + public bool ChangeReceivedState(int messageId, IState state) + { + var sql = $"UPDATE [{_options.Schema}].[Received] SET Retries=Retries+1,StatusName = '{state.Name}' WHERE Id={messageId}"; + + using (var connection = new SqlConnection(_options.ConnectionString)) + { + return connection.Execute(sql) > 0; + } + } + public void Dispose() { } @@ -161,5 +182,6 @@ VALUES(@Name,@Group,@Content,@Retries,@Added,@ExpiresAt,@StatusName);"; { return new StateData(); } + } } \ No newline at end of file