Example #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);
        }
        internal void SetDataElement(DataElementId element)
        {
            StringBuilder sb = new StringBuilder(binaryValue);

            sb[element.GetHashCode() - offset] = '1';
            binaryValue = sb.ToString();
        }
        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);
        }
Example #4
0
        /// <summary>
        /// commented the below 2 methods as it implemets the same as set method acceptiong string as 2nd param
        /// </summary>

        public NetworkMessage Set <T>(DataElementId id, IDataElement <T> element) where  T : class
        {
            if (element != null)
            {
                return(Set(id, element.ToByteArray()));
            }
            return(this);
        }
Example #5
0
 public NetworkMessage Set(DataElementId id, string value)
 {
     if (value != null)
     {
         return(Set(id, Encoding.UTF8.GetBytes(value)));
     }
     return(this);
 }
Example #6
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));
        }
Example #7
0
 public byte[] GetByteArray(DataElementId id)
 {
     if (elements.ContainsKey(id))
     {
         Iso8583Element element = elements[id];
         return(element.Buffer);
     }
     return(null);
 }
Example #8
0
 public string GetString(DataElementId id)
 {
     if (elements.ContainsKey(id))
     {
         Iso8583Element element = elements[id];
         return(Encoding.ASCII.GetString(element.Buffer));
     }
     return(null);
 }
Example #9
0
 public NetworkMessage Set(DataElementId id, byte[] buffer)
 {
     if (buffer != null)
     {
         Iso8583Element element = Factory.CreateElement(id, buffer);
         elements[id] = element;
     }
     return(this);
 }
Example #10
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));
 }
Example #11
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));
 }
Example #12
0
 public decimal GetAmount(DataElementId id)
 {
     if (elements.ContainsKey(id))
     {
         Iso8583Element element = elements[id];
         return(StringUtils.ToAmount(Encoding.ASCII.GetString(element.Buffer)));
     }
     return(0);
 }
Example #13
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());
        }
        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);
        }
Example #15
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());
        }
Example #16
0
        public DateTime?GetDate(DataElementId id, string formatter)
        {
            string value = GetString(id);

            if (!string.IsNullOrEmpty(value))
            {
                try {
                    return(DateTime.ParseExact(value, formatter, CultureInfo.InvariantCulture));
                }
                catch (Exception) {
                    return(null);
                }
            }
            return(null);
        }
Example #17
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));
        }
 public bool IsPresent(DataElementId element)
 {
     return(binaryValue[(int.Parse(EnumConverter.GetMapping(Target.NWS, element)) - offset)] == '1');
 }
Example #19
0
 private void AddElementMapping(DataElementId id, DataElementType type, string description, int length)
 {
     elementTypes[id]        = type;
     elementDescriptions[id] = description;
     elementLengths[id]      = length;
 }
Example #20
0
 public bool Has(DataElementId id)
 {
     return(elements.ContainsKey(id));
 }