Пример #1
0
        private static NetworkMessage ParseMessage(Iso8583Bitmap bitmap, MessageReader mr, Iso8583MessageType messageType)
        {
            NetworkMessage message = new NetworkMessage(messageType);

            message.Bitmap = bitmap;

            // initialize the factory
            message.Factory = Iso8583ElementFactory.GetConfiguredFactory(mr, messageType);

            // read the primary bitmap
            DataElementId currentElement = bitmap.GetNextDataElement();

            do
            {
                message.elements[currentElement] = message.Factory.CreateElement(currentElement);
                currentElement = bitmap.GetNextDataElement();
            }while (currentElement != 0);

            // check for secondary bitmap
            if (message.Has(DataElementId.DE_001))
            {
                byte[]        secondaryBuffer = message.GetByteArray(DataElementId.DE_001);
                Iso8583Bitmap secondaryMap    = new Iso8583Bitmap(secondaryBuffer, 64);

                currentElement = secondaryMap.GetNextDataElement();
                while (currentElement != 0)
                {
                    message.elements[currentElement] = message.Factory.CreateElement(currentElement);
                    currentElement = secondaryMap.GetNextDataElement();
                }
            }

            // return the document
            return(message);
        }
Пример #2
0
        public byte[] BuildMessage(bool addBitmapAsString)
        {
            MessageWriter mw = new MessageWriter();

            // put the MTI
            if (!string.IsNullOrEmpty(MessageTypeIndicator))
            {
                mw.AddRange(Encoding.UTF8.GetBytes(MessageTypeIndicator));
            }

            // deal with the bitmaps
            GenerateBitmaps();
            if (addBitmapAsString)
            {
                mw.AddRange(Encoding.UTF8.GetBytes(Bitmap.ToHexString()));
            }
            else
            {
                mw.AddRange(Bitmap.ToByteArray());
            }

            // primary bitmap
            DataElementId currentElement = Bitmap.GetNextDataElement();

            do
            {
                if (elements.ContainsKey(currentElement))
                {
                    Iso8583Element element = elements[currentElement];
                    mw.AddRange(element.GetSendBuffer());
                }
                currentElement = Bitmap.GetNextDataElement();
            }while (currentElement != 0);

            // secondary bitmap
            if (messageType.Equals(Iso8583MessageType.CompleteMessage))
            {
                currentElement = secondaryBitmap.GetNextDataElement();
                while (currentElement != 0)
                {
                    Iso8583Element element = elements[currentElement];
                    mw.AddRange(element.GetSendBuffer());

                    currentElement = secondaryBitmap.GetNextDataElement();
                }
            }

            return(mw.ToArray());
        }