/// <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); } }
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 sendPrintShiftsProtocol(int hotelId, PrintShiftsProtocol protocol) { send(Clients[hotelId].Client, protocol); }