【问题标题】:Extending/Modifying OpenIso8583.Net扩展/修改 OpenIso8583.Net
【发布时间】:2012-02-13 19:44:33
【问题描述】:

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

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

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

【问题讨论】:

    标签: customization iso8583 openiso8583.net


    【解决方案1】:

    我刚刚对项目进行了更改以允许这样做。从 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]
    

    【讨论】:

    • 刚刚注意到 FieldDescriptor 的 LengthFormatter 没有设置器。在您更新源之前,我已经手动添加了 setter。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-04
    • 2013-02-26
    • 1970-01-01
    • 2014-11-08
    • 2019-01-17
    相关资源
    最近更新 更多