Ejemplo n.º 1
0
        /// <summary>
        /// Creates a response for the specified request, by creating a new
        /// message with a message type of the original request type plus 16.
        /// If there is a template for the resulting type, its values are copied
        /// onto the new message; after that, all the values from the original
        /// request that are not already in the response are copied to it.
        /// </summary>
        /// <param name="request">An ISO8583 request.</param>
        /// <returns>A new ISO8583 message with the corresponding response
        /// type for the request and with values already copied from its
        /// template (if any) and the request.</returns>
        public IsoMessage CreateResponse(IsoMessage request)
        {
            IsoMessage resp = new IsoMessage(_isoHeaders[request.Type + 16])
            {
                Type = request.Type + 16,
                Etx  = _etx
            };

            IsoMessage templ = _typeTemplates[resp.Type];

            if (templ != null)
            {
                for (int i = 2; i < 128; i++)
                {
                    if (templ.HasField(i))
                    {
                        resp.SetField(i, (IsoValue)templ.GetField(i).Clone());
                    }
                }
            }
            for (int i = 2; i < 128; i++)
            {
                if (request.HasField(i))
                {
                    resp.SetField(i, (IsoValue)request.GetField(i).Clone());
                }
            }
            return(resp);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new message of the given type. If there is a template
        /// for the message type, then it is used to set all the values in the
        /// new message (the values will be copied from the original messages,
        /// not referred to directly, to avoid affecting the templates if a value
        /// in a message created this way is modified). If the factory has an
        /// ITraceGenerator set, it uses it to assign a new trace number as a
        /// NUMERIC value of length 6 in field 11; if AssignDate is true,
        /// then the current DateTime is stored in field 7 as a DATE10 type.
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public IsoMessage NewMessage(int type)
        {
            IsoMessage m = new IsoMessage(_isoHeaders[type])
            {
                Type = type,
                Etx  = Etx
            };

            IsoMessage templ = _typeTemplates[type];

            if (templ != null)
            {
                for (int i = 2; i < 128; i++)
                {
                    if (templ.HasField(i))
                    {
                        m.SetField(i, (IsoValue)templ.GetField(i).Clone());
                    }
                }
            }

            if (TraceGenerator != null)
            {
                m.SetValue(11, TraceGenerator.NextTrace(), IsoType.NUMERIC, 6);
            }
            if (AssignDate)
            {
                m.SetValue(7, DateTime.Now, IsoType.DATE10, 10);
            }
            return(m);
        }