扩展/修改 OpenIso8583.Net

发布于 2025-01-05 12:01:11 字数 992 浏览 4 评论 0原文

我正在使用出色的 OpenIso8583Net 来发送/接收 ISO 消息。但是,由于每个组织都有自己的定义和自定义,因此我希望能够在尽可能少地接触项目源的情况下自定义格式,以便能够更轻松地升级到新版本。
因此,这是我现在面临的三个自定义:

  • 如何使 Bitmap 使用 AsciiFormatter 而不是 BinaryFormatter?由于位图是AMessage类的私有字段,即使我直接从AMessage派生一个新的自定义类,我也无法访问它。构造函数默认使用BinaryFormatter。目前,我已修改 Bitmap.cs 无参数构造函数以使用 AsciiFormatter
  • 同样的情况也适用于可变长度格式化程序。它默认使用AsciiFormatter。但我希望它使用 BcdFormatter。我已修改此部分以在 VariableLengthFormatter 中默认使用 BcdFormatter
    如果有人向我展示一种通过扩展而不是修改来处理这些自定义的更好方法,我将不胜感激。
  • 假设我想显示日志文件中的字段。一个例子是我在 Fields 部分中的通过加密数据生成 MAC 中显示的内容。现在,我必须将 Template 属性公开并使用以下代码片段: for (var i = 2; i

如何在不公开 Template 的情况下访问字段?我想访问主程序中字段的 Display 方法以进行日志记录。

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 make 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.
  • Same story goes for variable length formatter. It uses AsciiFormatter by default. But I'd like it to use BcdFormatter. I have Modified this part to use BcdFormatter by default in VariableLengthFormatter.
    I'd appreciate if anyone shows me a better way to handle these customizations by extending, not modifying.
  • Suppose I want to display fields in a log file. An example would be what I have displayed at Generating MAC by encrypting data in the 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

姜生凉生 2025-01-12 12:01:11

我刚刚对项目进行了更改以允许这样做。从版本 0.5.0 开始(更新您的 NuGet 包)

位图格式化程序

您可以在消息类的模板中设置位图格式化程序。以下是一些示例代码:

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)
    {

    }
}

设置字段的长度格式化程序

static AsciiIso() 方法中,如果以这种方式修改,您将更改字段 2 以使用 BCD 长度格式化程序:

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

日志文件

到在日志文件中显示消息,使用消息类上的 .ToString() 方法,例如

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

给出:

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

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]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文