fly 2 years ago
parent
commit
40ac44ff80

+ 12 - 13
src/InteractionCenter/MasterInteractionCenterService.cs

@@ -58,8 +58,8 @@ namespace WingCloudServer.InteractionCenter
             {
                 if (!_serverUrlMap.Any(x => x.Key == request.SourceUrl))
                 {
-                    _serverUrlMap.TryAdd(request.SourceUrl, request.ServerID);
                     DynamicAddRemoteService(request.ServerID, request.SourceUrl);
+                    _serverUrlMap.TryAdd(request.SourceUrl, request.ServerID);
                 }
             }
             catch (Exception ex)
@@ -71,8 +71,9 @@ namespace WingCloudServer.InteractionCenter
 
         public void DynamicAddRemoteService(string serverID, string sourceUrl)
         {
+            
             var eval = CSScript.Evaluator.ReferenceDomainAssemblies(DomainAssemblies.AllStaticNonGAC);
-            var str = @"using System;
+            var str = @$"using System;
                         using System.Threading.Tasks;
                         using WingServerCommon.Service;
                         using WingInterfaceLibrary.OpLog;
@@ -81,18 +82,18 @@ namespace WingCloudServer.InteractionCenter
                         using WingInterfaceLibrary.Interface.DBInterface;
                         using WingCloudServer;
 
-                        public interface IDynamicSlaveService" + serverID + @"
-                        {
+                        public interface IDynamicSlaveService{serverID}
+                        {{
                             Task<bool> DynamicSlaveAsync(SyncReceiveServiceDataRequest request);
-                        }
+                        }}
 
                         public class DynamicAddRemoteServiceClass
-                        {
-                            public void DynamicAddRemoteMethod(SyncReceiveServiceDataRequest request)
-                            {
-                               WingServer.AddRemoteService<IDynamicSlaveService" + serverID + @">(IDynamicSlaveService" + serverID + @"," + sourceUrl + @");
-                            }
-                        }";
+                        {{
+                            public void DynamicAddRemoteMethod()
+                            {{
+                               WingServer.AddRemoteService<IDynamicSlaveService{serverID}>(""IDynamicSlaveService{serverID}"",""{sourceUrl}"");
+                            }}
+                        }}";
             Assembly compilecode = eval.CompileCode(str);
             var ps = compilecode.GetType("css_root+DynamicAddRemoteServiceClass");
             var obj = compilecode.CreateInstance("css_root+DynamicAddRemoteServiceClass");
@@ -101,8 +102,6 @@ namespace WingCloudServer.InteractionCenter
         }
     }
 
-
-
     public class SlaveInteractionCenterService : InteractionCenterService, ISlaveInteractionCenterService
     {
 

+ 10 - 10
src/InteractionCenter/MasterInteractionSyncService.cs

@@ -79,7 +79,7 @@ namespace WingCloudServer.InteractionCenter
         public void DynamicSlaveService(SyncReceiveServiceDataRequest request, string serverID)
         {
             var eval = CSScript.Evaluator.ReferenceDomainAssemblies(DomainAssemblies.AllStaticNonGAC);
-            var str = @"using System;
+            var str = @$"using System;
                         using System.Threading.Tasks;
                         using WingServerCommon.Service;
                         using WingInterfaceLibrary.OpLog;
@@ -88,20 +88,20 @@ namespace WingCloudServer.InteractionCenter
                         using WingInterfaceLibrary.Interface.DBInterface;
                         using WingCloudServer;
 
-                        public interface IDynamicSlaveService" + serverID + @"
-                        {
+                        public interface IDynamicSlaveService{serverID}
+                        {{
                             Task<bool> DynamicSlaveAsync(SyncReceiveServiceDataRequest request);
-                        }
+                        }}
 
                         public class DynamicSlaveServiceClass
-                        {
+                        {{
                             public void DynamicSlaveMethod(SyncReceiveServiceDataRequest request)
-                            {
-                                var _dynamicService = WingServer.WingServerGetProxy(IDynamicSlaveService" + serverID + @");
+                             {{
+                                var _dynamicService = WingServer.WingServerGetProxy(""IDynamicSlaveService{serverID}"");
 
-                                (_dynamicService as IDynamicSlaveService" + serverID + @").DynamicSlaveAsync(request);
-                            }
-                        }";
+                                (_dynamicService as IDynamicSlaveService{serverID}).DynamicSlaveAsync(request);
+                           }}
+                        }}";
             Assembly compilecode = eval.CompileCode(str);
             var ps = compilecode.GetType("css_root+DynamicSlaveServiceClass");
             var obj = compilecode.CreateInstance("css_root+DynamicSlaveServiceClass");

+ 20 - 20
src/WingServer.cs

@@ -26,7 +26,7 @@ using CSScriptLib;
 
 namespace WingCloudServer
 {
-    internal class WingServer
+    public class WingServer
     {
         private JsonRpcServer _rpcHttpServer;
         private JsonRpcServer _rpcInProcessServer;
@@ -34,7 +34,7 @@ namespace WingCloudServer
         private JsonRpcHttpServerEngine _jsonRpcHttpServerEngine;
         private Dictionary<Type, object> _rpcServices;
         private static JsonRpcClientPool _rpcClientPool;
-        private static Dictionary<string, object> _remoteServices;
+        private static Dictionary<string, object> _remoteServices = new Dictionary<string, object>();
 
 
         public WingServer(string host)
@@ -83,7 +83,7 @@ namespace WingCloudServer
         /// </summary>
         /// <param name="serviceName"></param>
         /// <param name="url"></param>
-        internal static void AddRemoteService<T>(string serviceName, string url)
+        public static void AddRemoteService<T>(string serviceName, string url)
         {
             try
             {
@@ -107,7 +107,7 @@ namespace WingCloudServer
             }
         }
 
-        internal static object WingServerGetProxy(string serviceName)
+        public static object WingServerGetProxy(string serviceName)
         {
             try
             {
@@ -245,7 +245,7 @@ namespace WingCloudServer
             slaveInteractionCenterService.Load(rpcClientPool);
 
             var eval = CSScript.Evaluator.ReferenceDomainAssemblies(DomainAssemblies.AllStaticNonGAC);
-            var str = @"
+            var str = @$"
                     using System;
                     using System.Threading.Tasks;
                     using WingServerCommon.Service;
@@ -255,32 +255,32 @@ namespace WingCloudServer
                     using WingInterfaceLibrary.Interface.DBInterface;
                     using WingInterfaceLibrary.DB.Request;
                                      
-                    public interface IDynamicSlaveService" + serverID + @"
-                    {
+                    public interface IDynamicSlaveService{serverID}
+                    {{
                         Task<bool> DynamicSlaveAsync(SyncReceiveServiceDataRequest request);
-                    }
-                    public class DynamicSlaveService : JsonRpcService,IDynamicSlaveService" + serverID + @"
-                    {
+                    }}
+                    public class DynamicSlaveService : JsonRpcService,IDynamicSlaveService{serverID}
+                    {{
                         protected ISlaveInteractionCenterService _slaveInteractionCenterService;
                         public override void Load(JsonRpcClientPool jsonRpcClientPool)
-                        {
+                        {{
                             base.Load(jsonRpcClientPool);
                             _slaveInteractionCenterService = GetProxy<ISlaveInteractionCenterService>();
-                        }
+                        }}
                         public async Task<bool> DynamicSlaveAsync(SyncReceiveServiceDataRequest request)
-                        {
+                        {{
                             await _slaveInteractionCenterService.SyncReceiveMasterServiceDataAsync(request);
                             return true;
-                        }
-                    }
+                        }}
+                    }}
                     public class DynamicMethodClass
-                    {
-                        public void DynamicMethod(JsonRpcClientPool rpcClientPool,JsonRpcServer _rpcHttpServer){
+                     {{
+                        public void DynamicMethod(JsonRpcClientPool rpcClientPool,JsonRpcServer _rpcHttpServer) {{
                             var DynamicSlaveService = new DynamicSlaveService();
-                            _rpcHttpServer.RegisterService(typeof(IDynamicSlaveService" + serverID + @"), DynamicSlaveService);
+                            _rpcHttpServer.RegisterService(typeof(IDynamicSlaveService{serverID}), DynamicSlaveService);
                             DynamicSlaveService.Load(rpcClientPool);
-                        }
-                    }
+                        }}
+                    }}
                     ";
             Assembly compilecode = eval.CompileCode(str);
             var ps = compilecode.GetType("css_root+DynamicMethodClass");