Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        private static PandaPacket getHeartbeatResponse(string clientID, PandaPacket request)
        {
            //Reply with a heartbeat signal
            PandaPacket response = null;

            try {
                response = PandaPacket.Encode(clientID, RESPONSE_HEARTBEAT, request, 0, 1, "");
            }
            catch (Exception ex) {
                AppTrace.Instance().TheTrace.WriteLine(new TraceMessage("An error occurred while processing request for heartbeat." + ex.ToString(), AppLib.EVENTLOGNAME, LogLevel.Error, "PacketMgr"));
            }
            return(response);
        }
Esempio n. 3
0
        private static PandaPacket getVerifyLabelResponse(string clientID, PandaPacket request)
        {
            //Verify the requested carton
            PandaPacket response = null;

            try {
                //Find the carton
                string cartonID   = request.MessageBody.Substring(0, PandaPacket.CartonIDLength).TrimEnd();
                string verifyCode = request.MessageBody.Substring(PandaPacket.CartonIDLength, 1).TrimEnd();
                string verifyFlag = CartonMgr.ProcessVerifyLabelRequest(cartonID, verifyCode);
                response = PandaPacket.Encode(clientID, RESPONSE_VERIFYLABEL, request, 0, 1, verifyFlag);
            }
            catch (Exception ex) {
                AppTrace.Instance().TheTrace.WriteLine(new TraceMessage("An error occurred while processing request to verify label." + ex.ToString(), AppLib.EVENTLOGNAME, LogLevel.Error, "PacketMgr"));
                response = PandaPacket.Encode(clientID, RESPONSE_VERIFYLABEL, request, 0, 1, "N");
            }
            return(response);
        }
Esempio n. 4
0
        public static byte[] ProcessPandARequest(string clientID, byte[] bytes)
        {
            //Process a PandA request from a remote socket client
            PandaPacket request  = null;
            PandaPacket response = null;
            DateTime    started  = DateTime.Now;

            try {
                //Process the message
                request = PandaPacket.Decode(clientID, bytes);
                AppTrace.Instance().TheTrace.WriteLine(new TraceMessage("REQUEST:" + request.Message, AppLib.EVENTLOGNAME, LogLevel.Information, "PacketMgr"));
                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;
                        AppTrace.Instance().TheTrace.WriteLine(new TraceMessage("PRIOR RESPONSE: " + priorResponse.Message, AppLib.EVENTLOGNAME, LogLevel.Information, "PacketMgr"));
                    }
                    else
                    {
                        //New, valid message; persist request and route to message handler
                        switch (request.MessageCode)
                        {
                        case REQUEST_LABELDATA:
                            response    = getLabelDataResponse(clientID, request);
                            LastRequest = request;
                            try { request.ProcessingTime = ((TimeSpan)DateTime.Now.Subtract(started)).TotalSeconds; } catch {}
                            if (LabelDataRequestComplete != null)
                            {
                                LabelDataRequestComplete(null, new PandaPacketEventArgs(request));
                            }
                            break;

                        case REQUEST_VERIFYLABEL:
                            response    = getVerifyLabelResponse(clientID, request);
                            LastRequest = request;
                            try { request.ProcessingTime = ((TimeSpan)DateTime.Now.Subtract(started)).TotalSeconds; } catch {}
                            if (VerifyLabelRequestComplete != null)
                            {
                                VerifyLabelRequestComplete(null, new PandaPacketEventArgs(request));
                            }
                            break;

                        case REQUEST_HEARTBEAT:
                            response = getHeartbeatResponse(clientID, request);
                            if (HeartbeatRequestComplete != null)
                            {
                                HeartbeatRequestComplete(null, EventArgs.Empty);
                            }
                            break;

                        case REQUEST_RESEND:
                            response = LastRequest.Response;
                            AppTrace.Instance().TheTrace.WriteLine(new TraceMessage("Resend requested.", AppLib.EVENTLOGNAME, LogLevel.Warning, "PacketMgr"));
                            if (ResendRequestComplete != null)
                            {
                                ResendRequestComplete(null, EventArgs.Empty);
                            }
                            break;

                        default:
                            AppTrace.Instance().TheTrace.WriteLine(new TraceMessage("Unknown message code.", AppLib.EVENTLOGNAME, LogLevel.Warning, "PacketMgr"));
                            break;
                        }
                    }
                }
                else
                {
                    //Invalid message packet
                    response = PandaPacket.Encode(clientID, RESPONSE_MSGERROR, request, 0, 0, "");
                    AppTrace.Instance().TheTrace.WriteLine(new TraceMessage("Message failed (decode) validation...", AppLib.EVENTLOGNAME, LogLevel.Warning, "PacketMgr"));
                }
            }
            catch (Exception ex) {
                response = PandaPacket.Encode(clientID, RESPONSE_MSGERROR, request, 0, 0, "");
                AppTrace.Instance().TheTrace.WriteLine(new TraceMessage("Error occurred while processing message: " + ex.ToString(), AppLib.EVENTLOGNAME, LogLevel.Error, "PacketMgr"));
            }
            return(response != null?response.Bytes:null);
        }