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); }
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)); }
public byte[] GetByteArray(DataElementId id) { if (elements.ContainsKey(id)) { Iso8583Element element = elements[id]; return(element.Buffer); } return(null); }
public string GetString(DataElementId id) { if (elements.ContainsKey(id)) { Iso8583Element element = elements[id]; return(Encoding.ASCII.GetString(element.Buffer)); } return(null); }
public NetworkMessage Set(DataElementId id, byte[] buffer) { if (buffer != null) { Iso8583Element element = Factory.CreateElement(id, buffer); elements[id] = element; } return(this); }
public decimal GetAmount(DataElementId id) { if (elements.ContainsKey(id)) { Iso8583Element element = elements[id]; return(StringUtils.ToAmount(Encoding.ASCII.GetString(element.Buffer))); } return(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)); }
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)); }
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); }
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()); }
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)); }