public GatewayConnector(MicroServiceHost microServiceHost, ICpuInfo cpuInfo, SSLConfiguration sSLConfiguration, ILogger <GatewayConnector> logger, IKeyLocker keyLocker) { _microServiceHost = microServiceHost; _logger = logger; _keyLocker = keyLocker; _cpuInfo = cpuInfo; _SSLConfiguration = sSLConfiguration; }
public RequestReception(ILogger <RequestReception> logger, ProcessExitHandler processExitHandler, MicroServiceHost microServiceProvider) { _logger = logger; _MicroServiceProvider = microServiceProvider; _processExitHandler = processExitHandler; _SSLConfiguration = _MicroServiceProvider.ServiceProvider.GetService <SSLConfiguration>(); var handlerTypes = typeof(RequestReception).Assembly.DefinedTypes.Where(m => m.ImplementedInterfaces.Contains(typeof(IRequestHandler))); foreach (var type in handlerTypes) { var handler = (IRequestHandler)microServiceProvider.ServiceProvider.GetService(type); _cache[handler.MatchType] = handler; } }
void connect() { SSLConfiguration sSLConfiguration = null; while (true) { if (_microServiceHost.ServiceProvider == null || _microServiceHost.Id == null) { Thread.Sleep(1000); continue; } if (sSLConfiguration == null) { sSLConfiguration = _microServiceHost.ServiceProvider.GetService <SSLConfiguration>(); _logger = _microServiceHost.ServiceProvider.GetService <ILogger <MapFileManager> >(); } try { using (var client = new GatewayClient(_gatewayAddress, sSLConfiguration)) { client.WriteServiceData(new GatewayCommand { Type = CommandType.ListenFileChange, Content = _dict.Keys.ToJsonString() }); client.ReadTimeout = 60000; while (true) { var ret = client.ReadServiceObject <InvokeResult <string> >(); if (ret.Data != null) { string filepath = ret.Data; _logger?.LogInformation("文件映射系统收到新的文件:{0}", filepath); int len = client.ReadInt(); var data = client.ReceiveDatas(len); try { var item = _dict[filepath]; string localpath = item.LocalPath; File.WriteAllBytes(localpath, data); if (item.Callback != null) { item.Callback(filepath, localpath); } } catch (Exception ex) { _logger?.LogError(ex, ex.Message); } } client.WriteServiceData(new InvokeResult()); } } } catch (Exception ex) { } Thread.Sleep(1000); } }
public GatewayClient(NetAddress addr, SSLConfiguration sSLConfiguration) : base(addr, sSLConfiguration != null ? sSLConfiguration.GatewayClientCertificate : null) { }