Beispiel #1
0
        public async Task Initialize()
        {
            YummyOnlineManager manager = new YummyOnlineManager();

            waitingForVerificationClients = new WaitingForVerificationClients(log, send);
            systemClient         = new SystemClient(log, send, GetTcpServerStatus);
            newDineInformClients = new NewDineInformClients(log, send, await manager.GetGuids());
            printerClients       = new PrinterClients(log, send, await manager.GetHotels());

            log($"Binding {ip}:{port}", Log.LogLevel.Info);

            tcp.StartListening(IPAddress.Parse(ip), port, client => {
                TcpClientInfo clientInfo = new TcpClientInfo(client);
                waitingForVerificationClients.Add(clientInfo);

                log($"{clientInfo.OriginalRemotePoint} Connected, Waiting for verification", Log.LogLevel.Info);
            });

            System.Timers.Timer timer = new System.Timers.Timer(10 * 1000);
            timer.Elapsed += (e, o) => {
                // 30秒之内已连接但是未发送身份信息的socket断开
                waitingForVerificationClients.HandleTimeOut();

                //60秒之内没有接收到心跳包的socket断开, 或发送心跳包失败的socket断开
                systemClient.HandleTimeOut();
                newDineInformClients.HandleTimeOut();
                printerClients.HandleTimeOut();
            };
            timer.Start();
        }
Beispiel #2
0
        private async Task refreshNewDineInformClients(NewDineInformClients newDineInformClients)
        {
            List <NewDineInformClientGuid> guids = await new YummyOnlineManager().GetGuids();

            newDineInformClients.RefreshClients(guids);
        }
Beispiel #3
0
        public void SystemCommand(TcpClientInfo clientInfo, SystemCommandProtocol protocol, NewDineInformClients newDineInformClients)
        {
            if (ClientInfo != clientInfo)
            {
                log($"{clientInfo.OriginalRemotePoint} Received SystemCommand From Invalid SystemClient", Log.LogLevel.Error);
                clientInfo.Close();
                return;
            }

            switch (protocol.CommandType)
            {
            case SystemCommandType.RefreshNewDineClients:
                log($"{clientInfo.OriginalRemotePoint} Refresh NewDineInformClients", Log.LogLevel.Success);
                var _ = refreshNewDineInformClients(newDineInformClients);
                break;

            case SystemCommandType.RequestTcpServerStatus:
                log($"{clientInfo.OriginalRemotePoint} Request TcpServerStatus", Log.LogLevel.Success);
                requestTcpServerStatus();
                break;
            }
        }