Exemplo n.º 1
0
 private void NewLog(string text, DateTime timeStamp, int index, CENTIROTRANS transaction)
 {
     if (_useLogTable)
     {
         _carrierCompliantQueue.NewLog(transaction != null ? (double?)transaction.REPORTJOBID : null, transaction != null ? transaction.REPORTTYPE : null, text, timeStamp, index, transaction != null ? (double?)transaction.REPORT.Length : null, _adapterId);
     }
 }
Exemplo n.º 2
0
        private CENTIROTRANS FindMessageToSend()
        {
            CENTIROTRANS transaction = null;

            double?tmpCCJOBID = null;
            string tmpCCTYPE  = null;
            string tmpCCMSG   = null;
            string tmpWHID    = null;

            _carrierCompliantQueue.GetNextMessage(_adapterId, ref tmpCCJOBID, ref tmpCCTYPE, ref tmpCCMSG, ref tmpWHID);


            if (tmpCCJOBID != null)
            {
                transaction = new CENTIROTRANS();

                transaction.REPORTJOBID = tmpCCJOBID.Value;

                if (string.IsNullOrEmpty(tmpCCTYPE))
                {
                    transaction.REPORTTYPE = "";
                }
                else
                {
                    transaction.REPORTTYPE = tmpCCTYPE;
                }

                if (string.IsNullOrEmpty(tmpCCMSG))
                {
                    transaction.REPORT = "";
                }
                else
                {
                    transaction.REPORT = tmpCCMSG;
                }

                if (string.IsNullOrEmpty(tmpWHID))
                {
                    transaction.WHID = "";
                }
                else
                {
                    transaction.WHID = tmpWHID;
                }

                Tracing.TraceEvent(TraceEventType.Verbose, 0,
                                   string.Format("Found job {0} - {1}", transaction.REPORTJOBID, transaction.REPORTTYPE));
            }


            return(transaction);
        }
Exemplo n.º 3
0
        protected override void ExecuteProcedure(JobArgumentCollection args)
        {
            // Check parameters
            _userName    = args["userName"];
            _password    = args["password"];
            _useLogTable = Convert.ToBoolean(args["useLogTable"]);

            _logDirectory = args["logDirectory"];
            _printerType  = args["printerType"];

            if (!string.IsNullOrEmpty(_printerType))
            {
                _fetchEachPrinterType = false;
            }

            string dumpXmlValue = args["dumpXml"];

            if (!string.IsNullOrEmpty(dumpXmlValue))
            {
                _isXmlDumpEnabled = (dumpXmlValue == "true");
            }

            _documentType = args["documentType"];

            if (string.IsNullOrEmpty(_documentType))
            {
                _documentType = "Rdf";
            }

            Tracing.TraceEvent(TraceEventType.Verbose, 0, "Start");

            _getMessages = true;
            _stopJob     = false;

            while (_getMessages && !_stopJob)
            {
                DateTime startDT = DateTime.Now;

                long start = DateTime.Now.Ticks;
                _getMessages = false;

                MessageId = Convert.ToString(DateTime.Now.Ticks);

                DateTime startDBDT = DateTime.Now;

                StartTransaction();

                CENTIROTRANS transaction = FindMessageToSend();

                Commit();

                DateTime doneDBDT = DateTime.Now;


                if (transaction != null)
                {
                    string error = "";

                    try
                    {
                        //Write log table
                        NewLog("Start message loop", startDT, 0, transaction);

                        //Write log table
                        NewLog("Start fetching message from database", startDBDT, 10, transaction);

                        //Write log table
                        NewLog("Done fetching message from database", doneDBDT, 20, transaction);

                        _getMessages = true;

                        if (_isXmlDumpEnabled)
                        {
                            //Write log table
                            NewLog("Start XML dump to file", DateTime.Now, 30, transaction);

                            new XMLHelper().DumpToFile(transaction.REPORT, LogFileName("FromPLQueue_type_" + transaction.REPORTTYPE));

                            //Write log table
                            NewLog("Done XML dump to file", DateTime.Now, 40, transaction);
                        }

                        //Write log table
                        NewLog("Start logging message", DateTime.Now, 50, transaction);

                        Tracing.TraceEvent(TraceEventType.Verbose, 0,
                                           string.Format("Found REPORTJOBID {0} REPORTTYPE {1}", transaction.REPORTJOBID, transaction.REPORTTYPE));

                        //Write log table
                        NewLog("Done logging message", DateTime.Now, 60, transaction);

                        StartTransaction();

                        //Write log table
                        NewLog("Start Centiro send and receive process", DateTime.Now, 70, transaction);

                        switch (transaction.REPORTTYPE)
                        {
                        case "UP":      /* Update Parcel */
                            UpdateParcel(transaction.REPORT);
                            break;

                        case "RP":      /* Remove Parcel */
                            RemoveParcel(transaction.REPORT);
                            break;

                        case "PP":      /* Print Parcel */
                            PrintParcel(transaction.REPORT, transaction.WHID);
                            break;

                        case "US":      /* Update Shipment */
                            UpdateShipment(transaction.REPORT);
                            break;

                        case "PS":      /* Print Shipment */
                            PrintShipment(transaction.REPORT, transaction.WHID);
                            break;

                        case "PD":      /* Print Departure */
                            PrintDeparture(transaction.REPORT);
                            break;

                        case "CD":      /* Close Departure */
                            CloseDeparture(transaction.REPORT);
                            break;

                        default:
                            Tracing.TraceEvent(TraceEventType.Verbose, 0,
                                               string.Format("REPORTTYPE {0} not supported", transaction.REPORTTYPE));
                            break;
                        }

                        //Write log table
                        NewLog("Done Centiro send and receive process", DateTime.Now, 80, transaction);

                        //Write log table
                        NewLog("Start enqueueing documents in print queue", DateTime.Now, 90, transaction);

                        EnqueueDocuments(transaction.WHID);

                        //Write log table
                        NewLog("Done enqueueing documents in print queue", DateTime.Now, 100, transaction);
                    }
                    catch (Exception ex)
                    {
                        Rollback();

                        //Write log table
                        NewLog("Start exception handler", DateTime.Now, 110, transaction);

                        Tracing.TraceEvent(TraceEventType.Error, 0, string.Format("Exception while printing REPORTJOBID {0} REPORTTYPE {1}", transaction.REPORTJOBID, transaction.REPORTTYPE));
                        Tracing.TraceData(TraceEventType.Error, 0, ex);

                        error = ex.Message;

                        StartTransaction();

                        //Write log table
                        NewLog("Done exception handler", DateTime.Now, 120, transaction);
                    }

                    string almid = "";

                    if (string.IsNullOrEmpty(error))
                    {
                        //Write log table
                        NewLog("Start updating status processed and logging status change", DateTime.Now, 130, transaction);

                        Tracing.TraceEvent(TraceEventType.Verbose, 0, String.Format("No error reported for REPORTJOBID {0} REPORTTYPE {1}", transaction.REPORTJOBID, transaction.REPORTTYPE));
                        _carrierCompliantQueue.ModifyProcessed(transaction.REPORTJOBID, MessageId, ref almid);

                        //Write log table
                        NewLog("Done updating status processed and logging status change", DateTime.Now, 140, transaction);
                    }
                    else
                    {
                        //Write log table
                        NewLog("Start updating status error and logging status change", DateTime.Now, 150, transaction);

                        Tracing.TraceEvent(TraceEventType.Error, 0, String.Format("Error reported for REPORTJOBID {0} REPORTTYPE {1}", transaction.REPORTJOBID, transaction.REPORTTYPE));

                        _carrierCompliantQueue.ModifyError(transaction.REPORTJOBID, error, MessageId, null, ref almid);

                        //Write log table
                        NewLog("Done updating status error and logging status change", DateTime.Now, 160, transaction);
                    }

                    if (!string.IsNullOrEmpty(almid))
                    {
                        //Write log table
                        NewLog("Start logging almid", DateTime.Now, 170, transaction);

                        Tracing.TraceEvent(TraceEventType.Error, 0, String.Format("Error while updating transaction status. Almid={0}. REPORTJOBID {1} REPORTTYPE {2}", almid, transaction.REPORTJOBID, transaction.REPORTTYPE));

                        //Write log table
                        NewLog("Done logging almid", DateTime.Now, 180, transaction);
                    }

                    Commit();

                    //Write log table
                    NewLog("Done processing message", DateTime.Now, 190, transaction);
                }

                long     stop = DateTime.Now.Ticks;
                TimeSpan ts   = new TimeSpan(stop - start);

                Tracing.TraceEvent(TraceEventType.Verbose, 0, String.Format("Stop (used {0}s)", ts.TotalSeconds.ToString("0.00")));
            }
            ;
        }