Ejemplo n.º 1
0
        /// <summary>Returns this object as a PandaDS dataset.</summary>
        public DataSet ToDataSet()
        {
            PandaDS ds = null;

            try {
                ds = new PandaDS();
                ds.PacketTable.AddPacketTableRow(this.mReceived,
                                                 this.mMessageLength,
                                                 this.mMessageCode,
                                                 this.mMessageNumber,
                                                 this.mOriginalMessageCode,
                                                 this.mMessageFlags,
                                                 this.mRecordIterator,
                                                 this.mMessageBody,
                                                 this.mValid,
                                                 (this.mException != null?this.mException.ToString():""),
                                                 this.mProcessingTime,
                                                 this.mClientID);
                ds.AcceptChanges();
            }
            catch (Exception ex) { Debug.Write(ex.ToString() + "\n"); }
            return(ds);
        }
Ejemplo n.º 2
0
        public PandaDS ProcessLabelDataRequest(string[] inputs, decimal weight)
        {
            //Create a new carton
            string cartonID = "", zpl = "";
            int    statusCode        = STATUS_NONE;
            ApplicationException aex = null;
            PandaDS ds = new PandaDS();

            //Validate for non-carton requests (scanner tripped)
            bool   hasInputData = false;
            string _inputs      = "";

            for (int i = 0; i < inputs.Length; i++)
            {
                if (inputs[i].Trim().Length > 0)
                {
                    hasInputData = true;
                }
                _inputs += (i + 1).ToString() + "=" + inputs[i] + "; ";
            }
            ArgixTrace.WriteLine(new TraceMessage("LABEL DATA REQUEST: " + _inputs + "weight=" + weight.ToString(), App.EventLogName, LogLevel.Information, "PandaSvc"));
            if (!hasInputData && weight == 0)
            {
                ArgixTrace.WriteLine(new TraceMessage("LABEL DATA RESPONSE: no inputs; no weight; processing aborted...", App.EventLogName, LogLevel.Information, "PandaSvc"));
                return(ds);
            }
            try {
                //Begin processing a new message request
                //if(this.LabelDataRequest != null) this.LabelDataRequest(null,EventArgs.Empty);
                try {
                    //Create a default carton identifier
                    DateTime dt  = DateTime.Now;
                    int      sec = ((3600 * dt.Hour) + (60 * dt.Minute) + dt.Second);
                    cartonID = dt.ToString("yyyy").Substring(3, 1) + dt.ToString("MM") + dt.ToString("dd") + sec.ToString("00000") + "0000";

                    //Get an outbound label for this carton
                    SortedItem sortedItem = this.mOperator.ProcessInputs(inputs, weight);
                    if (sortedItem != null)
                    {
                        try {
                            cartonID = sortedItem.LabelNumber;
                            zpl      = sortedItem.LabelFormat;
                            sortedItem.ThrowException();
                            statusCode = STATUS_CARTON_OK;
                            ArgixTrace.WriteLine(new TraceMessage("Carton processing successful [label data]...", App.EventLogName, LogLevel.Debug, "PandaSvc"));
                        }
                        catch (Tsort.InboundLabelException ex) {
                            //Test for various inbound label exceptions
                            bool allInvalid = true;
                            for (int i = 0; i < inputs.Length; i++)
                            {
                                if (inputs[i].Trim().Length > 0)
                                {
                                    allInvalid = false; break;
                                }
                            }
                            if (allInvalid)
                            {
                                statusCode = STATUS_SCANERROR_NODATA;
                                ArgixTrace.WriteLine(new TraceMessage("Message data validation failed [no data from scanner]-->" + ex.Message + (ex.InnerException != null?"-->" + ex.InnerException.Message:"") + "...", App.EventLogName, LogLevel.Warning, "PandaSvc"));
                            }
                            allInvalid = true;
                            for (int i = 0; i < inputs.Length; i++)
                            {
                                if (inputs[i].Replace("?", "").Trim().Length > 0)
                                {
                                    allInvalid = false; break;
                                }
                            }
                            if (allInvalid && statusCode == STATUS_NONE)
                            {
                                statusCode = STATUS_SCANERROR_NOREAD;
                                ArgixTrace.WriteLine(new TraceMessage("Message data validation failed [no read: ?]-->" + ex.Message + (ex.InnerException != null?"-->" + ex.InnerException.Message:"") + "...", App.EventLogName, LogLevel.Warning, "PandaSvc"));
                            }
                            allInvalid = true;
                            for (int i = 0; i < inputs.Length; i++)
                            {
                                if (inputs[i].Replace("#", "").Trim().Length > 0)
                                {
                                    allInvalid = false; break;
                                }
                            }
                            if (allInvalid && statusCode == STATUS_NONE)
                            {
                                statusCode = STATUS_SCANERROR_CONFLICT;
                                ArgixTrace.WriteLine(new TraceMessage("Message data validation failed [label conflict: #]-->" + ex.Message + (ex.InnerException != null?"-->" + ex.InnerException.Message:"") + "...", App.EventLogName, LogLevel.Warning, "PandaSvc"));
                            }
                            if (statusCode == STATUS_NONE)
                            {
                                statusCode = STATUS_SCANERROR_LABELFAILED;
                                ArgixTrace.WriteLine(new TraceMessage("Message data validation failed [inbound label exception]-->" + ex.Message + (ex.InnerException != null?"-->" + ex.InnerException.Message:"") + "...", App.EventLogName, LogLevel.Warning, "PandaSvc"));
                            }
                        }
                        catch (Tsort.ZeroWeightException ex) {
                            statusCode = STATUS_SCANERROR_WEIGHTBAD;
                            ArgixTrace.WriteLine(new TraceMessage("Message data validation failed [zero weight exception]-->" + ex.Message + (ex.InnerException != null?"-->" + ex.InnerException.Message:"") + "...", App.EventLogName, LogLevel.Warning, "PandaSvc"));
                        }
                        catch (Tsort.OverWeightException ex) {
                            statusCode = STATUS_SCANERROR_WEIGHTBAD;
                            ArgixTrace.WriteLine(new TraceMessage("Message data validation failed [over weight exception]-->" + ex.Message + (ex.InnerException != null?"-->" + ex.InnerException.Message:"") + "...", App.EventLogName, LogLevel.Warning, "PandaSvc"));
                        }
                        catch (Tsort.DestinationRoutingException ex) {
                            statusCode = STATUS_SCANERROR_LABELFAILED;
                            ArgixTrace.WriteLine(new TraceMessage("Sorted item processing failed [destination/routing exception]-->" + ex.Message + (ex.InnerException != null?"-->" + ex.InnerException.Message:"") + "...", App.EventLogName, LogLevel.Warning, "PandaSvc"));
                        }
                        catch (Exception ex) {
                            statusCode = STATUS_SCANERROR_LABELFAILED;
                            ArgixTrace.WriteLine(new TraceMessage("Sorted item processing failed [unexpected exception]-->" + ex.Message + (ex.InnerException != null?"-->" + ex.InnerException.Message:"") + "...", App.EventLogName, LogLevel.Warning, "PandaSvc"));
                        }
                        zpl = zpl.Replace(Tsort.Labels.TokenLibrary.STATUSCODE, statusCode.ToString());
                    }
                    else
                    {
                        aex        = new ApplicationException("Carton processing failed [no sorted item]...");
                        statusCode = STATUS_SCANERROR_LABELFAILED;
                        zpl        = createErrorLabelFormat(STATUS_SCANERROR_LABELFAILED, aex);
                        ArgixTrace.WriteLine(new TraceMessage(aex.Message, App.EventLogName, LogLevel.Warning, "PandaSvc"));
                    }
                }
                catch (Exception ex) {
                    aex        = new ApplicationException("Carton processing failed [sorted item processing threw an exception]-->" + ex.Message + (ex.InnerException != null?"-->" + ex.InnerException.Message:"") + "...", ex);
                    statusCode = STATUS_SCANERROR_LABELFAILED;
                    zpl        = createErrorLabelFormat(STATUS_SCANERROR_LABELFAILED, ex);
                    ArgixTrace.WriteLine(new TraceMessage(aex.Message, App.EventLogName, LogLevel.Warning, "PandaSvc"));
                }
                ds.PandaTable.AddPandaTableRow(cartonID, statusCode, zpl);
                ds.AcceptChanges();
            }
            catch (Exception ex) {
                aex        = new ApplicationException("Carton processing failed [unexpected exception]-->" + ex.Message + (ex.InnerException != null?"-->" + ex.InnerException.Message:"") + "...", ex);
                statusCode = STATUS_ERROR_UNKNOWN;
                zpl        = createErrorLabelFormat(STATUS_ERROR_UNKNOWN, ex);
                ds.PandaTable.AddPandaTableRow(cartonID, statusCode, zpl);
                ds.AcceptChanges();
                ArgixTrace.WriteLine(new TraceMessage(aex.Message, App.EventLogName, LogLevel.Warning, "PandaSvc"));
            }
            finally {
                ArgixTrace.WriteLine(new TraceMessage("LABEL DATA RESPONSE: " + cartonID + "; " + statusCode.ToString(), App.EventLogName, LogLevel.Information, "PandaSvc"));
                //    if(this.LabelDataRequestComplete != null) {
                //        PandaDS _ds = new PandaDS();
                //        _ds.CartonTable.AddCartonTableRow(cartonID,(inputs.Length>0?inputs[0]:""),(inputs.Length>1?inputs[1]:""),(inputs.Length>2?inputs[2]:""),(inputs.Length>3?inputs[3]:""),(inputs.Length>4?inputs[4]:""),(inputs.Length>5?inputs[5]:""),weight,statusCode,zpl,"",(aex!=null?aex.Message:""),"");
                //        this.LabelDataRequestComplete(this,new PandaLabelDataEventArgs(_ds.CartonTable[0]));
                //    }
            }
            return(ds);
        }