public static bool RestartListener(bool newSSL, int newPort, EcoHandler handle) { ServicesAPI.StopEcoService(); bool flag = ServicesAPI.StartEcoService(newSSL, newPort, handle); if (flag) { Common.WriteLine(string.Concat(new object[] { "Eco Listener is restarted successfully, ssl=", newSSL, ", port=", newPort }), new string[0]); } else { Common.WriteLine(string.Concat(new object[] { "Failed to restart Eco Listener, ssl=", newSSL, ", port=", newPort }), new string[0]); } return(flag); }
public static void StopDispatcher() { lock (DispatchAPI._lockDispatch) { Common.WriteLine("StopDispatcher ...", new string[0]); if (DispatchAPI._ecoHandler != null) { DispatchAPI._ecoHandler.Stop(); } DispatchAPI._ecoHandler = null; ServicesAPI.StopEcoService(); SessionAPI.StopSessionManager(); Common.WriteLine("StopDispatcher Done", new string[0]); } }
public static bool StartDispatcher(int port, bool useSSL = true) { bool result; lock (DispatchAPI._lockDispatch) { try { DispatchAPI._isServerRole = true; if (port == 0) { DispatchAPI._localConnection = true; } else { DispatchAPI.ExtractCertificate("MonitorServers.pfx"); } SessionAPI.StartSessionManager(); DispatchAPI._ecoHandler = new EcoHandler(); DispatchAPI._ecoHandler.Start(true); DeviceInfo.cbOnDBUpdated = new DeviceInfo.DelegateOnDbUpdate(DispatchAPI._ecoHandler.OnReloadDBData); DevAccessCfg._cbOnAutoModeUpdated = new DevAccessCfg.DelegateOnAutoModeUpdate(DispatchAPI._ecoHandler.OnAutoDiscovery); bool flag2 = ServicesAPI.StartEcoService(useSSL, port, DispatchAPI._ecoHandler); result = flag2; } catch (Exception ex) { Common.WriteLine("StartDispatcher: {0}", new string[] { ex.Message }); result = false; } } return(result); }
public static bool StartEcoService(bool ssl, int port, EcoHandler handle) { Common.WriteLine("StartEcoService... ssl=" + ssl.ToString() + ", port=" + port.ToString(), new string[0]); bool flag = false; try { ServerConfig serverConfig = new ServerConfig(); serverConfig.ssl = ssl; serverConfig.MaxListen = 100; serverConfig.BufferSize = 4096; serverConfig.Protocol = ecoServerProtocol.ServerTypes.TCP; serverConfig.serverName = "Eco Server"; serverConfig.tokenList = ""; serverConfig.MaxConnect = 3000; serverConfig.port = 7979; if (port != 0) { serverConfig.port = port; } if (serverConfig.ssl) { if (File.Exists(ServicesAPI._sCodebase + "MonitorServers.pfx")) { serverConfig.TlsCertificate = new X509Certificate2(ServicesAPI._sCodebase + "MonitorServers.pfx", "ecoserver"); ServicesAPI._ecoListener = new ServerSSL <EcoContext, EcoHandler>(serverConfig); } else { Common.WriteLine("Server Certificate is lost: {0}", new string[] { ServicesAPI._sCodebase + "MonitorServers.pfx" }); } } else { ServicesAPI._ecoListener = new BaseTCPServer <EcoContext, EcoHandler>(serverConfig); } if (ServicesAPI._ecoListener != null) { if (port == 0) { Random random = new Random(); for (int i = 128; i > 0; i++) { int usePort = 30000 + random.Next(35534); flag = ServicesAPI._ecoListener.Start(handle, usePort); if (flag) { InterProcessShared <Dictionary <string, string> > .setInterProcessKeyValue("Listen_Port", usePort.ToString()); ValuePairs.setValuePair("ServicePort", usePort.ToString()); ValuePairs.SaveValueKeyToRegistry(true); break; } } } else { flag = ServicesAPI._ecoListener.Start(handle, -1); if (flag) { ValuePairs.setValuePair("ServicePort", port.ToString()); ValuePairs.SaveValueKeyToRegistry(true); } } } } catch (Exception ex) { Common.WriteLine("StartEcoService: {0}", new string[] { ex.Message }); } return(flag); }