Пример #1
0
        public void NewDineInform(TcpClientInfo clientInfo, NewDineInformProtocol protocol)
        {
            lock (this) {
                NewDineInformClientGuid sender = GetSender(clientInfo);
                if (sender == null)
                {
                    log($"{clientInfo.OriginalRemotePoint} Received NewDineInform From Invalid NewDineInformClient", Log.LogLevel.Error);
                    clientInfo.Close();
                    return;
                }

                log($"{clientInfo.OriginalRemotePoint} (NewDineInform): From: {sender.Description}, HotelId: {protocol.HotelId}, DineId: {protocol.DineId}, IsPaid: {protocol.IsPaid}", Log.LogLevel.Success);

                foreach (var p in Clients)
                {
                    // 不向未连接的客户端与发送方客户端 发送新订单通知信息
                    if (p.Value == null || p.Value.Client == clientInfo.Client)
                    {
                        continue;
                    }

                    send(p.Value.Client, protocol);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 请求打印交接班
        /// </summary>
        public void RequestPrintShifts(TcpClientInfo clientInfo, RequestPrintShiftsProtocol protocol, NewDineInformClientGuid sender)
        {
            lock (this) {
                if (sender == null)
                {
                    log($"{clientInfo.OriginalRemotePoint} Received RequestPrintShifts From Invalid NewDineInformClient", Log.LogLevel.Error);
                    clientInfo.Close();
                    return;
                }

                protocol.Ids = protocol.Ids ?? new List <int>();

                StringBuilder idStr = new StringBuilder();
                foreach (int id in protocol.Ids)
                {
                    idStr.Append($"{id} ");
                }

                log($"{clientInfo.OriginalRemotePoint} (RequestPrintShifts): From: {sender.Description}, HotelId: {protocol.HotelId}, Ids: {idStr}, DateTime: {protocol.DateTime.ToString("yyyy-MM-dd")}",
                    Log.LogLevel.Success);

                PrintShiftsProtocol p = new PrintShiftsProtocol(protocol.Ids, protocol.DateTime);
                if (Clients[protocol.HotelId] == null)
                {
                    WaitedQueue[protocol.HotelId].Enqueue(p);
                    log($"Printer of Hotel {protocol.HotelId} is not connected", Log.LogLevel.Error);
                    return;
                }
                sendPrintShiftsProtocol(protocol.HotelId, p);
            }
        }
Пример #3
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);
            }
        }
Пример #4
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);
            }
        }
Пример #5
0
        /// <summary>
        /// 请求打印订单
        /// </summary>
        public void RequestPrintDine(TcpClientInfo clientInfo, RequestPrintDineProtocol protocol, NewDineInformClientGuid sender)
        {
            lock (this) {
                if (sender == null)
                {
                    log($"{clientInfo.OriginalRemotePoint} Received RequestPrintDine From Invalid NewDineInformClient", Log.LogLevel.Error);
                    clientInfo.Close();
                    return;
                }

                protocol.DineMenuIds = protocol.DineMenuIds ?? new List <int>();
                protocol.PrintTypes  = protocol.PrintTypes ?? new List <PrintType>();

                StringBuilder dineMenuStr = new StringBuilder();
                for (int i = 0; i < protocol.DineMenuIds.Count; i++)
                {
                    dineMenuStr.Append(protocol.DineMenuIds[i]);
                    if (i != protocol.DineMenuIds.Count - 1)
                    {
                        dineMenuStr.Append(' ');
                    }
                }

                StringBuilder typeStr = new StringBuilder();
                foreach (var type in protocol.PrintTypes)
                {
                    typeStr.Append($"{type.ToString()} ");
                }

                log($"{clientInfo.OriginalRemotePoint} (RequestPrintDine): From: {sender.Description}, HotelId: {protocol.HotelId}, DineId: {protocol.DineId}, DineMenuIds: {dineMenuStr}, PrintTypes: {typeStr}",
                    Log.LogLevel.Success);

                PrintDineProtocol p = new PrintDineProtocol(protocol.DineId, protocol.DineMenuIds, protocol.PrintTypes);
                if (Clients[protocol.HotelId] == null)
                {
                    WaitedQueue[protocol.HotelId].Enqueue(p);
                    log($"Printer of Hotel {protocol.HotelId} is not connected", Log.LogLevel.Error);
                    return;
                }
                sendPrintDineProtocol(protocol.HotelId, p);
            }
        }
Пример #6
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;
            }
        }