示例#1
0
        private static FieldParseInfo GetParser <T>(XmlElement f,
                                                    MessageFactory <T> mfact) where T : IsoMessage
        {
            var itype  = Enumm.Parse <IsoType>(f.GetAttribute("type"));
            var length = 0;

            if (f.GetAttribute("length").Length > 0)
            {
                length = int.Parse(f.GetAttribute("length"));
            }

            Debug.Assert(
                itype != null,
                "itype != null");

            var fpi = FieldParseInfo.GetInstance(
                itype.Value,
                length,
                mfact.Encoding);

            var subs = f.GetElementsByTagName("field");

            if (subs.Count <= 0)
            {
                return(fpi);
            }

            var compo = new CompositeField();

            for (var i = 0; i < subs.Count; i++)
            {
                var sf = (XmlElement)subs.Item(i);

                Debug.Assert(
                    sf != null,
                    "sf != null");

                if (sf.ParentNode == f)
                {
                    compo.AddParser(
                        GetParser(
                            sf,
                            mfact));
                }
            }

            fpi.Decoder = compo;

            return(fpi);
        }
示例#2
0
        public static FieldParseInfo GetInstance(IsoType t,
                                                 int len,
                                                 Encoding encoding)
        {
            FieldParseInfo fpi = null;

            switch (t)
            {
            case IsoType.ALPHA:
                fpi = new AlphaParseInfo(len);
                break;

            case IsoType.AMOUNT:
                fpi = new AmountParseInfo();
                break;

            case IsoType.BINARY:
                fpi = new BinaryParseInfo(len);
                break;

            case IsoType.DATE10:
                fpi = new Date10ParseInfo();
                break;

            case IsoType.DATE12:
                fpi = new Date12ParseInfo();
                break;

            case IsoType.DATE14:
                fpi = new Date14ParseInfo();
                break;

            case IsoType.DATE4:
                fpi = new Date4ParseInfo();
                break;

            case IsoType.DATE_EXP:
                fpi = new DateExpParseInfo();
                break;

            case IsoType.LLBIN:
                fpi = new LlbinParseInfo();
                break;

            case IsoType.LLLBIN:
                fpi = new LllbinParseInfo();
                break;

            case IsoType.LLLVAR:
                fpi = new LllvarParseInfo();
                break;

            case IsoType.LLVAR:
                fpi = new LlvarParseInfo();
                break;

            case IsoType.NUMERIC:
                fpi = new NumericParseInfo(len);
                break;

            case IsoType.TIME:
                fpi = new TimeParseInfo();
                break;

            case IsoType.LLLLVAR:
                fpi = new LlllvarParseInfo();
                break;

            case IsoType.LLLLBIN:
                fpi = new LlllbinParseInfo();
                break;
            }
            if (fpi == null)
            {
                throw new ArgumentException($"Cannot parse type {t}");
            }
            fpi.Encoding = encoding;
            return(fpi);
        }