Exemple #1
0
 public static void StopEcoService()
 {
     Common.WriteLine("StopEcoService", new string[0]);
     if (ServicesAPI._ecoListener != null)
     {
         ServicesAPI._ecoListener.Stop();
     }
     ServicesAPI._ecoListener = null;
 }
Exemple #2
0
        public static bool StartBillingService(ServerConfig cfg, int replacePort, string token)
        {
            Common.WriteLine("StartEnquiryServer", new string[0]);
            ServicesAPI._billingHandler = new BillingHandler();
            ServicesAPI._billingHandler.Start(true);
            ServerConfig serverConfig = cfg;

            if (cfg == null)
            {
                serverConfig            = new ServerConfig();
                serverConfig.ssl        = false;
                serverConfig.MaxListen  = 100;
                serverConfig.BufferSize = 4096;
                serverConfig.Protocol   = ecoServerProtocol.ServerTypes.TCP;
                serverConfig.serverName = "Billing Server";
                serverConfig.port       = 8888;
                serverConfig.MaxConnect = 3000;
                if (replacePort > 0)
                {
                    serverConfig.port = replacePort;
                }
                serverConfig.tokenList = "12345678";
                if (token != null && token != string.Empty)
                {
                    serverConfig.tokenList = token;
                }
            }
            if (serverConfig.Protocol == ecoServerProtocol.ServerTypes.TCP)
            {
                ServicesAPI._billingService = new BaseTCPServer <BillingContext, BillingHandler>(serverConfig);
                if (ServicesAPI._billingService != null)
                {
                    ServicesAPI._billingService.setAuthorizedString(true, serverConfig.tokenList);
                    if (ServicesAPI._billingService.Start(ServicesAPI._billingHandler, -1))
                    {
                        Common.WriteLine("Billing Listener is started successfully, port=" + serverConfig.port, new string[0]);
                        return(true);
                    }
                }
                Common.WriteLine("Failed to start Billing Listener, port=" + serverConfig.port, new string[0]);
                return(false);
            }
            throw new InvalidOperationException("Protocol not supported.");
        }
Exemple #3
0
 public static void StopBillingService()
 {
     try
     {
         Common.WriteLine("StopBillingService", new string[0]);
         if (ServicesAPI._billingHandler != null)
         {
             ServicesAPI._billingHandler.Stop();
         }
         ServicesAPI._billingHandler = null;
         if (ServicesAPI._billingService != null)
         {
             ServicesAPI._billingService.Stop();
         }
         ServicesAPI._billingService = null;
     }
     catch (Exception ex)
     {
         Common.WriteLine("StopBillingService: {0}", new string[]
         {
             ex.Message
         });
     }
 }
Exemple #4
0
        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);
        }