private static PandaPacket getLabelDataResponse(string clientID, PandaPacket request) { // PandaPacket response = null; DataSet ds = null; try { //Extract message body string barcode1 = request.MessageBody.Substring(0, 32).TrimEnd(); string barcode2 = request.MessageBody.Substring(32, 32).TrimEnd(); string barcode3 = request.MessageBody.Substring(64, 32).TrimEnd(); string barcode4 = request.MessageBody.Substring(96, 32).TrimEnd(); string barcode5 = request.MessageBody.Substring(128, 32).TrimEnd(); string barcode6 = request.MessageBody.Substring(160, 32).TrimEnd(); float weight = Convert.ToInt32(request.MessageBody.Substring(192, 5)) / 100; //Process the label data request ds = CartonMgr.ProcessLabelDataRequest(barcode1, barcode2, barcode3, barcode4, barcode5, barcode6, weight); if (ds != null) { //New carton response = PandaPacket.Encode(clientID, RESPONSE_LABELDATA, request, 0, 1, PandaPacket.FormatLabelDataMessageBody(ds.Tables["PandATable"].Rows[0]["CartonID"].ToString(), int.Parse(ds.Tables["PandATable"].Rows[0]["StatusCode"].ToString()), ds.Tables["PandATable"].Rows[0]["LabelData"].ToString())); } } catch (Exception ex) { AppTrace.Instance().TheTrace.WriteLine(new TraceMessage("Error occurred while processing request for label data- " + ex.ToString(), AppLib.EVENTLOGNAME, LogLevel.Error, "PacketMgr")); if (ds != null) { response = PandaPacket.Encode(clientID, RESPONSE_LABELDATA, request, 0, 1, PandaPacket.FormatLabelDataMessageBody(ds.Tables["PandATable"].Rows[0]["CartonID"].ToString(), int.Parse(ds.Tables["PandATable"].Rows[0]["StatusCode"].ToString()), ds.Tables["PandATable"].Rows[0]["LabelData"].ToString())); } } return(response); }
/// <summary>Processes </summary> /// <param name="clientID">A unique identifier for the requestor (can be an empty string).</param> /// <param name="request">A Tsort.PandA.PandaPacket request.</param> /// <exceptions cref="ApplicationException">Thrown for unexpected errors.</exceptions> /// <returns>An instance of Tsort.PandA.PandaPacket containing the response.</returns> public PandaPacket ProcessPandARequest(string clientID, PandaPacket request) { //Process a PandA request from a remote socket client PandaPacket response = null; DateTime started = DateTime.Now; try { //Process the PandA message; Decode() always returns a non-null request object ArgixTrace.WriteLine(new TraceMessage("", AppLib.PRODUCTNAME, LogLevel.Information, "PandaSvc")); ArgixTrace.WriteLine(new TraceMessage("REQUEST:" + request.Message, AppLib.PRODUCTNAME, LogLevel.Information, "PandaSvc")); if (request.Valid) { //Check if this was a prior request PandaPacket priorResponse = isPriorRequest(clientID, request); if (priorResponse != null) { //This was a prior message; return prior response response = priorResponse; ArgixTrace.WriteLine(new TraceMessage("PRIOR RESPONSE: " + priorResponse.Message, AppLib.PRODUCTNAME, LogLevel.Information, "PandaSvc")); } else { //New, valid message; persist request and route to message handler switch (request.MessageCode) { case REQUEST_LABELDATA: DataSet ds = null; try { //Extract message body and process message request string barcode1 = request.MessageBody.Substring(0, 32).TrimEnd(); string barcode2 = request.MessageBody.Substring(32, 32).TrimEnd(); string barcode3 = request.MessageBody.Substring(64, 32).TrimEnd(); string barcode4 = request.MessageBody.Substring(96, 32).TrimEnd(); string barcode5 = request.MessageBody.Substring(128, 32).TrimEnd(); string barcode6 = request.MessageBody.Substring(160, 32).TrimEnd(); decimal weight = decimal.Parse(request.MessageBody.Substring(192, 5)) / 100; string[] inputs = new string[] { barcode1, barcode2, barcode3, barcode4, barcode5, barcode6 }; ds = ProcessLabelDataRequest(inputs, weight); if (ds != null) { response = PandaPacket.Encode(clientID, RESPONSE_LABELDATA, 0, 1, PandaPacket.FormatLabelDataMessageBody(ds.Tables["PandATable"].Rows[0]["CartonID"].ToString(), int.Parse(ds.Tables["PandATable"].Rows[0]["StatusCode"].ToString()), ds.Tables["PandATable"].Rows[0]["LabelData"].ToString()), request.MessageNumber, request); } } catch (Exception ex) { if (ds != null) { response = PandaPacket.Encode(clientID, RESPONSE_LABELDATA, 0, 1, PandaPacket.FormatLabelDataMessageBody(ds.Tables["PandATable"].Rows[0]["CartonID"].ToString(), int.Parse(ds.Tables["PandATable"].Rows[0]["StatusCode"].ToString()), ds.Tables["PandATable"].Rows[0]["LabelData"].ToString()), request.MessageNumber, request); } ArgixTrace.WriteLine(new TraceMessage("An error occurred while processing Panda label data request-->" + ex.Message, AppLib.PRODUCTNAME, LogLevel.Error, "PandaSvc")); } this.mLastRequest = request; try { request.ProcessingTime = (float)((TimeSpan)DateTime.Now.Subtract(started)).TotalSeconds; } catch {} if (PandaRequestComplete != null) { PandaRequestComplete(null, new PandaPacketEventArgs(request)); } break; case REQUEST_VERIFYLABEL: try { //Find the carton string cartonID = request.MessageBody.Substring(0, PandaPacket.CartonIDLength).TrimEnd(); string verifyCode = request.MessageBody.Substring(PandaPacket.CartonIDLength, 1).TrimEnd(); string verifyFlag = ProcessVerifyLabelRequest(cartonID, verifyCode); response = PandaPacket.Encode(clientID, RESPONSE_VERIFYLABEL, 0, 1, verifyFlag, request.MessageNumber, request); } catch (Exception ex) { response = PandaPacket.Encode(clientID, RESPONSE_VERIFYLABEL, 0, 1, VERIFY_NO, request.MessageNumber, request); ArgixTrace.WriteLine(new TraceMessage("An error occurred while processing Panda verify label request-->" + ex.Message, AppLib.PRODUCTNAME, LogLevel.Error, "PandaSvc")); } this.mLastRequest = request; try { request.ProcessingTime = (float)((TimeSpan)DateTime.Now.Subtract(started)).TotalSeconds; } catch {} if (PandaRequestComplete != null) { PandaRequestComplete(null, new PandaPacketEventArgs(request)); } break; case REQUEST_RESEND: response = this.mLastRequest.Response; ArgixTrace.WriteLine(new TraceMessage("Resend requested.", AppLib.PRODUCTNAME, LogLevel.Warning, "PandaSvc")); if (PandaResendComplete != null) { PandaResendComplete(null, EventArgs.Empty); } break; case REQUEST_HEARTBEAT: try { response = PandaPacket.Encode(clientID, RESPONSE_HEARTBEAT, 0, 1, "", request.MessageNumber, request); } catch (Exception ex) { ArgixTrace.WriteLine(new TraceMessage("An error occurred while processing Panda heartbeat request-->" + ex.Message, AppLib.PRODUCTNAME, LogLevel.Error, "PandaSvc")); } if (HeartbeatRequestComplete != null) { HeartbeatRequestComplete(null, EventArgs.Empty); } break; default: ArgixTrace.WriteLine(new TraceMessage("Unknown message code.", AppLib.PRODUCTNAME, LogLevel.Warning, "PandaSvc")); break; } } } else { //Invalid message packet response = PandaPacket.Encode(clientID, RESPONSE_MSGERROR, 0, 0, "", request.MessageNumber, request); ArgixTrace.WriteLine(new TraceMessage("Message failed (decode) validation...", AppLib.PRODUCTNAME, LogLevel.Warning, "PandaSvc")); } } catch (Exception ex) { response = PandaPacket.Encode(clientID, RESPONSE_MSGERROR, 0, 0, "", request.MessageNumber, request); ArgixTrace.WriteLine(new TraceMessage("An error occurred while processing Panda message-->" + ex.Message, AppLib.PRODUCTNAME, LogLevel.Error, "PandaSvc")); } finally { if (response != null) { ArgixTrace.WriteLine(new TraceMessage("RESPONSE: " + new ASCIIEncoding().GetString(response.Bytes), AppLib.PRODUCTNAME, LogLevel.Information, "PandaSvc")); } else { ArgixTrace.WriteLine(new TraceMessage("RESPONSE: NULL", AppLib.PRODUCTNAME, LogLevel.Warning, "PandaSvc")); } } return(response); }