示例#1
0
 static CheDaoInterface create(LocalChePackage p)
 {
     Trace.WriteLineIf(Program.trace_sw.TraceVerbose, String.Format("incomming package {0:d} {1:s}", p.msg_type, p.rawXML), "message");
     if (p.msg_type == CheDaoInterface.data_validation)
     {
         Invoice_Request_Count++;
         return(CheRequest.create(p.rawXML, p.time_ticks));
     }
     if (p.msg_type == CheDaoInterface.scan_print || p.msg_type == CheDaoInterface.manual_print)
     {
         Print_Request_Count++;
         return(ChePrintRequest.create(p.msg_type, p.rawXML, p.time_ticks));
     }
     if (p.msg_type == CheDaoInterface.print_confirm)
     {
         Print_Act_Count++;
         return(ChePActionRequest.create(p.rawXML, p.time_ticks));//it is just a string
     }
     if (p.msg_type == CheDaoInterface.delete_cmd)
     {
         Print_Act_Count++;
         return(CheDeleteActionRequest.create(p.rawXML, p.time_ticks));//it is just a string
     }
     return(new SimpleRequest(p.msg_type));
 }
示例#2
0
        public static ChePrintRequest create(int msg_type, string str, long create_time)
        {
            XmlDocument   doc           = new XmlDocument();
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(ChePrintRequest));

            try
            {
                ChePrintRequest o = (ChePrintRequest)xmlSerializer.Deserialize(new StringReader(str));
                o.message_type = msg_type;
                o.create_time  = create_time;
                return(o);
            }
            catch (Exception e)
            {
                Trace.WriteLineIf(Program.trace_sw.TraceError, "decode XML error " + e.ToString());
                return(null);
            }
        }
示例#3
0
        /**
         *  make sure the function is re-entriable.
         **/
        static CheDaoInterface _HandlePackage(LocalChePackage p)
        {
            CheDaoInterface msg = create(p);

            if (msg != null)
            {
                switch (msg.message_type)
                {
                case CheDaoInterface.data_validation:
                    lock (mPendingList)
                    {
                        CheRequest item = (CheRequest)msg;
                        try
                        {
                            //put to pending list
                            mPendingList.Add(item.Order_Number, item);
                        }
                        catch (Exception e)
                        {
                            Trace.WriteLineIf(Program.trace_sw.TraceError, "Insert CheRequest Failed, maybe the key already exist " + e.Message, "error");
                            msg.Result = 2;     //2:其它不符;
                        }
                    }
                    break;

                case CheDaoInterface.clean_cmd:    //delete the item one hour later
                    int bypass_counter = 0;
                    lock (mPendingList)
                    {
                        Dictionary <String, CheRequest> newPendingList = new Dictionary <String, CheRequest>();
                        foreach (String str in mPendingList.Keys)
                        {
                            CheRequest c_item = mPendingList[str];
                            DateTime   c_date = new DateTime(c_item.create_time);
                            if (c_date.AddMinutes(AppConfig.GetLifeTimeOfRec()) > DateTime.Now)
                            {
                                newPendingList.Add(str, c_item);
                            }
                            else
                            {
                                bypass_counter++;
                            }
                        }
                        mPendingList = newPendingList;
                    }
                    Trace.WriteLineIf(Program.trace_sw.TraceVerbose, "clean up the internal cache and bypass " + bypass_counter.ToString());
                    break;

                case CheDaoInterface.scan_print:
                case CheDaoInterface.manual_print:
                    lock (mPendingList)
                    {
                        ChePrintRequest p_item = (ChePrintRequest)msg;
                        if (mPendingList.ContainsKey(p_item.Order_Number))
                        {
                            CheRequest w_item = mPendingList[p_item.Order_Number];
                            mPendingList.Remove(p_item.Order_Number);
                            Program.NewRequest(w_item);     // to be print
                        }
                        else
                        {
                            Trace.WriteLineIf(Program.trace_sw.TraceError, "invalide print request, no key exist", "error");
                            msg.Result = 2;    //2:已开票;
                        }
                    }
                    break;

                case CheDaoInterface.print_confirm:
                    Program.NewRequest(msg);     //internal message
                    break;

                case CheDaoInterface.delete_cmd:
                    Program.NewRequest(msg);     //internal message
                    break;

                default:
                    msg = null;
                    break;
                }
                try
                {
                    lock (bk_stream)
                    {
                        if (msg != null)
                        {
                            p.save(bk_stream);              // just save the valid msg
                        }
                    }
                }
                catch (Exception e)
                {
                    save_error_count++;
                    Trace.WriteLineIf(Program.trace_sw.TraceError, "Write backup stream failed " + e.Message, "error");
                }
            }
            return(msg);
        }
示例#4
0
        private byte[] GenInvoicePackage()
        {
            CheRequest req = new CheRequest();
            String order_no = "RND"+ new Random().Next().ToString() ;
            req.Order_Number = order_no;
            req.Print_Number = "PR" + order_no;
            req.Product_Code = "94";
            req.Product_Price = "4.5";
            req.Product_Number = "10";
            req.Customer_Text = "中国石化";
            req.Amount = "100";
            req.LicenseNumber = "粤AXX434";
            req.Time = DateTime.Now.ToString();
            req.Pump_Number = "3";
            ChePrintRequest p_req = new ChePrintRequest();
            p_req.Order_Number = order_no;
            p_req.Print_Type = "1";

            byte[] res = GenerateBytes(1, req);
            byte[] rsp = GenerateBytes(2, p_req);
            InvoiceList.Add(rsp);
            return res;
        }