Esempio n. 1
0
        public override void WriteToStream(Stream s)
        {
            // create the message body in a buffer
            MemoryStream ms = new MemoryStream();
            WbxmlWriter w = new WbxmlWriter(ms, AppConfig.TerminalEncoding);
            w.WriteHeader();
            w.WriteElement(tempRootElement);

            byte[] buf = ms.ToArray();
            int len = buf.Length;

            log.Debug("sending message: length: " + len + "\r\n" + HexHelper.ToHexDump(buf));

            // write message into the TCP/IP stream (length + body + MAC if needed)
            BinaryWriter bw = new BinaryWriter(s);
            bw.Write(BinaryHelper.SwapByteOrder(len));
            bw.Write(buf);
        }
Esempio n. 2
0
        public virtual void WriteToStream(Stream s)
        {
            // create the message body in a buffer
            MemoryStream ms = new MemoryStream();
            WbxmlWriter w = new WbxmlWriter(ms, AppConfig.TerminalEncoding);
            w.WriteHeader();
            w.WriteElement(type, flags);
            if ((flags & WbxmlWriter.ElementFlags.HasAttributes) != 0)
            {
                WriteAttributes(w);
                w.WriteTerminator();
            }
            if ((flags & WbxmlWriter.ElementFlags.HasChildren) != 0)
            {
                WriteChildElements(w);
                w.WriteTerminator();
            }

            byte[] buf = ms.ToArray();
            int len = buf.Length;

            // calculate MAC if needed
            if (authType > 0)
            {
                //mac = CalculateMac(authType, serialNo, sapNo, imsi, imei, buf, terminalId);
            }
            log.Debug("sending message: length: " + len + "\r\n" +
                HexHelper.ToHexDump(buf) +
                ((authType > 0) ? "\r\n" + "MAC: " + HexHelper.ToHexString(mac) : ""));

            // write message into the TCP/IP stream (length + body + MAC if needed)
            BinaryWriter bw = new BinaryWriter(s);
            bw.Write(BinaryHelper.SwapByteOrder(len));
            bw.Write(buf);
            if (authType > 0)
            {
                bw.Write(mac);
            }
        }