Esempio n. 1
0
        public string ParseByRead(byte[] bytes)
        {
            Stopwatch sw = new Stopwatch();
            sw.Start();
            using (MemoryStream ms = new MemoryStream(bytes))
            using (BinaryReader br = new BinaryReader(ms))
            {
                HeaderMessage headerMessage = new HeaderMessage();
                headerMessage.blberProtocol = br.ReadByte();
                headerMessage.uTermId = br.ReadUInt32();
                headerMessage.MsgType = br.ReadByte();
                headerMessage.uCRC = br.ReadUInt16();

                SpyMessage spyMessage = new SpyMessage();
                spyMessage.HeaderMsg = headerMessage;
                spyMessage.szTime = Encoding.ASCII.GetString(br.ReadBytes(9));
                spyMessage.nEmployeeId = br.ReadUInt32();
                spyMessage.szEmployeeName = Encoding.ASCII.GetString(br.ReadBytes(40));
                spyMessage.nManagerId = br.ReadUInt32();
                spyMessage.szManagerName = Encoding.ASCII.GetString(br.ReadBytes(40));
                spyMessage.nTableId = br.ReadUInt32();
                spyMessage.nCheckId = br.ReadUInt32();
                spyMessage.nTransactionType = br.ReadInt32();
                spyMessage.szDescription = Encoding.ASCII.GetString(br.ReadBytes(40));
                //byte[] amountBytes = br.ReadBytes(8);
                //spyMessage.dAmount = BitConverter.ToDouble(amountBytes, 0);
                spyMessage.dAmount = br.ReadDouble();
                spyMessage.nQuantity = br.ReadInt16();

                sw.Stop();
                //Logger.Log("PARSE BY READ (" + sw.ElapsedTicks + ")");
                return getSpyMessageSummary(spyMessage).Replace("\0", "");
            }
        }
Esempio n. 2
0
        public string ParseByMarshal(byte[] bytes)
        {
            Stopwatch sw = new Stopwatch();
            sw.Start();

            SpyMessage spyMessage = new SpyMessage();

            int size = Marshal.SizeOf(spyMessage);
            IntPtr ptr = Marshal.AllocHGlobal(size);
            Marshal.Copy(bytes, 0, ptr, size);
            spyMessage = (SpyMessage)Marshal.PtrToStructure(ptr, spyMessage.GetType());
            Marshal.FreeHGlobal(ptr);

            sw.Stop();

            Logger.Log("PARSE BY MARSHAL (" + sw.ElapsedTicks + ")");
            return getSpyMessageSummary(spyMessage);
        }
Esempio n. 3
0
        private string getSpyMessageSummary(SpyMessage spyMessage)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("Protocol: " + spyMessage.HeaderMsg.blberProtocol);
            sb.AppendLine("Term ID: " + spyMessage.HeaderMsg.uTermId);
            sb.AppendLine("Message Type: " + spyMessage.HeaderMsg.MsgType);
            sb.AppendLine("UCRC: " + spyMessage.HeaderMsg.uCRC);

            sb.AppendLine("Time: " + spyMessage.szTime);
            sb.AppendLine("Employee ID: " + spyMessage.nEmployeeId);
            sb.AppendLine("Employee: " + spyMessage.szEmployeeName);
            sb.AppendLine("Manager ID: " + spyMessage.nManagerId);
            sb.AppendLine("Manager: " + spyMessage.szManagerName);
            sb.AppendLine("Table ID: " + spyMessage.nTableId);
            sb.AppendLine("Check ID: " + spyMessage.nCheckId);
            sb.AppendLine("Transaction Type: " + getAlohaType(spyMessage.nTransactionType));
            sb.AppendLine("Description: " + spyMessage.szDescription);
            sb.AppendLine("Amount: " + spyMessage.dAmount);
            sb.AppendLine("Quantity: " + spyMessage.nQuantity);
            sb.AppendLine();

            return sb.ToString();
        }