Browse Source

修改bug

denny 2 years ago
parent
commit
1b88df5e44

+ 0 - 95
src/InteractionCenter/IVinnoServerManager.cs

@@ -1,95 +0,0 @@
-using System.Threading.Tasks;
-using System.Collections.Generic;
-using WingInterfaceLibrary.DTO.ServerInfo;
-using WingServerCommon.Interfaces.Cache;
-using System;
-using System.Linq;
-
-namespace WingCloudServer.InteractionCenter
-{
-    interface IVinnoServerManager : IBaseCacheManager<ServerInformation>
-    {
-        /// <summary>
-        /// Get All ServerInfos 
-        /// </summary>
-        /// <returns></returns>
-        IList<ServerInformation> GetAllServerInfos();   
-
-        /// <summary>
-        /// Get ServerInfos with specified client id
-        /// </summary>
-        /// <param name="clientId">User code, admin code or device code</param>
-        /// <returns></returns>
-        IList<ServerInformation> GetServerInfos(string code);       
-
-        // <summary>
-        /// Get tokens with specified client ids
-        /// </summary>
-        /// <param name="clientId">User code, admin code or device code</param>
-        /// <returns></returns>
-        IList<ServerInformation> GetServerInfosByCodes(List<string> codes);
-
-        /// <summary>
-        /// The ServerInfo info update event
-        /// </summary>
-        event EventHandler<IList<ServerInformation>> ServerInfoUpdate;
-    }
-    
-    /// <summary>
-    /// Internal Server token, just used in server session module
-    /// </summary>
-    internal class ServerInformation : ServerInfoDTO, ICacheObject
-    {
-        public ServerInformation()
-        {
-
-        }
-
-        //
-        // 摘要:
-        //     The token string value
-        public string Code { get; set; }
-    }
-
-    
-    internal class VinnoServerManager : CacheManager<ServerInformation>, IVinnoServerManager
-    {
-        private bool _isWatching = true;
-        public event EventHandler<IList<ServerInformation>> ServerInfoUpdate;
-
-        public VinnoServerManager(Func<string, ServerInformation> loadCacheFromDbWithId, Func<IList<string>, IList<ServerInformation>> loadCachesFromDbWithIds) : base(loadCacheFromDbWithId, loadCachesFromDbWithIds)
-        {
-
-        }
-
-        /// <summary>
-        /// Get tokens with specified client id
-        /// </summary>
-        /// <param name="clientId">User code, admin code or device code</param>
-        /// <returns></returns>
-        public IList<ServerInformation> GetServerInfos(string code)
-        {
-            return Where(x => x.Code == code)?.ToList() ?? new List<ServerInformation>();
-        }
-
-        /// <summary>
-        /// Get tokens with specified client ids
-        /// </summary>
-        /// <param name="clientId">User code, admin code or device code</param>
-        /// <returns></returns>
-        public IList<ServerInformation> GetServerInfosByCodes(List<string> codes)
-        {
-            return Where(x => codes.Contains(x.Code))?.ToList() ?? new List<ServerInformation>();
-        }
-
-        /// <summary>
-        /// Get tokens with specified client id
-        /// </summary>
-        /// <param name="clientId">User code, admin code or device code</param>
-        /// <returns></returns>
-        public IList<ServerInformation> GetAllServerInfos()
-        {
-            return Where(x => !string.IsNullOrEmpty(x.Name) && !string.IsNullOrEmpty(x.Host))?.ToList() ?? new List<ServerInformation>();
-        }
-    }
-}

+ 45 - 4
src/InteractionCenter/VinnoServerService.cs

@@ -1,5 +1,4 @@
 using WingServerCommon.Service;
-using WingInterfaceLibrary.OpLog;
 using System.Threading.Tasks;
 using System.Collections.Generic;
 using WingInterfaceLibrary.Interface;
@@ -135,8 +134,50 @@ namespace WingCloudServer.InteractionCenter
             _distributedServerInfoDBService = GetProxy<IDistributedServerInfoDBService>();       
             _authenticationService = GetProxy<IAuthenticationService>();  
             _tokenDBService = GetProxy<ITokenDBService>();  
-            //LoadDBServerInfo();   
-            InitFastestServerService(_fastServerHost);           
+            LoadDBServerInfo();   
+            InitVinnoServerService(_fastServerHost);           
+        }
+
+        /// <summary>
+        /// 加载ServerInfo到内存
+        /// </summary>
+        /// <returns></returns>
+        private void LoadDBServerInfo()
+        {
+            Task.Run(async () =>
+           {
+               try
+               {
+                    int tryCount = 1;
+                    IList<CacheDistributedServerInfosDTO> serverInformationList = null;
+                    while (true) 
+                    {
+                        try 
+                        {
+                            serverInformationList = await GetServerInformationList(null);
+                        }
+                        catch (Exception ex) 
+                        {
+                            Logger.WriteLineError($"ServerInfo Cache Init Error:{ex}");
+                        }
+                        if (serverInformationList != null) 
+                        {
+                            break;
+                        }
+                        tryCount++;
+                        if (tryCount > 10) 
+                        {
+                            break;
+                        }
+                        await Task.Delay(500);
+                    }
+                    CacheMaintenance.Instance.Get<IDistributedServerInfosManager>().LoadFromDbOject(serverInformationList);
+               }
+               catch (Exception ex)
+               {
+                   Logger.WriteLineWarn($"VinnoServerService LoadDBServerInfo err, {ex}");
+               }
+           });
         }
 
         #region 监听服务
@@ -144,7 +185,7 @@ namespace WingCloudServer.InteractionCenter
         /// <summary>
         /// 初始化监听
         /// </summary>
-        private void InitFastestServerService(string fastServerHost = "http://*:9304/")
+        private void InitVinnoServerService(string fastServerHost = "http://*:9304/")
         {   
             //添加已经挂在的静态服务的监听
             _listener.Prefixes.Add(fastServerHost);