コード例 #1
0
        internal static Iso8583Element Inflate(DataElementId id, DataElementType type, string description, int length, MessageReader mr)
        {
            Iso8583Element element = new Iso8583Element {
                Id          = id,
                Type        = type,
                Description = description,
                Length      = length
            };

            switch (type)
            {
            case DataElementType.LVAR:
            case DataElementType.LLVAR:
            case DataElementType.LLLVAR:
                string lengthStr    = mr.ReadString(type.Equals(DataElementType.LVAR) ? 1 : type.Equals(DataElementType.LLVAR) ? 2 : 3);
                int    actualLength = int.Parse(lengthStr);
                element.Buffer = mr.ReadBytes(actualLength);
                break;

            default:
                element.Buffer = mr.ReadBytes(length);
                break;
            }
            return(element);
        }
コード例 #2
0
        internal Iso8583Element CreateElement(DataElementId id, byte[] buffer)
        {
            DataElementType type        = elementTypes[id];
            string          description = elementDescriptions[id];
            int             length      = elementLengths[id];

            return(Iso8583Element.Inflate(id, type, description, length, buffer));
        }
コード例 #3
0
 public byte[] GetByteArray(DataElementId id)
 {
     if (elements.ContainsKey(id))
     {
         Iso8583Element element = elements[id];
         return(element.Buffer);
     }
     return(null);
 }
コード例 #4
0
 public string GetString(DataElementId id)
 {
     if (elements.ContainsKey(id))
     {
         Iso8583Element element = elements[id];
         return(Encoding.ASCII.GetString(element.Buffer));
     }
     return(null);
 }
コード例 #5
0
 public NetworkMessage Set(DataElementId id, byte[] buffer)
 {
     if (buffer != null)
     {
         Iso8583Element element = Factory.CreateElement(id, buffer);
         elements[id] = element;
     }
     return(this);
 }
コード例 #6
0
 public decimal GetAmount(DataElementId id)
 {
     if (elements.ContainsKey(id))
     {
         Iso8583Element element = elements[id];
         return(StringUtils.ToAmount(Encoding.ASCII.GetString(element.Buffer)));
     }
     return(0);
 }
コード例 #7
0
 public DE48_AdministrativelyDirectedTaskCode GetByteConstant(DataElementId id)
 {
     if (elements.ContainsKey(id))
     {
         Iso8583Element element = elements[id];
         return((DE48_AdministrativelyDirectedTaskCode)(Object)(element.Buffer[0]));
     }
     return(default(DE48_AdministrativelyDirectedTaskCode));
 }
コード例 #8
0
 public TResult GetDataElement <TResult>(DataElementId id) where TResult : IDataElement <TResult>
 {
     if (elements.ContainsKey(id))
     {
         Iso8583Element element = elements[id];
         return(element.GetConcrete <TResult>());
     }
     return(default(TResult));
 }
コード例 #9
0
        public new string ToString()
        {
            StringBuilder sb = new StringBuilder();

            // put the MTI
            if (!string.IsNullOrEmpty(MessageTypeIndicator))
            {
                sb.Append(string.Format("MTI: {0}\r\n", MessageTypeIndicator));
            }

            // deal with the bitmaps
            GenerateBitmaps();
            sb.Append(string.Format("P_BITMAP: {0}\r\n", Bitmap.ToHexString()));

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

            do
            {
                Iso8583Element element = elements[currentElement];
                if (currentElement.Equals(DataElementId.DE_001))
                {
                    sb.Append(string.Format("S_BITMAP: {0}\r\n", secondaryBitmap.ToHexString()));
                }
                else
                {
                    // special handling for DE 55
                    if (element.Id.Equals(DataElementId.DE_055))
                    {
                        byte[] buffer = element.Buffer;
                        sb.Append(string.Format("{0}: {1}{2}\r\n", element.Id, StringUtils.PadLeft(buffer.Length, 3, '0'), StringUtils.HexFromBytes(buffer)));
                    }
                    else
                    {
                        sb.Append(string.Format("{0}: {1}\r\n", element.Id, Encoding.UTF8.GetString(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];
                    sb.Append(string.Format("{0}: {1}\r\n", element.Id, Encoding.ASCII.GetString(element.GetSendBuffer())));

                    currentElement = secondaryBitmap.GetNextDataElement();
                }
            }

            return(sb.ToString());
        }
コード例 #10
0
        internal static Iso8583Element Inflate(DataElementId id, DataElementType type, string description, int length, byte[] buffer)
        {
            Iso8583Element element = new Iso8583Element {
                Id          = id,
                Type        = type,
                Description = description,
                Length      = length,
                Buffer      = buffer
            };

            return(element);
        }
コード例 #11
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());
        }
コード例 #12
0
        public DE48_CardType GetStringConstant(DataElementId id)
        {
            if (elements.ContainsKey(id))
            {
                Iso8583Element element = elements[id];
                string         value   = Encoding.ASCII.GetString(element.Buffer);

                //DE48_CardType rvalue = (DE48_CardType)Enum.Parse(typeof(DE48_CardType),StringUtils.Trim(value));
                DE48_CardType rvalue = EnumConverter.FromMapping <DE48_CardType>(Target.NWS, StringUtils.Trim(value));
                if (rvalue == default(DE48_CardType))
                {
                    rvalue = EnumConverter.FromMapping <DE48_CardType>(Target.NWS, value);
                }
                return(rvalue);
            }
            return(default(DE48_CardType));
        }