static TcpMapServerWorker AddStartServer(TcpMapServer server)
        {
            var conn = new TcpMapServerWorker()
            {
                Server = server
            };

            lock (_servers)
                _servers.Add(conn);
            conn.StartWork();
            return(conn);
        }
        static public TcpMapServerWorker CreateServerWorker(TcpMapLicense lic, int port)
        {
            CheckPortAvailable(port);

            TcpMapServer server = new TcpMapServer();

            server.Id          = DateTime.Now.ToString("yyyyMMddHHmmssfff");
            server.License     = lic;
            server.IsDisabled  = false;
            server.IsValidated = true;
            server.ServerPort  = port;
            string jsonfilepath = Path.Combine(DataFolder, "TcpMapServer_" + server.Id + ".json");

            File.WriteAllText(jsonfilepath, JsonSerializer.Serialize(server));
            return(AddStartServer(server));
        }
        static public void ReAddServer(TcpMapServer server)
        {
            string jsonfilepath = Path.Combine(DataFolder, "TcpMapServer_" + server.Id + ".json");

            File.WriteAllText(jsonfilepath, JsonSerializer.Serialize(server));
            TcpMapServerWorker serverWorker = null;

            lock (_clients)
            {
                serverWorker = _servers.Where(v => v.Server.Id == server.Id).FirstOrDefault();
                if (serverWorker != null)
                {
                    _servers.Remove(serverWorker);
                }
            }
            if (serverWorker != null)
            {
                serverWorker.Stop();
            }
            AddStartServer(server);
        }