/// <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); } }
private async Task initialize() { string resultStr = await HttpPost.PostAsync(Config.RemoteGetHotelConfigUrl, null); var hotel = JsonConvert.DeserializeObject <YummyOnlineDAO.Models.Hotel>(resultStr); Config.HotelId = hotel.Id; Title += $" {hotel.Name}"; TcpClient tcp = new TcpClient( IPAddress.Parse(Config.TcpServerIp), Config.TcpServerPort, new PrintDineClientConnectProtocol(Config.HotelId) ); tcp.CallBackWhenMessageReceived = async(t, p) => { if (t == TcpProtocolType.PrintDine) { PrintDineProtocol protocol = (PrintDineProtocol)p; await printDine(protocol.DineId, protocol.DineMenuIds, protocol.PrintTypes); } else if (t == TcpProtocolType.PrintShifts) { PrintShiftsProtocol protocol = (PrintShiftsProtocol)p; await printShifts(protocol.Ids, protocol.DateTime); } }; tcp.CallBackWhenConnected = () => { serverLog("服务器连接成功", LogLevel.Success); remoteLog(Log.LogLevel.Success, "Printer Connected"); }; tcp.CallBackWhenExceptionOccured = (e) => { serverLog(e.Message, LogLevel.Error); remoteLog(Log.LogLevel.Error, e.Message, e.ToString()); }; tcp.Start(); }
/// <summary> /// 向饭店打印机发送打印订单协议 /// </summary> private void sendPrintDineProtocol(int hotelId, PrintDineProtocol protocol) { send(Clients[hotelId].Client, protocol); }