customizationiso8583openiso8583.net

Extending/Modifying OpenIso8583.Net


I'm using the excellent OpenIso8583Net to send/receive ISO messages. However, since every organization has its own definition and customization, I want to be able to customoize the format with as little touch to the projects' source as possible to be able to upgrade to new versions more easily.
So here are three customizations I am facing right now:

How can I access the fields without making the Template public? I want to access the Display method of fields in my main program for logging purposes.


Solution

  • I have just made changes to the project to allow this. As of version 0.5.0 (Update your NuGet package)

    Bitmap Formatter

    You can set the bitmap formatter in the Template for your message class. Here is some sample code:

    public class AsciiIsoMsg : Iso8583
    {
        // First you need to customise the template
        // The message 
        private static readonly Template template;
    
        static AsciiIsoMsg()
        {
            // Get the default template for the Iso8583 class
            template = GetDefaultIso8583Template();
            // change the bitmap formatter
            template.BitmapFormatter = new AsciiFormatter();
        }
    
        // override the base class using the template and you will be using the bitmap formatter
        public AsciiIsoMsg():base(template)
        {
    
        }
    }
    

    Set Length Formatter of a field

    In the static AsciiIso() method, if you modify in this manner, you'll change field 2 to use a BCD length formatter:

    // Set field 2 to use BCD formatter
    template[2] = FieldDescriptor.BcdVar(2, 19, Formatters.Bcd);
    

    Log File

    To display the message in the log file, use the .ToString() method on the message class, e.g.

    var msg = new AsciiIsoMsg();
    msg.MessageType = Iso8583.MsgType._0200_TRAN_REQ;
    msg[3] = "010000";
    Console.WriteLine(msg.ToString());
    

    Which gives:

    0200:
       [Fixed    n         6 0006] 003 [010000]