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:
Bitmap
to use AsciiFormatter
instead of BinaryFormatter
? since bitmap is a private field of AMessage
class, I cannot access it even if I directly derive a new custom class from AMessage
. And the constructor uses BinaryFormatter
by default. Currently, I have modified Bitmap.cs parameterless constructor to use AsciiFormatter
. AsciiFormatter
by default. But I'd like it to use BcdFormatter
. I have Modified this part to use BcdFormatter
by default in VariableLengthFormatter.Fields
section. Right now, I have to make Template
property public and use the following snippet:
for (var i = 2; i 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.
I have just made changes to the project to allow this. As of version 0.5.0 (Update your NuGet package)
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)
{
}
}
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);
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]