示例#1
0
 public void ClientConnected(TcpClientInfo clientInfo,
                             WaitingForVerificationClients waitingForVerificationClients)
 {
     log($"{clientInfo.OriginalRemotePoint} (System) Connected", Log.LogLevel.Success);
     ClientInfo = clientInfo;
     waitingForVerificationClients.ClientConnected(clientInfo);
 }
示例#2
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();
        }
示例#3
0
        public void ClientConnected(TcpClientInfo clientInfo, PrintDineClientConnectProtocol protocol,
                                    WaitingForVerificationClients waitingForVerificationClients)
        {
            lock (this) {
                log($"{clientInfo.OriginalRemotePoint} (Printer): HotelId: {protocol.HotelId} Request Connection", Log.LogLevel.Info);

                if (!Clients.ContainsKey(protocol.HotelId))
                {
                    log($"{clientInfo.OriginalRemotePoint} Printer HotelId {protocol.HotelId} Not Matched", Log.LogLevel.Warning);
                    clientInfo.Close();
                    return;
                }

                KeyValuePair <int, TcpClientInfo> pair = Clients.FirstOrDefault(p => p.Key == protocol.HotelId);

                if (pair.Value != null)
                {
                    log($"Printer HotelId {pair.Key} Repeated", Log.LogLevel.Warning);
                    pair.Value.ReadyToReplaceClient = clientInfo;
                    pair.Value.Close();
                }
                else
                {
                    Clients[pair.Key] = clientInfo;
                }

                log($"{clientInfo.OriginalRemotePoint} (Printer of Hotel {protocol.HotelId}) Connected", Log.LogLevel.Success);

                // 打印存储在打印等待队列中的所有请求
                while (WaitedQueue[pair.Key].Count > 0)
                {
                    BaseTcpProtocol printProtocol = WaitedQueue[pair.Key].Dequeue();
                    if (printProtocol.Type == TcpProtocolType.PrintDine)
                    {
                        sendPrintDineProtocol(pair.Key, (PrintDineProtocol)printProtocol);
                    }
                    else if (printProtocol.Type == TcpProtocolType.PrintShifts)
                    {
                        sendPrintShiftsProtocol(pair.Key, (PrintShiftsProtocol)printProtocol);
                    }
                    log($"Send Waited Dine of Hotel {pair.Key}", Log.LogLevel.Success);
                }

                waitingForVerificationClients.ClientConnected(clientInfo);
            }
        }
示例#4
0
        public void ClientConnected(TcpClientInfo clientInfo, NewDineInformClientConnectProtocol protocol,
                                    WaitingForVerificationClients waitingForVerificationClients)
        {
            lock (this) {
                log($"{clientInfo.OriginalRemotePoint} (NewDineInformClient): Guid: {protocol.Guid} Request Connection", Log.LogLevel.Info);

                if (protocol.Guid == new Guid())
                {
                    log($"{clientInfo.OriginalRemotePoint} NewDineInformClient Lack Guid", Log.LogLevel.Warning);
                    clientInfo.Close();
                    return;
                }

                KeyValuePair <NewDineInformClientGuid, TcpClientInfo> pair = Clients.FirstOrDefault(p => p.Key.Guid == protocol.Guid);
                if (pair.Key == null)
                {
                    log($"{clientInfo.OriginalRemotePoint} NewDineInformClient Guid {protocol.Guid} Not Matched", Log.LogLevel.Warning);
                    clientInfo.Close();
                    return;
                }
                else
                {
                    if (pair.Value != null)
                    {
                        log($"NewDineInformClient Guid {pair.Key.Guid} Repeated", Log.LogLevel.Warning);
                        pair.Value.ReadyToReplaceClient = clientInfo;
                        pair.Value.Close();
                    }
                    else
                    {
                        Clients[pair.Key] = clientInfo;
                    }

                    log($"{clientInfo.OriginalRemotePoint} ({pair.Key.Description}) Connected", Log.LogLevel.Success);
                }

                waitingForVerificationClients.ClientConnected(clientInfo);
            }
        }