|
@@ -33,6 +33,9 @@ namespace WingCloudServer
|
|
|
private JsonRpcInProcessEngine _inProcessEngine;
|
|
|
private JsonRpcHttpServerEngine _jsonRpcHttpServerEngine;
|
|
|
private Dictionary<Type, object> _rpcServices;
|
|
|
+ private static JsonRpcClientPool _rpcClientPool;
|
|
|
+ private static Dictionary<string, object> _remoteServices;
|
|
|
+
|
|
|
|
|
|
public WingServer(string host)
|
|
|
{
|
|
@@ -75,13 +78,56 @@ namespace WingCloudServer
|
|
|
_rpcInProcessServer.Stop();
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 动态添加远程服务
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="serviceName"></param>
|
|
|
+ /// <param name="url"></param>
|
|
|
+ internal static void AddRemoteService<T>(string serviceName, string url)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (_remoteServices.Any(x => x.Key == serviceName))
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var serviceInfo = new RemoteServiceInfo()
|
|
|
+ {
|
|
|
+ ServiceName = serviceName,
|
|
|
+ Url = url
|
|
|
+ };
|
|
|
+ _rpcClientPool.Add(serviceInfo);
|
|
|
+
|
|
|
+ var service = _rpcClientPool.GetJsonRpcClient<T>().CreateProxy<T>();
|
|
|
+ _remoteServices.TryAdd(serviceName, service);
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Logger.WriteLineWarn("AddService err" + ex);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ internal static object WingServerGetProxy(string serviceName)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var service = _remoteServices.FirstOrDefault(x => x.Key == serviceName);
|
|
|
+ return service.Value;
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Logger.WriteLineWarn("WingServerGetProxy err" + ex);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
void InitializeServices()
|
|
|
{
|
|
|
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());
|
|
|
+ _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;
|
|
@@ -116,8 +162,6 @@ namespace WingCloudServer
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //TestCSScript(rpcClientPool);
|
|
|
-
|
|
|
//Rpc http service load and register to rpc http server
|
|
|
if (ConfigurationManager.IsDistributed)
|
|
|
{
|
|
@@ -125,12 +169,12 @@ namespace WingCloudServer
|
|
|
{
|
|
|
var masterInteractionCenterService = new MasterInteractionCenterService();
|
|
|
_rpcHttpServer.RegisterService(typeof(IMasterInteractionCenterService), masterInteractionCenterService);
|
|
|
- masterInteractionCenterService.Load(rpcClientPool);
|
|
|
-
|
|
|
+ masterInteractionCenterService.Load(_rpcClientPool);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//TODO determin if we need to assess slave server on master server
|
|
|
+ RegisterDynamicSlaveInteractionCenterService(_rpcClientPool);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -167,95 +211,82 @@ namespace WingCloudServer
|
|
|
foreach (var service in _rpcServices)
|
|
|
{
|
|
|
var method = service.Key.GetMethod("Load");
|
|
|
- method.Invoke(service.Value, new object[] { rpcClientPool });
|
|
|
+ method.Invoke(service.Value, new object[] { _rpcClientPool });
|
|
|
}
|
|
|
|
|
|
- //load service if distrubuted system
|
|
|
- if (ConfigurationManager.IsDistributed)
|
|
|
- {
|
|
|
- if (ConfigurationManager.IsMaster)
|
|
|
- {
|
|
|
- //_rpcHttpServer.RegisterService(IMaster); TODO
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- //TODO
|
|
|
- }
|
|
|
- }
|
|
|
//最快服务器
|
|
|
var vinnoServerService = new VinnoServerService();
|
|
|
_rpcHttpServer.RegisterService(typeof(WingInterfaceLibrary.Interface.IVinnoServerService), vinnoServerService);
|
|
|
- vinnoServerService.Load(rpcClientPool);
|
|
|
+ vinnoServerService.Load(_rpcClientPool);
|
|
|
|
|
|
//plugin
|
|
|
_tokenVerifyPlugin = new TokenVerifyPlugin();
|
|
|
_rpcHttpServer.RegisterService(typeof(ITokenVerifyPlugin), _tokenVerifyPlugin);
|
|
|
- _tokenVerifyPlugin.Load(rpcClientPool);
|
|
|
+ _tokenVerifyPlugin.Load(_rpcClientPool);
|
|
|
_ipAddressPlugin = new IPAddressPlugin();
|
|
|
_rpcHttpServer.RegisterService(typeof(IIPAddressPlugin), _ipAddressPlugin);
|
|
|
- _ipAddressPlugin.Load(rpcClientPool);
|
|
|
+ _ipAddressPlugin.Load(_rpcClientPool);
|
|
|
_serverListPlugin = new ServerListPlugin();
|
|
|
_rpcHttpServer.RegisterService(typeof(IServerListPlugin), _serverListPlugin);
|
|
|
- _serverListPlugin.Load(rpcClientPool);
|
|
|
+ _serverListPlugin.Load(_rpcClientPool);
|
|
|
|
|
|
}
|
|
|
|
|
|
- public void TestCSScript(JsonRpcClientPool rpcClientPool)
|
|
|
+ /// <summary>
|
|
|
+ /// 副服务器动态服务
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="rpcClientPool"></param>
|
|
|
+ public void RegisterDynamicSlaveInteractionCenterService(JsonRpcClientPool rpcClientPool)
|
|
|
{
|
|
|
- //接口
|
|
|
- var eval = CSScript.Evaluator.ReferenceDomainAssemblies(DomainAssemblies.AllStaticNonGAC);
|
|
|
- var host = ConfigurationManager.Host.Replace("http:", "").Replace(".", "").Replace("/", "");
|
|
|
- var str = @"
|
|
|
+ var serverID = ConfigurationManager.GetParammeter<StringParameter>("General", "ServerID").Value;
|
|
|
+ //先注册 下面要调用
|
|
|
+ var slaveInteractionCenterService = new SlaveInteractionCenterService();
|
|
|
+ _rpcHttpServer.RegisterService(typeof(ISlaveInteractionCenterService), slaveInteractionCenterService);
|
|
|
+ slaveInteractionCenterService.Load(rpcClientPool);
|
|
|
+
|
|
|
+ var eval = CSScript.Evaluator.ReferenceDomainAssemblies(DomainAssemblies.AllStaticNonGAC);
|
|
|
+ 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 ICSScriptTest"+host+@"
|
|
|
+ public interface IDynamicSlaveService" + serverID + @"
|
|
|
{
|
|
|
- Task<bool> CSScriptTestAsync();
|
|
|
+ Task<bool> DynamicSlaveAsync(SyncReceiveServiceDataRequest request);
|
|
|
}
|
|
|
- public class CSScriptTestService : JsonRpcService,ICSScriptTest"+host+@"
|
|
|
+ public class DynamicSlaveService : JsonRpcService,IDynamicSlaveService" + serverID + @"
|
|
|
{
|
|
|
- protected IOpLogDBService OpLogDBService;
|
|
|
- protected IDeviceInfoDBService deviceInfoDBService;
|
|
|
+ protected ISlaveInteractionCenterService _slaveInteractionCenterService;
|
|
|
public override void Load(JsonRpcClientPool jsonRpcClientPool)
|
|
|
{
|
|
|
base.Load(jsonRpcClientPool);
|
|
|
- OpLogDBService = GetProxy<IOpLogDBService>();
|
|
|
- deviceInfoDBService = GetProxy<IDeviceInfoDBService>();
|
|
|
+ _slaveInteractionCenterService = GetProxy<ISlaveInteractionCenterService>();
|
|
|
}
|
|
|
- public async Task<bool> CSScriptTestAsync()
|
|
|
+ public async Task<bool> DynamicSlaveAsync(SyncReceiveServiceDataRequest request)
|
|
|
{
|
|
|
- var res = deviceInfoDBService.FindDictionaryItemsAsync(new FindDictionaryItemsDBRequest()).Result;
|
|
|
- Console.WriteLine(""flytest""+res.Count);
|
|
|
+ await _slaveInteractionCenterService.SyncReceiveMasterServiceDataAsync(request);
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
- public class Test
|
|
|
+ public class DynamicMethodClass
|
|
|
{
|
|
|
- public void Test1(JsonRpcClientPool rpcClientPool,JsonRpcServer _rpcHttpServer){
|
|
|
- var csScriptTestService = new CSScriptTestService();
|
|
|
- _rpcHttpServer.RegisterService(typeof(ICSScriptTest"+host+@"), csScriptTestService);
|
|
|
- csScriptTestService.Load(rpcClientPool);
|
|
|
+ public void DynamicMethod(JsonRpcClientPool rpcClientPool,JsonRpcServer _rpcHttpServer){
|
|
|
+ var DynamicSlaveService = new DynamicSlaveService();
|
|
|
+ _rpcHttpServer.RegisterService(typeof(IDynamicSlaveService" + serverID + @"), DynamicSlaveService);
|
|
|
+ DynamicSlaveService.Load(rpcClientPool);
|
|
|
}
|
|
|
}
|
|
|
";
|
|
|
-
|
|
|
- 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 });
|
|
|
+ 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 });
|
|
|
}
|
|
|
|
|
|
void LoadDataAfterRegister()
|