|
@@ -14,18 +14,18 @@ namespace WingCloudServer
|
|
|
{
|
|
|
internal class WingServer
|
|
|
{
|
|
|
- private JsonRpcServer _rpcHttpServer;
|
|
|
+ private JsonRpcServer _rpcHttpServer;
|
|
|
private JsonRpcServer _rpcInProcessServer;
|
|
|
private JsonRpcInProcessEngine _inProcessEngine;
|
|
|
public WingServer(int port)
|
|
|
{
|
|
|
JsonRpcLite.Log.Logger.DebugMode = Logger.Debug;
|
|
|
JsonRpcLite.Log.Logger.Writer = new JsonRpcLiteLogWrite();
|
|
|
-
|
|
|
+
|
|
|
_rpcInProcessServer = new JsonRpcServer();
|
|
|
_inProcessEngine = new JsonRpcInProcessEngine();
|
|
|
_rpcInProcessServer.UseEngine(_inProcessEngine);
|
|
|
-
|
|
|
+
|
|
|
_rpcHttpServer = new JsonRpcServer();
|
|
|
var jsonRpcHttpServerEngine = new JsonRpcHttpServerEngine($"http://*:{port}/");
|
|
|
_rpcHttpServer.UseEngine(jsonRpcHttpServerEngine);
|
|
@@ -34,13 +34,14 @@ namespace WingCloudServer
|
|
|
/// <summary>
|
|
|
/// Start server to load all service
|
|
|
/// </summary>
|
|
|
- internal void Start(){
|
|
|
-
|
|
|
+ internal void Start()
|
|
|
+ {
|
|
|
+
|
|
|
InitializeServices();
|
|
|
_rpcInProcessServer.Start();
|
|
|
_rpcHttpServer.Start();
|
|
|
- }
|
|
|
-
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// Stop server
|
|
|
/// </summary>
|
|
@@ -48,48 +49,48 @@ namespace WingCloudServer
|
|
|
{
|
|
|
//TODO dispose service
|
|
|
_rpcHttpServer.Stop();
|
|
|
- _rpcInProcessServer.Stop();
|
|
|
+ _rpcInProcessServer.Stop();
|
|
|
}
|
|
|
|
|
|
void InitializeServices()
|
|
|
- {
|
|
|
+ {
|
|
|
//initiaize rpc client pool
|
|
|
var remoteRpcHttpServices = LoadRemoteServiceConfig();//new RemoteServiceInfo[0]; //TODO from settings
|
|
|
var rpcClientPool = new JsonRpcClientPool(_inProcessEngine);
|
|
|
- rpcClientPool.Initialize(remoteRpcHttpServices.ToArray());
|
|
|
+ rpcClientPool.Initialize(remoteRpcHttpServices.ToArray());
|
|
|
|
|
|
- var folder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Services");
|
|
|
- var inProcessServicesString = ConfigurationManager.GetParammeter<StringParameter>("Services","InProcess").Value;
|
|
|
- var inProcessServices = inProcessServicesString.Split(',');
|
|
|
- var rpcHttpServicesString = ConfigurationManager.GetParammeter<StringParameter>("Services","JsonRpcHttp").Value;
|
|
|
- var rpcHttpServices = rpcHttpServicesString.Split(',');
|
|
|
+ var folder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Services");
|
|
|
+ var inProcessServicesString = ConfigurationManager.GetParammeter<StringParameter>("Services", "InProcess").Value;
|
|
|
+ var inProcessServices = inProcessServicesString.Split(',');
|
|
|
+ var rpcHttpServicesString = ConfigurationManager.GetParammeter<StringParameter>("Services", "JsonRpcHttp").Value;
|
|
|
+ var rpcHttpServices = rpcHttpServicesString.Split(',');
|
|
|
if (!Directory.Exists(folder))
|
|
|
{
|
|
|
throw new NotSupportedException($"Folder {folder} not exist");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
//InProcess service load and register to InPrcess rpc server
|
|
|
- var rpcServices = new Dictionary<Type, object>();
|
|
|
+ var rpcServices = new Dictionary<Type, object>();
|
|
|
foreach (var service in inProcessServices)
|
|
|
- {
|
|
|
+ {
|
|
|
var wingServiceType = LoadService(folder, service);
|
|
|
var instance = Activator.CreateInstance(wingServiceType);
|
|
|
- rpcServices.Add(wingServiceType, instance);
|
|
|
+ rpcServices.Add(wingServiceType, instance);
|
|
|
var interfaces = wingServiceType.GetInterfaces();
|
|
|
- foreach(var serviceInterface in interfaces)
|
|
|
- {
|
|
|
- if (serviceInterface == typeof(IDisposable))
|
|
|
+ foreach (var serviceInterface in interfaces)
|
|
|
+ {
|
|
|
+ if (serviceInterface == typeof(IDisposable))
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
- if (serviceInterface == typeof(IJsonRpcService))
|
|
|
- {
|
|
|
- continue;
|
|
|
+ if (serviceInterface == typeof(IJsonRpcService))
|
|
|
+ {
|
|
|
+ continue;
|
|
|
}
|
|
|
- Logger.WriteLineInfo($"Registering type-{wingServiceType.Name}, interface-{serviceInterface.Name} to Rpc InProcess Server");
|
|
|
- _rpcInProcessServer.RegisterService(serviceInterface, instance);
|
|
|
-
|
|
|
- }
|
|
|
+ Logger.WriteLineInfo($"Registering type-{wingServiceType.Name}, interface-{serviceInterface.Name} to Rpc InProcess Server");
|
|
|
+ _rpcInProcessServer.RegisterService(serviceInterface, instance);
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//Rpc http service load and register to rpc http server
|
|
@@ -97,32 +98,35 @@ namespace WingCloudServer
|
|
|
{
|
|
|
var wingServiceType = LoadService(folder, service);
|
|
|
var instance = Activator.CreateInstance(wingServiceType);
|
|
|
- rpcServices.Add(wingServiceType, instance);
|
|
|
+ rpcServices.Add(wingServiceType, instance);
|
|
|
var interfaces = wingServiceType.GetInterfaces();
|
|
|
- foreach(var serviceInterface in interfaces)
|
|
|
- {
|
|
|
- if (serviceInterface == typeof(IDisposable))
|
|
|
+ foreach (var serviceInterface in interfaces)
|
|
|
+ {
|
|
|
+ if (serviceInterface == typeof(IDisposable))
|
|
|
{
|
|
|
continue;
|
|
|
- }
|
|
|
- if (serviceInterface == typeof(IJsonRpcService))
|
|
|
- {
|
|
|
- continue;
|
|
|
}
|
|
|
- Logger.WriteLineInfo($"Registering type-{wingServiceType.Name}, interface-{serviceInterface.Name} to Rpc Http Server");
|
|
|
- _rpcHttpServer.RegisterService(serviceInterface, instance);
|
|
|
-
|
|
|
- }
|
|
|
+ if (serviceInterface == typeof(IJsonRpcService))
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Logger.WriteLineInfo($"Registering type-{wingServiceType.Name}, interface-{serviceInterface.Name} to Rpc Http Server");
|
|
|
+ _rpcHttpServer.RegisterService(serviceInterface, instance);
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//load services
|
|
|
- foreach(var service in rpcServices)
|
|
|
+ foreach (var service in rpcServices)
|
|
|
{
|
|
|
- var method = service.Key.GetMethod("Load");
|
|
|
- method.Invoke(service.Value, new object[] { rpcClientPool});
|
|
|
+ var method = service.Key.GetMethod("Load");
|
|
|
+ method.Invoke(service.Value, new object[] { rpcClientPool });
|
|
|
}
|
|
|
+
|
|
|
+ //load extdll
|
|
|
+ InitSkiaSharp();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
private Type LoadService(string folder, object serviceName)
|
|
|
{
|
|
|
var file = Path.Combine(folder, $"{serviceName}.dll");
|
|
@@ -130,10 +134,10 @@ namespace WingCloudServer
|
|
|
{
|
|
|
throw new NotSupportedException($"File {file} not exist");
|
|
|
}
|
|
|
- var assemblyLoader = new AssemblyLoader();
|
|
|
+ var assemblyLoader = new AssemblyLoader();
|
|
|
var assembly = assemblyLoader.LoadAssemblyDependencies(file);
|
|
|
- var types = assembly.GetTypes();
|
|
|
- var wingServiceType = types.FirstOrDefault(x=>typeof(JsonRpcService).IsAssignableFrom(x) && x.IsClass && !x.IsAbstract);
|
|
|
+ var types = assembly.GetTypes();
|
|
|
+ var wingServiceType = types.FirstOrDefault(x => typeof(JsonRpcService).IsAssignableFrom(x) && x.IsClass && !x.IsAbstract);
|
|
|
if (wingServiceType == null)
|
|
|
{
|
|
|
throw new NotImplementedException($"WingService not find in {file}");
|
|
@@ -149,7 +153,7 @@ namespace WingCloudServer
|
|
|
private Dictionary<string, List<string>> GetServiceByModuleName(string defaultInterfaceName = "WingInterfaceLibrary", string defaultInterfaceFolder = "Interface")
|
|
|
{
|
|
|
var dic = new Dictionary<string, List<string>>();
|
|
|
- var folder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Dependencies");
|
|
|
+ var folder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Dependencies");
|
|
|
if (!Directory.Exists(folder))
|
|
|
{
|
|
|
throw new NotSupportedException($"Folder {folder} not exist");
|
|
@@ -161,7 +165,7 @@ namespace WingCloudServer
|
|
|
}
|
|
|
var assemblyLoader = new AssemblyLoader();
|
|
|
var assembly = assemblyLoader.LoadAssemblyDependencies(file);
|
|
|
- var types = assembly.GetTypes();
|
|
|
+ var types = assembly.GetTypes();
|
|
|
var namespaceStr = $"{defaultInterfaceName}.{defaultInterfaceFolder}";
|
|
|
foreach (var item in types)
|
|
|
{
|
|
@@ -181,11 +185,11 @@ namespace WingCloudServer
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- dic.Add(desc, new List<string> () { item.Name });
|
|
|
+ dic.Add(desc, new List<string>() { item.Name });
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
return dic;
|
|
|
}
|
|
|
|
|
@@ -197,12 +201,12 @@ namespace WingCloudServer
|
|
|
{
|
|
|
List<RemoteServiceInfo> resList = new List<RemoteServiceInfo>();
|
|
|
var remoteStr = ConfigurationManager.GetParammeter<StringParameter>("Services", "Remote").Value;
|
|
|
- var rpcHttpServicesString = ConfigurationManager.GetParammeter<StringParameter>("Services","JsonRpcHttp").Value;
|
|
|
+ var rpcHttpServicesString = ConfigurationManager.GetParammeter<StringParameter>("Services", "JsonRpcHttp").Value;
|
|
|
if (!string.IsNullOrEmpty(remoteStr) && remoteStr.Split(',').Length > 0)
|
|
|
{
|
|
|
var dic = GetServiceByModuleName();
|
|
|
var list = remoteStr.Split(',');
|
|
|
- foreach(var serviceInfo in list)
|
|
|
+ foreach (var serviceInfo in list)
|
|
|
{
|
|
|
var remoteArray = serviceInfo.Split('|');
|
|
|
if (remoteArray != null && remoteArray.Length > 1)
|
|
@@ -227,6 +231,43 @@ namespace WingCloudServer
|
|
|
return resList;
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 初始化SkiaSharp
|
|
|
+ /// </summary>
|
|
|
+ private void InitSkiaSharp()
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var dllsRootPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "runtimes");
|
|
|
+ var skiaSharpPath = "";
|
|
|
+ var libSkiaSharpDest = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Dependencies", "libSkiaSharp.dll");
|
|
|
+ switch (Environment.OSVersion.Platform)
|
|
|
+ {
|
|
|
+ case PlatformID.Win32NT:
|
|
|
+ if (Environment.Is64BitProcess)
|
|
|
+ {
|
|
|
+ skiaSharpPath = Path.Combine(dllsRootPath, "win-x64", "native", "libSkiaSharp.dll");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ skiaSharpPath = Path.Combine(dllsRootPath, "win-x86", "native", "libSkiaSharp.dll");
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case PlatformID.MacOSX:
|
|
|
+ skiaSharpPath = Path.Combine(dllsRootPath, "osx", "native", "libSkiaSharp.dylib");
|
|
|
+ libSkiaSharpDest = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Dependencies", "libSkiaSharp.dylib");
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ File.Copy(skiaSharpPath, libSkiaSharpDest, true);
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Logger.WriteLineError($"InitSkiaSharp error:{ex}");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private class JsonRpcLiteLogWrite : JsonRpcLite.Log.ILogWriter
|
|
|
{
|
|
|
public void WriteDebug(string message)
|
|
@@ -254,5 +295,5 @@ namespace WingCloudServer
|
|
|
Logger.WriteLineWarn(message);
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
}
|