Browse Source

bsDatashow

xf 1 năm trước cách đây
mục cha
commit
9274f38cb7

+ 5 - 0
src/Hotline.Api/Realtimes/RealtimeMethods.cs

@@ -44,6 +44,11 @@
 
         #endregion
 
+        #region 大屏-数据展示
+
+        public static string BsDataShow = "BsDataShow";
+
+        #endregion
     }
 }
     

+ 8 - 10
src/Hotline.Api/Realtimes/RealtimeService.cs

@@ -138,7 +138,7 @@ public class RealtimeService : IRealtimeService, IScopeDependency
         if (record.CircularType == Share.Enums.Article.ECircularType.Person)
         {
             //个人
-            await SendMsgToUserAsync(record.UserId, RealtimeMethods.CircularRecord,
+            await SendToUserAsync(record.UserId, RealtimeMethods.CircularRecord,
                 new CircularRecoordDto() { CircularType = Share.Enums.Article.ECircularType.Person, Count = record.RecordCount },
                 cancellationToken);
         }
@@ -150,7 +150,7 @@ public class RealtimeService : IRealtimeService, IScopeDependency
             {
                 try
                 {
-                    await SendMsgToUserAsync(user.Id, RealtimeMethods.CircularRecord,
+                    await SendToUserAsync(user.Id, RealtimeMethods.CircularRecord,
                         new CircularRecoordDto()
                             { CircularType = Share.Enums.Article.ECircularType.Org, Count = record.RecordCount },
                         cancellationToken);
@@ -164,12 +164,10 @@ public class RealtimeService : IRealtimeService, IScopeDependency
 
     #endregion
 
-    #region 通用
+    #region 大屏.数据展示
 
-    //public int GetGroupMemberCount(string groupName)
-    //{
-    //    _hubContext.Clients.Group(groupName)
-    //}
+    public Task BsDataShowChangedAsync(object obj, CancellationToken cancellationToken) =>
+        SendToGroupAsync(RealtimeGroupNames.BigScreenDataShow, RealtimeMethods.BsDataShow, obj, cancellationToken);
 
     #endregion
 
@@ -195,14 +193,14 @@ public class RealtimeService : IRealtimeService, IScopeDependency
             throw UserFriendlyException.SameMessage($"该用户不属于分组:{groupName}");
     }
 
-    private async Task SendMsgToUserAsync(string userId, string msg, object? value, CancellationToken cancellationToken)
+    private async Task SendToUserAsync(string userId, string msg, object? value, CancellationToken cancellationToken)
     {
         var connection = await _realtimeCacheManager.GetConnectionAsync(userId, cancellationToken);
         await _hubContext.Clients.Client(connection.ConnectionId).SendAsync(msg, value, cancellationToken);
     }
 
-    private Task SendMsgToGroupAsync(string groupName, string msg, object? value, CancellationToken cancellationToken) => 
-        _hubContext.Clients.Group(groupName).SendAsync(msg, value, cancellationToken);
+    private Task SendToGroupAsync(string groupName, string method, object? value, CancellationToken cancellationToken) =>
+        _hubContext.Clients.Group(groupName).SendAsync(method, value, cancellationToken);
 
     #endregion
 }

+ 42 - 37
src/Hotline.Application/Bigscreen/BigscreenDataShowRefreshService.cs

@@ -1,42 +1,47 @@
-//using System;
-//using System.Collections.Generic;
-//using System.Linq;
-//using System.Text;
-//using System.Threading.Tasks;
-//using Hotline.Realtimes;
-//using Microsoft.Extensions.DependencyInjection;
-//using Microsoft.Extensions.Hosting;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Hotline.Realtimes;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
 
-//namespace Hotline.Application.Bigscreen
-//{
-//    public class BigscreenDataShowRefreshService : BackgroundService
-//    {
-//        private readonly IServiceScopeFactory _serviceScopeFactory;
+namespace Hotline.Application.Bigscreen
+{
+    public class BigscreenDataShowRefreshService : BackgroundService
+    {
+        private readonly IServiceScopeFactory _serviceScopeFactory;
 
-//        public BigscreenDataShowRefreshService(IServiceScopeFactory serviceScopeFactory)
-//        {
-//            _serviceScopeFactory = serviceScopeFactory;
-//        }
+        public BigscreenDataShowRefreshService(IServiceScopeFactory serviceScopeFactory)
+        {
+            _serviceScopeFactory = serviceScopeFactory;
+        }
 
-//        /// <summary>
-//        /// This method is called when the <see cref="T:Microsoft.Extensions.Hosting.IHostedService" /> starts. The implementation should return a task that represents
-//        /// the lifetime of the long running operation(s) being performed.
-//        /// </summary>
-//        /// <param name="stoppingToken">Triggered when <see cref="M:Microsoft.Extensions.Hosting.IHostedService.StopAsync(System.Threading.CancellationToken)" /> is called.</param>
-//        /// <returns>A <see cref="T:System.Threading.Tasks.Task" /> that represents the long running operations.</returns>
-//        /// <remarks>See <see href="https://docs.microsoft.com/dotnet/core/extensions/workers">Worker Services in .NET</see> for implementation guidelines.</remarks>
-//        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
-//        {
-//            using var scope = _serviceScopeFactory.CreateScope();
-//            var realtimeService = scope.ServiceProvider.GetService<IRealtimeService>();
+        /// <summary>
+        /// This method is called when the <see cref="T:Microsoft.Extensions.Hosting.IHostedService" /> starts. The implementation should return a task that represents
+        /// the lifetime of the long running operation(s) being performed.
+        /// </summary>
+        /// <param name="stoppingToken">Triggered when <see cref="M:Microsoft.Extensions.Hosting.IHostedService.StopAsync(System.Threading.CancellationToken)" /> is called.</param>
+        /// <returns>A <see cref="T:System.Threading.Tasks.Task" /> that represents the long running operations.</returns>
+        /// <remarks>See <see href="https://docs.microsoft.com/dotnet/core/extensions/workers">Worker Services in .NET</see> for implementation guidelines.</remarks>
+        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
+        {
+            using var scope = _serviceScopeFactory.CreateScope();
+            var realtimeService = scope.ServiceProvider.GetRequiredService<IRealtimeService>();
 
-//            while (!stoppingToken.IsCancellationRequested)
-//            {
-//                //todo
-                
+            while (!stoppingToken.IsCancellationRequested)
+            {
+                //todo
+                var data = new {
+                    Name = "John",
+                    Age = 20
+                };
 
-//                await Task.Delay(30000, stoppingToken);
-//            }
-//        }
-//    }
-//}
+                await realtimeService.BsDataShowChangedAsync(data, stoppingToken);
+
+                await Task.Delay(30000, stoppingToken);
+            }
+        }
+    }
+}

+ 6 - 0
src/Hotline/Realtimes/IRealtimeService.cs

@@ -27,5 +27,11 @@ namespace Hotline.Realtimes
         Task CircularRecoordAsync(string id, CancellationToken cancellationToken);
 
         #endregion
+
+        #region 大屏.数据展示
+
+        Task BsDataShowChangedAsync(object obj, CancellationToken cancellationToken);
+
+        #endregion
     }
 }