Browse Source

调整回来

fly 2 years ago
parent
commit
68cdcbe515
1 changed files with 49 additions and 96 deletions
  1. 49 96
      src/WingServer.cs

+ 49 - 96
src/WingServer.cs

@@ -21,9 +21,8 @@ using WingInterfaceLibrary.Request.Authentication;
 using JsonRpcLite.Services;
 using WingInterfaceLibrary.Enum;
 using WingCloudServer.Plugin;
-using WingInterfaceLibrary.DTO.DistributedServerInfo;
-using CSScriptLib;
 using System.Reflection;
+using CSScriptLib;
 
 namespace WingCloudServer
 {
@@ -80,7 +79,9 @@ namespace WingCloudServer
         {
             var folder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory);
             //initiaize rpc client pool
+            var remoteRpcHttpServices = LoadRemoteServiceConfig(folder);//new RemoteServiceInfo[0]; 
             var rpcClientPool = new JsonRpcClientPool(_inProcessEngine);
+            rpcClientPool.Initialize(remoteRpcHttpServices.ToArray());
             var inProcessServicesString = ConfigurationManager.GetParammeter<StringParameter>("Services", "InProcess").Value;
             var inProcessServices = inProcessServicesString.Split(',');
             var rpcHttpServicesString = ConfigurationManager.GetParammeter<StringParameter>("Services", "JsonRpcHttp").Value;
@@ -114,8 +115,9 @@ namespace WingCloudServer
 
                 }
             }
-            var remoteRpcHttpServices = LoadRemoteServiceConfig(folder);//new RemoteServiceInfo[0]; 
-            rpcClientPool.Initialize(remoteRpcHttpServices.ToArray());
+
+            //TestCSScript(rpcClientPool);
+
             //Rpc http service load and register to rpc http server
             if (ConfigurationManager.IsDistributed)
             {
@@ -124,6 +126,7 @@ namespace WingCloudServer
                     var masterInteractionCenterService = new MasterInteractionCenterService();
                     _rpcHttpServer.RegisterService(typeof(IMasterInteractionCenterService), masterInteractionCenterService);
                     masterInteractionCenterService.Load(rpcClientPool);
+
                 }
                 else
                 {
@@ -160,6 +163,13 @@ namespace WingCloudServer
                 }
             }
 
+            //load services
+            foreach (var service in _rpcServices)
+            {
+                var method = service.Key.GetMethod("Load");
+                method.Invoke(service.Value, new object[] { rpcClientPool });
+            }
+
             //load service if distrubuted system
             if (ConfigurationManager.IsDistributed)
             {
@@ -169,18 +179,9 @@ namespace WingCloudServer
                 }
                 else
                 {
-                    //动态注册副服务器实时同步服务
-                    RegisterDynamicSlaveInteractionCenterService(rpcClientPool);
+                    //TODO
                 }
             }
-
-            //load services
-            foreach (var service in _rpcServices)
-            {
-                var method = service.Key.GetMethod("Load");
-                method.Invoke(service.Value, new object[] { rpcClientPool });
-            }
-
             //最快服务器
             var vinnoServerService = new VinnoServerService();
             _rpcHttpServer.RegisterService(typeof(WingInterfaceLibrary.Interface.IVinnoServerService), vinnoServerService);
@@ -198,54 +199,65 @@ namespace WingCloudServer
             _serverListPlugin.Load(rpcClientPool);
 
         }
-        //todo 待验证是否可以调用本地的service
-        public void RegisterDynamicSlaveInteractionCenterService(JsonRpcClientPool rpcClientPool)
+
+        public void TestCSScript(JsonRpcClientPool rpcClientPool)
         {
-            var eval = CSScript.Evaluator.ReferenceDomainAssemblies(DomainAssemblies.AllStaticNonGAC);
-            var host = ConfigurationManager.Host.Replace("http:", "").Replace(".", "").Replace("/", "");
-            var str = @"
+            //接口
+                    var eval = CSScript.Evaluator.ReferenceDomainAssemblies(DomainAssemblies.AllStaticNonGAC);
+                    var host = ConfigurationManager.Host.Replace("http:", "").Replace(".", "").Replace("/", "");
+                    var str = @"
                     using System;
                     using System.Threading.Tasks;
+                    using System;
                     using WingServerCommon.Service;
                     using WingInterfaceLibrary.OpLog;
+                    using System.Threading.Tasks;
                     using System.Collections.Generic;
                     using JsonRpcLite.Rpc;
                     using WingInterfaceLibrary.Interface.DBInterface;
                     using WingInterfaceLibrary.DB.Request;
                                      
-                    public interface IDynamicSlaveService" + host + @"
+                    public interface ICSScriptTest"+host+@"
                     {
-                        Task<bool> DynamicSlaveAsync(SyncReceiveServiceDataRequest request);
+                        Task<bool> CSScriptTestAsync();
                     }
-                    public class DynamicSlaveService : JsonRpcService,IDynamicSlaveService" + host + @"
+                    public class CSScriptTestService : JsonRpcService,ICSScriptTest"+host+@"
                     {
-                        protected ISlaveInteractionCenterService _slaveInteractionCenterService;
+                        protected IOpLogDBService OpLogDBService;
+                        protected IDeviceInfoDBService deviceInfoDBService;
                         public override void Load(JsonRpcClientPool jsonRpcClientPool)
                         {
                             base.Load(jsonRpcClientPool);
-                            _slaveInteractionCenterService = GetProxy<ISlaveInteractionCenterService>();
+                            OpLogDBService = GetProxy<IOpLogDBService>();
+                            deviceInfoDBService = GetProxy<IDeviceInfoDBService>();
                         }
-                        public async Task<bool> DynamicSlaveAsync(SyncReceiveServiceDataRequest request)
+                            public async Task<bool> CSScriptTestAsync()
                         {
-                            await _slaveInteractionCenterService.SyncReceiveMasterServiceDataAsync(request);
+                            var res = deviceInfoDBService.FindDictionaryItemsAsync(new FindDictionaryItemsDBRequest()).Result;
+                            Console.WriteLine(""flytest""+res.Count);
                             return true;
                         }
                     }
-                    public class DynamicMethodClass
+                    public class Test
                     {
-                        public void DynamicMethod(JsonRpcClientPool rpcClientPool,JsonRpcServer _rpcHttpServer){
-                            var DynamicSlaveService = new DynamicSlaveService();
-                            _rpcHttpServer.RegisterService(typeof(IDynamicSlaveService" + host + @"), DynamicSlaveService);
-                            DynamicSlaveService.Load(rpcClientPool);
+                        public void Test1(JsonRpcClientPool rpcClientPool,JsonRpcServer _rpcHttpServer){
+                            var csScriptTestService = new CSScriptTestService();
+                            _rpcHttpServer.RegisterService(typeof(ICSScriptTest"+host+@"), csScriptTestService);
+                            csScriptTestService.Load(rpcClientPool);
                         }
                     }
                     ";
-            Assembly compilecode = eval.CompileCode(str);
-            var ps = compilecode.GetType("css_root+DynamicMethodClass");
-            var obj = compilecode.CreateInstance("css_root+DynamicMethodClass");
-            var mes = ps.GetMethod("DynamicMethod");
-            mes.Invoke(obj, new object[] { rpcClientPool, _rpcHttpServer });
+
+                    Assembly compilecode = eval.CompileCode(str);
+
+
+
+                    var ps = compilecode.GetType("css_root+Test");
+                    var obj = compilecode.CreateInstance("css_root+Test");
+                    var mes = ps.GetMethod("Test1");
+                    mes.Invoke(obj, new object[] { rpcClientPool, _rpcHttpServer });
         }
+
         void LoadDataAfterRegister()
         {
             foreach (var service in _rpcServices)
@@ -285,7 +297,7 @@ namespace WingCloudServer
             {
                 if (ConfigurationManager.IsMaster)
                 {
-                    DynamicRemoteSlaveService(resList);
+                    //TODO determin if we need to assess slave server on master server
                 }
                 else
                 {
@@ -330,65 +342,6 @@ namespace WingCloudServer
             return resList;
         }
 
-        public void DynamicRemoteSlaveService(List<RemoteServiceInfo> resList)
-        {
-            var slaveList = new List<DistributedServerInfoDTO>();
-            var host = ConfigurationManager.Host;
-            var eval = CSScript.Evaluator.ReferenceDomainAssemblies(DomainAssemblies.AllStaticNonGAC);
-            var str = @"
-            using System;
-            using System.Threading.Tasks;
-            using WingServerCommon.Service;
-            using WingInterfaceLibrary.OpLog;
-            using System.Collections.Generic;
-            using JsonRpcLite.Rpc;
-            using WingInterfaceLibrary.Interface.DBInterface;
-            using WingInterfaceLibrary.DB.Request;
-            using WingInterfaceLibrary.DTO.DistributedServerInfo;
-            using WingInterfaceLibrary.Request.DBRequest;
-            using System.Linq;
-
-            public class GetUrlListService : JsonRpcService
-            {
-                protected IDistributedServerInfoDBService _distributedServerInfoDBService;
-                public override void Load(JsonRpcClientPool jsonRpcClientPool)
-                {
-                    base.Load(jsonRpcClientPool);
-                    _distributedServerInfoDBService = GetProxy<IDistributedServerInfoDBService>();
-                }
-
-                public List<DistributedServerInfoDTO> GetSlaveList(string host,List<DistributedServerInfoDTO> slaveList)
-                {
-                    var distributedServerInfoDBPagesRequest = new GetDistributedServerInfoDBPagesRequest();
-                    distributedServerInfoDBPagesRequest.CurrentPage = 1;
-                    distributedServerInfoDBPagesRequest.PageSize = 9999;
-                    var result = _distributedServerInfoDBService.GetDistributedServerInfoPagesAsync(distributedServerInfoDBPagesRequest).Result;
-                    if (result != null && result.TotalCount > 0)
-                    {
-                        slaveList = result.PageData;
-                        slaveList = slaveList.Where(x => x.ServerUrl != host).ToList();
-                    }
-                    return slaveList;
-                }
-            }
-            ";
-            Assembly compilecode = eval.CompileCode(str);
-            var ps = compilecode.GetType("css_root+GetUrlListService");
-            var obj = compilecode.CreateInstance("css_root+GetUrlListService");
-            var mes = ps.GetMethod("GetSlaveList");
-            mes.Invoke(obj, new object[] { slaveList });
-            //动态注册副服务器服务
-            foreach (var item in slaveList)
-            {
-                var serviceInfo = new RemoteServiceInfo()
-                {
-                    ServiceName = "IDynamicSlaveService" + item.ServerUrl.Replace("http:", "").Replace(".", "").Replace("/", ""),
-                    Url = ConfigurationManager.MasterUrl
-                };
-                resList.Add(serviceInfo);
-            }
-        }
-
         /// <summary>
         /// 初始化AIDiagnosis
         /// </summary>