Esempio n. 1
0
        public MessageContext Parse(string msg)
        {
            try
            {
                MessageContext msgContext = new MessageContext();
                // only 64 fields,No Second map
                msgContext.BitMap     = "0";
                msgContext.SrcMessage = msg;

                int    bitLength = 16;
                string bitMapHex = msgContext.SrcMessage.Substring(msgContext.Start, bitLength);
                msgContext.Start  = msgContext.Start + bitLength;
                msgContext.BitMap = this.BitMapWorker.GetBitMapBits(bitMapHex);

                for (int fno = 2; fno <= msgContext.BitMap.Length; fno++)
                {
                    if (msgContext.HasField(fno))
                    {
                        BitIndex bi      = this.Df61BitWorker[fno];
                        IPattern pattern = bi.PatternWorker;
                        msgContext.CurrentField.NextFuncNo = fno;
                        pattern.Parse(msgContext);
                    }
                }
                return(msgContext);
            }
            catch (Exception ex)
            {
                logger.LogError(ex.Message);
            }
            return(null);
        }
Esempio n. 2
0
 public IPattern GetPattern(BitIndex bitIndex)
 {
     lock (this.obj)
     {
         if (!this.dicPatterns.ContainsKey(bitIndex.Representation))
         {
             IPattern pattern = PatternSelector(bitIndex);
             this.dicPatterns.Add(bitIndex.Representation, pattern);
         }
     }
     return(this.dicPatterns[bitIndex.Representation]);
 }
Esempio n. 3
0
        private IPattern PatternSelector(BitIndex bitIndex)
        {
            string reSrc = bitIndex.Representation;

            string rePattern = @"^(?'TYPE'\S+?)\s+(?'LEN'\d+?)$";
            string type;
            int    length;
            int    variLen;

            Match m = Regex.Match(reSrc, rePattern);

            // fixed field
            if (m.Success)
            {
                type   = (m.Groups["TYPE"]).Value;
                length = Convert.ToInt32((m.Groups["LEN"]).Value, 10);
                if ("n".Equals(type) || "x+n".Equals(type))
                {
                    return(new FixedLengthNumPattern(logger, length));
                }
                else if ("b".Equals(type))
                {
                    //hex
                    return(new FixedLengthStringPattern(logger, length / 4));
                }
                else
                {
                    return(new FixedLengthStringPattern(logger, length));
                }
            }

            rePattern = @"^(?'TYPE'\S+?)\s+(?'VAR'\.+?)(?'LEN'\d+?)$";
            m         = Regex.Match(reSrc, rePattern);
            if (m.Success)
            {
                type    = (m.Groups["TYPE"]).Value;
                variLen = (m.Groups["VAR"].Value).Length;
                length  = Convert.ToInt32((m.Groups["LEN"]).Value, 10);
                return(new VariablePattern(logger, variLen, length));
            }

            rePattern = @"\s+(?'LEN'\d+?)$";
            m         = Regex.Match(reSrc, rePattern);
            if (m.Success)
            {
                length = Convert.ToInt32((m.Groups["LEN"]).Value, 10);
                return(new FixedLengthStringPattern(logger, length));
            }
            return(null);
        }
Esempio n. 4
0
        public MessageContext Build(string fromTo, string mti, string[] funcDatas)
        {
            try
            {
                MessageContext msgContextMain = new MessageContext();
                msgContextMain.FromTo = fromTo;
                msgContextMain.Mti    = mti;
                // BitMap, always has SecondMap in Common
                if (65 == funcDatas.Length)
                {
                    msgContextMain.BitMap = "0";
                }
                else
                {
                    msgContextMain.BitMap = "1";
                }

                string[] srcList = new string[funcDatas.Length];
                for (int i = 0; i < srcList.Length; i++)
                {
                    srcList[i] = funcDatas[i];
                }

                for (int fno = 2; fno < srcList.Length; fno++)
                {
                    if (!((null == srcList[fno]) || ("".Equals(srcList[fno]))))
                    {
                        BitIndex bi      = this.BitWorker[fno];
                        IPattern pattern = bi.PatternWorker;
                        msgContextMain.AddField(fno, srcList[fno]);
                        pattern.Build(msgContextMain);
                    }
                    else
                    {
                        msgContextMain.BitMap += "0";
                    }
                }
                msgContextMain.SrcMessage  = msgContextMain.FromTo + msgContextMain.Mti + this.BitMapWorker.GetBitMapHex(msgContextMain.BitMap) + msgContextMain.SrcMessage;
                msgContextMain.MessageSize = msgContextMain.SrcMessage.Length;

                return(msgContextMain);
            }
            catch (Exception ex)
            {
                logger.LogError(ex.Message);
            }
            return(null);
        }
Esempio n. 5
0
        public MessageContext Parse(string msg)
        {
            try
            {
                MessageContext msgContextMain = new MessageContext();
                if ((null != this.HasHeader) && ("Y".Equals(this.HasHeader)))
                {
                    this.parseHeader(msg, msgContextMain);
                }
                else
                {
                    msgContextMain.SrcMessage  = msg;
                    msgContextMain.MessageSize = msg.Length;
                }

                msgContextMain.Start  = 0;
                msgContextMain.FromTo = msgContextMain.SrcMessage.Substring(msgContextMain.Start, 8);
                msgContextMain.Start  = msgContextMain.Start + 8;

                msgContextMain.Mti   = msgContextMain.SrcMessage.Substring(msgContextMain.Start, 4);
                msgContextMain.Start = msgContextMain.Start + 4;

                bool   hasSecondMap = this.BitMapWorker.HasExtend(msgContextMain.SrcMessage.Substring(msgContextMain.Start, 2));
                int    bitLength    = hasSecondMap ? 32 : 16;
                string bitMapHex    = msgContextMain.SrcMessage.Substring(msgContextMain.Start, bitLength);
                msgContextMain.Start  = msgContextMain.Start + bitLength;
                msgContextMain.BitMap = this.BitMapWorker.GetBitMapBits(bitMapHex);

                for (int fno = 2; fno <= msgContextMain.BitMap.Length; fno++)
                {
                    if (msgContextMain.HasField(fno))
                    {
                        BitIndex bi      = this.BitWorker[fno];
                        IPattern pattern = bi.PatternWorker;
                        msgContextMain.CurrentField.NextFuncNo = fno;
                        pattern.Parse(msgContextMain);
                    }
                }
                return(msgContextMain);
            }
            catch (Exception ex)
            {
                logger.LogError(ex.Message);
            }
            return(null);
        }
Esempio n. 6
0
        public MessageContext Build(string fromTo, string mti, string[] funcDatas)
        {
            try
            {
                MessageContext msgContext = new MessageContext();
                // only 64 fields
                msgContext.BitMap = "0";
                string[] srcList = new string[this.Df61BitWorker.Length()];
                for (int i = 0; i < srcList.Length; i++)
                {
                    if (i < funcDatas.Length)
                    {
                        srcList[i] = funcDatas[i];
                    }
                    else
                    {
                        srcList[i] = "";
                    }
                }

                for (int fno = 2; fno < srcList.Length; fno++)
                {
                    if (!((null == srcList[fno]) || ("".Equals(srcList[fno]))))
                    {
                        BitIndex bi      = this.Df61BitWorker[fno];
                        IPattern pattern = bi.PatternWorker;
                        msgContext.AddField(fno, srcList[fno]);
                        pattern.Build(msgContext);
                    }
                    else
                    {
                        msgContext.BitMap += "0";
                    }
                }
                msgContext.SrcMessage = this.BitMapWorker.GetBitMapHex(msgContext.BitMap) + msgContext.SrcMessage;

                return(msgContext);
            }
            catch (Exception ex)
            {
                logger.LogError(ex.Message);
            }
            return(null);
        }