/// <summary> /// Adds message bytes the rest of the Fields /// </summary> /// <param name="orderedFieldPositions">fields that need to be builded</param> /// <param name="message">message instance</param> /// <param name="messageBytes">message bytes as Ref</param> private void BuildFields(IEnumerable <int> orderedFieldPositions, IIsoMessage message, ref List <byte> messageBytes) { foreach (var fieldPosition in orderedFieldPositions) { IIsoFieldProperties fieldProperties = message.GetFieldByPosition(fieldPosition); if (fieldProperties != null) { var valueForMessage = fieldProperties.Value; _validator?.EnsureContent(fieldProperties); _validator?.EnsureLength(fieldProperties); if (fieldProperties is IsoField isoField && isoField.Tags != null) { IEnumerable <byte> customFieldBytes = BuildTagFields(isoField); messageBytes.AddRange(fieldProperties.BuildCustomFieldLentgh(customFieldBytes.Count().ToString())); messageBytes.AddRange(customFieldBytes); } else { messageBytes.AddRange(fieldProperties.BuildFieldValue(valueForMessage.ToString())); } } }
/// <summary> /// Builds BitMap value of Message to Send /// </summary> /// <param name="bitMapField">bitmap field properties</param> /// <param name="orderedFields">ordered fields positions</param> /// <returns>byte array bitMap value</returns> private byte[] BuildBitMap(IIsoFieldProperties bitMapField, IEnumerable <int> orderedFields) { var secondBitRequired = orderedFields.Any(pos => pos > 65 && pos < 128); char[] bitmapBinaryArray = null; if (secondBitRequired) { bitmapBinaryArray = new char[129]; bitmapBinaryArray[1] = '1'; } else { bitmapBinaryArray = new char[65]; bitmapBinaryArray[1] = '0'; } //Building BitMap for (var i = 2; i < bitmapBinaryArray.Length; i++) { if (orderedFields.Contains(i)) { bitmapBinaryArray[i] = '1'; } else { bitmapBinaryArray[i] = '0'; } } var bitmapString = new string(bitmapBinaryArray); var bitMap = Convert.ToInt64(bitmapString.Substring(1, 64), 2).ToString("X").PadLeft(16, '0'); if (secondBitRequired) { bitMap = bitMap + Convert.ToInt64(bitmapString.Substring(65, 64), 2).ToString("X").PadLeft(16, '0'); } return(bitMapField.BuildFieldValue(bitMap)); }