예제 #1
0
        /// <summary>
        /// Builds Byte[] from Instance of Message
        /// </summary>
        /// <typeparam name="TMessage">TMessage class, a derived class of BaseMessage class</typeparam>
        /// <param name="message">message instance</param>
        /// <param name="MTI">MTI Response value</param>
        /// <param name="notIncludeFields">whether the BitMap will Contain Fields without values</param>
        /// <returns>byte array Iso Message</returns>
        public byte[] Build <TMessage>(TMessage message, string MTI, params IsoFields[] notIncludeFields) where TMessage : BaseMessage, new()
        {
            IEnumerable <int> orderedFieldPositions = message.MessagePropsIsoFieldAttributes.Select(c => (int)c.Value.Position);

            IsoFieldAttribute mtiIsoField = message.GetIsoFieldByPropName(nameof(message.MTI));
            var mtiBytes = mtiIsoField.BuildFieldValue(MTI);

            var messageBytes = new List <byte>(mtiBytes);

            IEnumerable <int> fieldsForBitMap = orderedFieldPositions.Where(pos => !notIncludeFields.Contains((IsoFields)pos));

            messageBytes.AddRange(BuildBitMap(message, fieldsForBitMap));

            IEnumerable <int> fieldsToBuild = fieldsForBitMap.Where(pos => pos != (int)IsoFields.F1 && pos != (int)IsoFields.BitMap && pos != (int)IsoFields.MTI);

            BuildFields(fieldsToBuild, message, ref messageBytes);
            return(messageBytes.ToArray());
        }
예제 #2
0
        /// <summary>
        /// Builds BitMap value of Message to Send
        /// </summary>
        /// <typeparam name="TMessage">TMessage class, a derived class of BaseMessage class</typeparam>
        /// <param name="message">message instance</param>
        /// <param name="orderedFields">ordered fields positions</param>
        /// <returns>byte array bitMap value</returns>
        private byte[] BuildBitMap <TMessage>(TMessage message, IEnumerable <int> orderedFields) where TMessage : BaseMessage, new()
        {
            var secondBitRequired            = orderedFields.Any(pos => pos > 65 && pos < 128);
            IsoFieldAttribute bitMapIsoField = message.GetIsoFieldByPropName(nameof(BaseMessage.BitMap));

            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(bitMapIsoField.BuildFieldValue(bitMap));
        }