Пример #1
0
        public List <ParsRowView> GetView(XDCMessage XDCmsg)
        {
            List <ParsRowView> mprvlist = new List <ParsRowView>();

            try
            {
                OperatorHelper.CurrentNode = null;
                OperatorHelper.GetXmlConfig(XDCmsg);
                int tempXMLIndex = 0;
                for (int i = 0; i < XDCmsg.MsgASCIIStringFields.Length; i++)
                {
                    List <ParsRowView> ilist = OperatorHelper.GetViewList(XDCmsg, XDCmsg.MsgASCIIStringFields[i], i, ref tempXMLIndex);
                    if (ilist != null)
                    {
                        mprvlist.AddRange(ilist);
                    }

                    if (i != XDCmsg.MsgASCIIStringFields.Length - 1)
                    {
                        mprvlist.Add(new ParsRowView("FS", "", ""));
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.LogError(this.GetType().Name, "GetView Error:" + ex.Message);
            }
            return(mprvlist);
        }
Пример #2
0
        public List <ParsRowView> GetView(XDCMessage XDCmsg)
        {
            List <ParsRowView> mprvlist = new List <ParsRowView>();

            //OperatorHelper.CurrentNode = null;
            //OperatorHelper.GetXmlConfig(XDCmsg);
            //int tempXMLIndex = 0;
            //for (int i = 0; i < XDCmsg.MsgASCIIStringFields.Length; i++)
            //{
            //    List<ParsRowView> ilist = OperatorHelper.GetViewList(XDCmsg, XDCmsg.MsgASCIIStringFields[i], i, ref tempXMLIndex);
            //    if (ilist != null)
            //        mprvlist.AddRange(ilist);

            //    if (i != XDCmsg.MsgASCIIStringFields.Length - 1)
            //    {
            //        mprvlist.Add(new ParsRowView("FS", "", ""));
            //    }
            //}


            return(mprvlist);
        }
Пример #3
0
        /// <summary>
        /// 获取xml节点列表
        /// </summary>
        /// <returns></returns>
        public static List <TemplateView> GetXmlConfig(XDCMessage CurrentMessage)
        {
            string[] tempArrary = CurrentMessage.MsgASCIIStringFields;
            XmlNode  root       = null;
            string   attrID     = "";
            //1NDC|2DDC
            string attrProtocolType = "1";
            //1State
            //2Screen
            //3Fit
            //4Message
            string  attrDataType = "4";
            XmlNode cur          = null;
            string  commandCode  = "";

            string MessageIdentifier = "";
            int    sdIndex           = 3;

            root = XMLHelper.instance.XMLFiles["ProtocolTemplate"].XmlDoc.SelectSingleNode("ProtocolTemplate");
            switch (CurrentMessage.MsgType)
            {
            case MessageType.DataCommand:
            {
                #region 3x_DataCommand

                commandCode       = tempArrary[3].Substring(0, 1);
                MessageIdentifier = commandCode;
                attrID            = "3FSFSFS" + commandCode;
                cur = XDCUnity.GetNodeDetail(root, attrID, attrProtocolType, attrDataType);
                if (null == cur)
                {
                    //通常查询xml文件中ID=1的配置
                    attrID = tempArrary[0].Substring(0, 1);
                    cur    = XDCUnity.GetNodeDetail(root, attrID, attrProtocolType, attrDataType);
                }
                #endregion
            }
            break;

            case MessageType.TerminalCommand:
            {
                #region 1x_TerminalCommand

                commandCode = tempArrary[3].Substring(0, 1);
                //TerminalCommand消息中,MessageIdentifier的值等于commandCode,因为
                //TerminalCommand消息LUNO号后只有一个FS
                MessageIdentifier = commandCode;
                attrID            = "1FSFSFS" + commandCode;
                cur = XDCUnity.GetNodeDetail(root, attrID, attrProtocolType, attrDataType);
                if (null == cur)
                {
                    //通常查询xml文件中ID=1的配置
                    attrID = tempArrary[0].Substring(0, 1);
                    cur    = XDCUnity.GetNodeDetail(root, attrID, attrProtocolType, attrDataType);
                }
                #endregion
            }
            break;

            case MessageType.SolicitedMessage:
            {
                #region 22||23_SolicitedMessage
                attrID = tempArrary[0] + "FSFSFS";
                int fsCount = 3;
                try
                {
                    commandCode = tempArrary[sdIndex].Substring(0, 1);
                }
                catch
                {
                    commandCode = "";
                }
                if (tempArrary.Length > sdIndex + 1)
                {
                    MessageIdentifier = tempArrary[sdIndex + 1].Substring(0, 1);
                }
                attrID += commandCode;
                string tempXMLid = "";
                string miString  = "";
                if (commandCode == "8" ||
                    commandCode == "C" ||
                    commandCode == "F")
                {
                    miString = "FS" + MessageIdentifier;
                    fsCount++;
                }

                int maxFsCountRear = tempArrary.Length - fsCount - 1;
                //最多的FS,并逐个递减
                while (maxFsCountRear > -1)
                {
                    tempXMLid = attrID + miString + XDCUnity.GetFS(maxFsCountRear);
                    cur       = XDCUnity.GetNodeDetail(root, tempXMLid, attrProtocolType, attrDataType);
                    if (null != cur)
                    {
                        break;
                    }
                    maxFsCountRear--;
                }
                //如果还未空,去掉MessageIdentifier
                if (null == cur)
                {
                    tempXMLid = attrID;
                    cur       = XDCUnity.GetNodeDetail(root, tempXMLid, attrProtocolType, attrDataType);
                    if (null == cur)
                    {
                        tempXMLid = tempArrary[0];
                        cur       = XDCUnity.GetNodeDetail(root, tempXMLid, attrProtocolType, attrDataType);
                    }
                }
                #endregion
            }
            break;

            case MessageType.UnSolicitedMessage:
            {
                #region 12||11_UnSolicitedMessage
                try
                {
                    commandCode = tempArrary[3].Substring(0, 1);
                }
                catch
                {
                    commandCode = "";
                }
                attrID = tempArrary[0] + "FSFSFS" + commandCode;
                if (tempArrary[0].Equals("11"))
                {
                    try
                    {
                        MessageIdentifier = tempArrary[13].Substring(0, 1);
                    }
                    catch
                    {
                        MessageIdentifier = "";
                    }
                }

                cur = XDCUnity.GetNodeDetail(root, attrID, attrProtocolType, attrDataType);
                if (null == cur)
                {
                    attrID = tempArrary[0];
                    cur    = XDCUnity.GetNodeDetail(root, attrID, attrProtocolType, attrDataType);
                }
                #endregion
            }
            break;

            case MessageType.TransactionReplyCommand:
            {
                #region 4_TransactionReplyCommand

                attrID = "4";
                cur    = XDCUnity.GetNodeDetail(root, attrID, attrProtocolType, attrDataType);

                #endregion
            }
            break;

            case MessageType.UploadEJMessage:
            {
                #region 6x_UploadEJMessage
                try
                {
                    commandCode       = tempArrary[3].Substring(0, 1);
                    MessageIdentifier = commandCode;
                }
                catch
                {
                    commandCode       = "";
                    MessageIdentifier = commandCode;
                }
                attrID = tempArrary[0].Substring(0, tempArrary[0].Length);
                cur    = XDCUnity.GetNodeDetail(root, attrID, attrProtocolType, attrDataType);
                if (null == cur)
                {
                    attrID = tempArrary[0].Substring(0, 1);
                    cur    = XDCUnity.GetNodeDetail(root, attrID, attrProtocolType, attrDataType);
                }
                #endregion
            }
            break;

            case MessageType.ExitToHostMessages:
            {
            }
            break;

            case MessageType.HostToExitMessages:
            {
                #region 7_HostToExitMessages

                attrID = tempArrary[0].Substring(0, 1);
                cur    = XDCUnity.GetNodeDetail(root, attrID, attrProtocolType, attrDataType);

                #endregion
            }
            break;

            case MessageType.Unknow:
                break;

            default:
                break;
            }
            if (null == cur)
            {
                return(null);
            }
            bool alreadyFS_X           = true;;
            List <TemplateView> TvList = new List <TemplateView>();
            foreach (XmlNode item in cur.ChildNodes)
            {
                TemplateView tv        = new TemplateView();
                XmlAttribute fieldName = item.Attributes["Name"];
                XmlAttribute fieldSize = item.Attributes["Size"];

                if (fieldName != null)
                {
                    tv.FieldName = fieldName.Value;
                }
                if ((tv.FieldName.StartsWith("FS") && tv.FieldName.Length > 2) ||
                    (tv.FieldName.StartsWith("GS") && tv.FieldName.Length > 2))
                {
                    if (tv.FieldName.Contains('|'))
                    {
                        bool     isFoundInnerFS = false;
                        string[] fsSpliterArray = tv.FieldName.Replace("FS", "").Split('|');
                        foreach (string fsSpliterStr in fsSpliterArray)
                        {
                            if (MessageIdentifier == fsSpliterStr)
                            {
                                tv.FieldName   = "FS";
                                isFoundInnerFS = true;
                                alreadyFS_X    = true;
                                break;
                            }
                            else
                            {
                                isFoundInnerFS = false;
                            }
                        }
                        if (!isFoundInnerFS)
                        {
                            continue;
                        }
                    }
                    else if (tv.FieldName.Equals("FS" + "*"))
                    {
                        //找到FS*
                        tv.FieldName = "FS*";
                        alreadyFS_X  = true;
                    }
                    //已FS开头,但是不等於FS/GS的需要越过两行
                    else if (!tv.FieldName.Equals("FS" + MessageIdentifier) &&
                             !tv.FieldName.Equals("GS" + MessageIdentifier))
                    {
                        alreadyFS_X = false;
                        continue;
                    }
                    else
                    {
                        tv.FieldName = tv.FieldName.Substring(0, 2);
                        alreadyFS_X  = true;
                    }
                }
                else if (tv.FieldName.Equals("FS"))
                {
                    alreadyFS_X = true;
                }
                if (!alreadyFS_X)
                {
                    continue;
                }

                if (fieldSize != null)
                {
                    int  fSize;
                    bool isNumeric = int.TryParse(fieldSize.Value, out fSize);
                    if (isNumeric)
                    {
                        tv.FieldSize = fSize;
                    }
                    else
                    {
                        //非数字的情况,如*
                        tv.FieldSize = -1;
                    }
                }
                if (item.HasChildNodes)
                {
                    Dictionary <string, string> dic = new Dictionary <string, string>();
                    foreach (XmlNode valueItem in item.ChildNodes)
                    {
                        XmlAttribute attrComment   = valueItem.Attributes["Comment"];
                        XmlAttribute attrOperation = valueItem.Attributes["Operation"];
                        if (attrOperation != null)
                        {
                            //进行&运算
                            if (attrOperation.Value.StartsWith("&"))
                            {
                                //&运算
                                string ampValue = attrOperation.Value.Replace("&", "");
                                dic.Add(valueItem.InnerText + "&amp;" + ampValue, attrComment.Value);
                            }
                        }
                        else if (null != attrComment &&
                                 !dic.ContainsKey(valueItem.InnerText))
                        {
                            dic.Add(valueItem.InnerText, attrComment.Value);
                        }
                        if (valueItem.InnerText != "*")
                        {
                            tv.FieldSize = valueItem.InnerText.Length > tv.FieldSize ? valueItem.InnerText.Length : tv.FieldSize;
                        }
                    }
                    tv.FieldValue = dic;
                }
                TvList.Add(tv);
            }


            return(TvList);
        }
Пример #4
0
        public List <ParsRowView> GetView(XDCMessage XDCmsg)
        {
            List <TemplateView> xmlList = OperatorHelper.GetXmlConfig(XDCmsg);

            if (null == xmlList)
            {
                return(null);
            }
            List <ParsRowView> mprvlist = new List <ParsRowView>();
            int    i                       = 0;
            int    J                       = 0;
            bool   alreadyGSorFS           = false;
            string alreadGSorFsSpliter     = string.Empty;
            List <TemplateView> GSitemList = new List <TemplateView>();

            foreach (TemplateView item in xmlList)
            {
                if (item.FieldName == "FS")
                {
                    mprvlist.Add(new ParsRowView("FS", "", ""));
                    i = 0;
                    J++;
                    alreadyGSorFS       = false;
                    alreadGSorFsSpliter = "";
                }
                else if (item.FieldName == "GS" ||
                         item.FieldName == "FS*")
                {
                    alreadyGSorFS       = true;
                    alreadGSorFsSpliter = item.FieldName.Substring(0, 2);
                }
                else
                {
                    //处理GS情况
                    if (alreadyGSorFS)
                    {
                        GSitemList.Add(item);
                        continue;
                    }

                    #region GS非结尾的情况

                    if (GSitemList.Count > 0)
                    {
                        Char     spliterGS = '\u001D';
                        string[] GSstring;
                        if (alreadGSorFsSpliter == "GS")
                        {
                            GSstring = XDCmsg.MsgASCIIStringFields[J].Split(spliterGS);
                        }
                        else
                        {
                            GSstring = OperatorHelper.GetSubArray(XDCmsg.MsgASCIIStringFields, J + 1);
                        }
                        string tempValueGS  = "";
                        string tempComment2 = "";
                        for (int k = alreadGSorFsSpliter == "GS" ? 1 : 0; k < GSstring.Length; k++)
                        {
                            if (null == (GSstring[k]))
                            {
                                break;
                            }
                            mprvlist.Add(new ParsRowView(alreadGSorFsSpliter, "", ""));
                            for (int l = 0; l < GSitemList.Count; l++)
                            {
                                if (GSitemList[l].FieldSize > 0)
                                {
                                    if (GSstring[k].Length >= GSitemList[l].FieldSize)
                                    {
                                        tempValueGS = GSstring[k].Substring(l, GSitemList[l].FieldSize);
                                    }
                                    else
                                    {
                                        tempValueGS = "";
                                    }
                                }
                                else
                                {
                                    if (l < GSstring[k].Length)
                                    {
                                        tempValueGS = GSstring[k].Substring(l, GSstring[k].Length - l);
                                    }
                                    else
                                    {
                                        tempValueGS = "";
                                    }
                                }
                                if (GSitemList[l].FieldValue != null &&
                                    GSitemList[l].FieldValue.ContainsKey(tempValueGS))
                                {
                                    tempComment2 = GSitemList[l].FieldValue[tempValueGS];
                                }
                                else if (GSitemList[l].FieldValue != null &&
                                         GSitemList[l].FieldValue.ContainsKey("*"))
                                {
                                    tempComment2 = GSitemList[l].FieldValue["*"];
                                }
                                else
                                {
                                    if (string.IsNullOrEmpty(tempValueGS))
                                    {
                                        tempComment2 = "No Value";
                                    }
                                    else
                                    {
                                        tempComment2 = "";
                                    }
                                }

                                mprvlist.Add(new ParsRowView(GSitemList[l].FieldName, tempValueGS, tempComment2));
                            }
                        }
                    }

                    GSitemList.Clear();
                    #endregion
                    string tempValue = string.Empty;
                    //域的值有指定长度的情况
                    if (item.FieldSize > 0)
                    {
                        try
                        {
                            tempValue = XDCmsg.MsgASCIIStringFields[J].Substring(i, item.FieldSize);
                            i        += item.FieldSize;
                        }
                        catch
                        {
                            tempValue = "";
                            i        += item.FieldSize;
                        }
                    }
                    else
                    {
                        try
                        {
                            tempValue = XDCmsg.MsgASCIIStringFields[J].Substring(i, XDCmsg.MsgASCIIStringFields[J].Length - i);
                            i        += XDCmsg.MsgASCIIStringFields[J].Length - i;
                        }
                        catch
                        {
                            tempValue = "";
                            i        += item.FieldSize;
                        }
                    }
                    string tempComment = string.Empty;

                    if (item.FieldValue != null)
                    {
                        if (string.IsNullOrEmpty(tempValue))
                        {
                            tempComment = "No Value";
                        }
                        else if (item.FieldValue.ContainsKey(tempValue))
                        {
                            tempComment = item.FieldValue[tempValue];
                        }
                        else if (item.FieldValue.ContainsKey("*"))
                        {
                            tempComment = item.FieldValue["*"];
                        }
                        else
                        {
                            bool isFind = false;
                            foreach (KeyValuePair <string, string> kvpItem in item.FieldValue)
                            {
                                //&运算
                                if (kvpItem.Key.Contains("&amp;"))
                                {
                                    isFind = true;
                                    string ampValue    = kvpItem.Key.Substring(0, kvpItem.Key.IndexOf("&amp;"));
                                    string ampOperator = kvpItem.Key.Substring(kvpItem.Key.IndexOf("&amp;") + 5, kvpItem.Key.Length - kvpItem.Key.IndexOf("&amp;") - 5);
                                    int    ampResult   = int.Parse(tempValue) & int.Parse(ampOperator);
                                    if (ampResult.ToString() == ampValue)
                                    {
                                        tempComment += kvpItem.Value + ";";
                                    }
                                }
                            }
                            if (!isFind)
                            {
                                tempComment = "UnKnow Value";
                            }
                        }
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(tempValue))
                        {
                            tempComment = "No Value";
                        }
                        else
                        {
                            tempComment = "";
                        }
                    }
                    mprvlist.Add(new ParsRowView(item.FieldName, tempValue, tempComment));
                }
            }
            #region GS结尾的情况

            if (GSitemList.Count > 0)
            {
                Char     spliterGS = '\u001D';
                string[] GSstring;
                if (alreadGSorFsSpliter == "GS")
                {
                    GSstring = XDCmsg.MsgASCIIStringFields[J].Split(spliterGS);
                }
                else
                {
                    GSstring = OperatorHelper.GetSubArray(XDCmsg.MsgASCIIStringFields, J + 1);
                }
                string tempValueGS = "";
                string tempComment = "";
                for (int k = alreadGSorFsSpliter == "GS" ? 1 : 0; k < GSstring.Length; k++)
                {
                    if (null == (GSstring[k]))
                    {
                        break;
                    }
                    mprvlist.Add(new ParsRowView(alreadGSorFsSpliter, "", ""));
                    for (int l = 0; l < GSitemList.Count; l++)
                    {
                        if (GSitemList[l].FieldSize > 0)
                        {
                            if (GSstring[k].Length >= GSitemList[l].FieldSize)
                            {
                                tempValueGS = GSstring[k].Substring(l, GSitemList[l].FieldSize);
                            }
                            else
                            {
                                tempValueGS = "";
                            }
                        }
                        else
                        {
                            if (l < GSstring[k].Length)
                            {
                                tempValueGS = GSstring[k].Substring(l, GSstring[k].Length - l);
                            }
                            else
                            {
                                tempValueGS = "";
                            }
                        }
                        if (GSitemList[l].FieldValue != null &&
                            GSitemList[l].FieldValue.ContainsKey(tempValueGS))
                        {
                            tempComment = GSitemList[l].FieldValue[tempValueGS];
                        }
                        else if (GSitemList[l].FieldValue != null &&
                                 GSitemList[l].FieldValue.ContainsKey("*"))
                        {
                            tempComment = GSitemList[l].FieldValue["*"];
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(tempValueGS))
                            {
                                tempComment = "No Value";
                            }
                            else
                            {
                                tempComment = "";
                            }
                        }

                        mprvlist.Add(new ParsRowView(GSitemList[l].FieldName, tempValueGS, tempComment));
                    }
                }
            }

            #endregion
            return(mprvlist);
        }
        public XDCMessage Format(byte[] msgByte, int msgLength, TcpHead HeadType = TcpHead.NoHead, bool isDebug = false)
        {
            XDCMessage result = new XDCMessage();

            try
            {
                #region EBCDIC
                long blong = 0;
                XDCUnity.PackMsgCode(ref msgByte, ref blong, "Recv", isDebug);
                #endregion
                //0.原字节数组
                result.MsgByteArray = msgByte;

                //2.ASCII字符串
                //2.ASCII字符串
                if (HeadType == TcpHead.L2L1)
                {
                    //L2L1,the len is in index 1
                    int megLen = msgByte[1] + (msgByte[0] << 8);
                    result.MsgASCIIString = Encoding.ASCII.GetString(msgByte, 2, megLen);
                    //result.MsgASCIIString = Encoding.ASCII.GetString(msgByte, 2, msgLength - 2);
                }
                else if (HeadType == TcpHead.L1L2)
                {
                    //L1L2, the len is in index 0
                    int megLen = msgByte[0] + (msgByte[1] << 8);
                    result.MsgASCIIString = Encoding.ASCII.GetString(msgByte, 2, megLen);
                    //result.MsgASCIIString = Encoding.ASCII.GetString(msgByte, 2, msgLength - 2);
                }
                else if (HeadType == TcpHead.L4L3L2L1)
                {
                    int megLen = msgByte[3] + (msgByte[2] << 8) + (msgByte[1] << 16) + (msgByte[0] << 24);
                    result.MsgASCIIString = Encoding.ASCII.GetString(msgByte, 4, megLen);
                    //result.MsgASCIIString = Encoding.ASCII.GetString(msgByte, 4, msgLength - 4);
                }
                else if (HeadType == TcpHead.L4L3L2L1_ASCII)
                {
                    byte[] m_head = new byte[] { msgByte[0], msgByte[1], msgByte[2], msgByte[3] };
                    int    megLen = int.Parse(Encoding.ASCII.GetString(m_head));// msgByte[3] + (msgByte[2] << 8) + (msgByte[1] << 16) + (msgByte[0] << 24);
                    result.MsgASCIIString = Encoding.ASCII.GetString(msgByte, 4, megLen);
                    //result.MsgASCIIString = Encoding.ASCII.GetString(msgByte, 4, msgLength - 4);
                }
                else if (HeadType == TcpHead.L1L2L3L4)
                {
                    int megLen = msgByte[0] + (msgByte[1] << 8) + (msgByte[2] << 16) + (msgByte[3] << 24);;
                    result.MsgASCIIString = Encoding.ASCII.GetString(msgByte, 4, megLen);
                }
                else
                {
                    result.MsgASCIIString = Encoding.ASCII.GetString(msgByte, 0, msgLength);
                }

                char     MsgFS     = '\u001C';//域分隔符
                string[] msgFields = result.MsgASCIIString.Split(MsgFS);

                //3.分解消息得各域的字符数组
                result.MsgASCIIStringFields = msgFields;

                //4.标识
                if (msgFields.Length > 3 && msgFields[3].Length > 0)
                {
                    result.Identification = msgFields[3].Substring(0, 1);
                }
                //5.消息类别
                string tempField_0 = msgFields[0].Length > 3 ? msgFields[0].Substring(2, msgFields[0].Length - 2) : msgFields[0];
                result.MsgType = FormatHelper.ParsMessageClass(tempField_0);

                if (result.MsgType == MessageType.UnSolicitedMessage &&
                    msgFields.Length > 7 && msgFields[7].Length > 0)
                {
                    //操作码
                    result.OperationCode = msgFields[7].Replace(" ", "_");
                    //金额域
                    if (msgFields.Length > 8)
                    {
                        result.AmountField = msgFields[8];
                    }
                    //pan
                    if (msgFields[5].IndexOf('=') > 0)
                    {
                        result.PAN = msgFields[5].Substring(1, msgFields[5].IndexOf('=') - 1);
                    }
                }

                string msgResult = string.Empty;
                result.MsgCommandType = MessageCommandType.Unknow;

                #region 5.判断消息类型

                switch (result.Identification)
                {
                case "1":
                {
                    if (result.MsgType == MessageType.TerminalCommand)
                    {
                        result.MsgCommandType = MessageCommandType.GoInService;
                    }
                }
                break;

                case "2":
                {
                    if (result.MsgType == MessageType.TerminalCommand)
                    {
                        result.MsgCommandType = MessageCommandType.GoOutOfService;
                    }
                }
                break;

                case "3":
                {
                    //NDC
                    if (result.MsgType == MessageType.SolicitedMessage)
                    {
                        result.MsgCommandType = MessageCommandType.NewKeyVerification;
                    }
                    //NeedSendToBothHost.Enqueue(result.MsgBase64String);
                }
                break;

                case "8":
                {
                    //NDC
                    if (result.MsgType == MessageType.SolicitedMessage)
                    {
                        result.MsgCommandType = MessageCommandType.DeviceFault;
                    }
                    if (msgFields.Length > 4 && msgFields[4].Length > 2 && msgFields[4].Substring(0, 2) == "E2")
                    {
                        result.MsgCommandType = MessageCommandType.Reversal;
                    }
                }
                break;

                case "9":
                {
                    if (result.MsgType == MessageType.SolicitedMessage)
                    {
                        result.MsgCommandType = MessageCommandType.ReadyB;
                    }
                }
                break;

                case "B":
                {
                    if (result.MsgType == MessageType.UnSolicitedMessage)
                    {
                        if (msgFields[3].Equals("B0000"))
                        {
                            result.MsgCommandType = MessageCommandType.FullDownLoad;
                            if (!XDCUnity.isFulldownLoadEnqueue)
                            {
                                NeedSendToBothHost.Enqueue(result.MsgASCIIString);
                                XDCUnity.isFulldownLoadEnqueue = true;
                            }
                        }
                        else
                        {
                            result.MsgCommandType = MessageCommandType.NotFullDownLoad;
                        }
                    }
                }
                break;

                case "E":
                {
                    if (result.MsgType == MessageType.UnSolicitedMessage)
                    {
                        //cash handle
                        result.MsgCommandType = MessageCommandType.CashHandler;
                        //NeedSendToBothHost.Enqueue(result.MsgBase64String);
                    }
                }
                break;

                case "F":
                {
                    //NDC
                    if (result.MsgType == MessageType.SolicitedMessage)
                    {
                        //TerminalState
                        result.MsgCommandType = MessageCommandType.TerminalState;
                        //NeedSendToBothHost.Enqueue(result.MsgBase64String);
                    }
                }
                break;

                case "P":
                {
                    if (result.MsgType == MessageType.UnSolicitedMessage &&
                        msgFields[3].Length > 2)
                    {
                        if ("20" == msgFields[3].Substring(1, 2))
                        {
                            result.MsgCommandType = MessageCommandType.SupervisorAndSupplySwitchOFF;
                        }
                        else if ("21" == msgFields[3].Substring(1, 2))
                        {
                            result.MsgCommandType = MessageCommandType.SupervisorAndSupplySwitchON;
                        }
                    }
                }
                break;

                case "":
                {
                    result.MsgCommandType = MessageCommandType.TransactionMessage;
                }
                break;

                default:
                    break;
                }

                #endregion

                //6.LUNO
                if (msgFields.Length > 1 && msgFields[1].Length > 0)
                {
                    if (msgFields[1].Length > 6)
                    {
                        result.LUNO = msgFields[1].Substring(0, 6);
                    }
                    else
                    {
                        result.LUNO = msgFields[1];
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.LogError(this.GetType().Name, "Format Error:" + ex.Message);
            }
            return(result);
        }
Пример #6
0
        /// <summary>
        /// 获取xml节点列表
        /// </summary>
        /// <returns></returns>
        public static void GetXmlConfig(XDCMessage CurrentMessage)
        {
            string[] tempArrary = CurrentMessage.MsgASCIIStringFields;
            XmlNode  root       = null;
            string   attrID     = "";
            //1NDC|2DDC
            string attrProtocolType = "1";
            //1State
            //2Screen
            //3Fit
            //4Message
            string  attrDataType = "4";
            XmlNode cur          = null;
            string  commandCode  = "";

            string MessageIdentifier = "";
            int    sdIndex           = 3;

            //root = XMLHelper.instance.XMLFiles["ProtocolTemplate"].XmlDoc.SelectSingleNode("ProtocolTemplate");
            switch (CurrentMessage.MsgType)
            {
            case MessageType.DataCommand:
            {
                #region 3x_DataCommand

                commandCode       = tempArrary[3].Substring(0, 1);
                MessageIdentifier = commandCode;
                attrID            = "3FSFSFS" + commandCode;
                cur = XDCUnity.GetNodeDetail(root, attrID, attrProtocolType, attrDataType);
                if (null == cur)
                {
                    //通常查询xml文件中ID=1的配置
                    attrID = tempArrary[0].Substring(0, 1);
                    cur    = XDCUnity.GetNodeDetail(root, attrID, attrProtocolType, attrDataType);
                }
                #endregion
            }
            break;

            case MessageType.TerminalCommand:
            {
                #region 1x_TerminalCommand

                commandCode = tempArrary[3].Substring(0, 1);
                //TerminalCommand消息中,MessageIdentifier的值等于commandCode,因为
                //TerminalCommand消息LUNO号后只有一个FS
                MessageIdentifier = commandCode;
                attrID            = "1FSFSFS" + commandCode;
                cur = XDCUnity.GetNodeDetail(root, attrID, attrProtocolType, attrDataType);
                if (null == cur)
                {
                    //通常查询xml文件中ID=1的配置
                    attrID = tempArrary[0].Substring(0, 1);
                    cur    = XDCUnity.GetNodeDetail(root, attrID, attrProtocolType, attrDataType);
                }
                #endregion
            }
            break;

            case MessageType.SolicitedMessage:
            {
                #region 22||23_SolicitedMessage
                attrID = tempArrary[0] + "FSFSFS";
                int fsCount = 3;
                try
                {
                    commandCode = tempArrary[sdIndex].Substring(0, 1);
                }
                catch
                {
                    commandCode = "";
                }
                if (tempArrary.Length > sdIndex + 1)
                {
                    MessageIdentifier = tempArrary[sdIndex + 1].Substring(0, 1);
                }
                attrID += commandCode;
                string tempXMLid = "";
                string miString  = "";
                if (commandCode == "8" ||
                    commandCode == "C" ||
                    commandCode == "F")
                {
                    miString = "FS" + MessageIdentifier;
                    fsCount++;
                }

                int maxFsCountRear = tempArrary.Length - fsCount - 1;
                //最多的FS,并逐个递减
                while (maxFsCountRear > -1)
                {
                    tempXMLid = attrID + miString + XDCUnity.GetFS(maxFsCountRear);
                    cur       = XDCUnity.GetNodeDetail(root, tempXMLid, attrProtocolType, attrDataType);
                    if (null != cur)
                    {
                        break;
                    }
                    maxFsCountRear--;
                }
                //如果还未空,去掉MessageIdentifier
                if (null == cur)
                {
                    tempXMLid = attrID;
                    cur       = XDCUnity.GetNodeDetail(root, tempXMLid, attrProtocolType, attrDataType);
                    if (null == cur)
                    {
                        tempXMLid = tempArrary[0];
                        cur       = XDCUnity.GetNodeDetail(root, tempXMLid, attrProtocolType, attrDataType);
                    }
                }
                #endregion
            }
            break;

            case MessageType.UnSolicitedMessage:
            {
                #region 12||11_UnSolicitedMessage
                try
                {
                    commandCode = tempArrary[3].Substring(0, 1);
                }
                catch
                {
                    commandCode = "";
                }
                attrID = tempArrary[0] + "FSFSFS" + commandCode;
                if (tempArrary[0].Equals("11"))
                {
                    try
                    {
                        MessageIdentifier = tempArrary[13].Substring(0, 1);
                    }
                    catch
                    {
                        MessageIdentifier = "";
                    }
                }

                cur = XDCUnity.GetNodeDetail(root, attrID, attrProtocolType, attrDataType);
                if (null == cur)
                {
                    attrID = tempArrary[0];
                    cur    = XDCUnity.GetNodeDetail(root, attrID, attrProtocolType, attrDataType);
                }
                #endregion
            }
            break;

            case MessageType.TransactionReplyCommand:
            {
                #region 4_TransactionReplyCommand

                attrID = "4";
                cur    = XDCUnity.GetNodeDetail(root, attrID, attrProtocolType, attrDataType);

                #endregion
            }
            break;

            case MessageType.UploadEJMessage:
            {
                #region 6x_UploadEJMessage
                try
                {
                    commandCode       = tempArrary[3].Substring(0, 1);
                    MessageIdentifier = commandCode;
                }
                catch
                {
                    commandCode       = "";
                    MessageIdentifier = commandCode;
                }
                attrID = tempArrary[0].Substring(0, tempArrary[0].Length);
                cur    = XDCUnity.GetNodeDetail(root, attrID, attrProtocolType, attrDataType);
                if (null == cur)
                {
                    attrID = tempArrary[0].Substring(0, 1);
                    cur    = XDCUnity.GetNodeDetail(root, attrID, attrProtocolType, attrDataType);
                }
                #endregion
            }
            break;

            case MessageType.ExitToHostMessages:
            {
            }
            break;

            case MessageType.HostToExitMessages:
            {
                #region 7_HostToExitMessages

                attrID = tempArrary[0].Substring(0, 1);
                cur    = XDCUnity.GetNodeDetail(root, attrID, attrProtocolType, attrDataType);

                #endregion
            }
            break;

            case MessageType.EMVConfigMessages:
            {
                #region 8x_EmvConfigMessages

                commandCode       = tempArrary[2].Substring(0, 1);
                MessageIdentifier = commandCode;
                attrID            = "8FSFS" + commandCode;
                cur = XDCUnity.GetNodeDetail(root, attrID, attrProtocolType, attrDataType);
                if (null == cur)
                {
                    //通常查询xml文件中ID=1的配置
                    attrID = tempArrary[0].Substring(0, 1);
                    cur    = XDCUnity.GetNodeDetail(root, attrID, attrProtocolType, attrDataType);
                }
                #endregion
            }
            break;

            case MessageType.Unknow:
                break;

            default:
                break;
            }

            CurrentNode = cur;
        }
Пример #7
0
        public static List <ParsRowView> GetViewList(XDCMessage XDCmsg, string msgCurrentFieldContent, int currentFSindex, ref int currXmlNodeIndex)
        {
            #region 修复12消息解析错误的问题

            if (string.IsNullOrEmpty(msgCurrentFieldContent) &&
                CurrentNode != null && CurrentNode.ChildNodes.Count > currXmlNodeIndex)
            {
                XmlAttribute fieldName = CurrentNode.ChildNodes[currXmlNodeIndex].Attributes["Name"];
                if (fieldName != null && fieldName.Value.StartsWith("FS"))
                {
                    //解决存款消息中,310,311等buffer先生不正确的问题。edit by frde 20160106
                    currXmlNodeIndex += 1;
                    return(null);
                }
            }
            #endregion
            List <ParsRowView>  rowViewList = new List <ParsRowView>();
            List <TemplateView> TvList      = new List <TemplateView>();

            int  FSCountIndex = 0;
            bool isFSrepeat   = false;
            bool isFoundFS_x  = false;
            bool isOccurFS_x  = false;
            int  tempIndex    = currXmlNodeIndex;
            if (CurrentNode == null)
            {
                return(rowViewList);
            }
            for (int i = tempIndex; i < CurrentNode.ChildNodes.Count; i++)
            {
                if (!isFSrepeat)
                {
                    currXmlNodeIndex++;
                }
                TemplateView tv        = new TemplateView();
                XmlAttribute fieldName = CurrentNode.ChildNodes[i].Attributes["Name"];
                XmlAttribute fieldSize = CurrentNode.ChildNodes[i].Attributes["Size"];
                if (fieldName != null)
                {
                    if (fieldName.Value.ToString() == "FS")
                    {
                        isOccurFS_x = false;
                        FindFinalFS(ref rowViewList, ref TvList, ref isFoundFS_x, msgCurrentFieldContent);
                        break;
                    }
                    else if (fieldName.Value.ToString().StartsWith("FS"))
                    {
                        isOccurFS_x = true;
                        //if(string.IsNullOrEmpty(msgCurrentFieldContent))
                        //{
                        //    FindFinalFS(ref rowViewList, ref TvList, ref isFoundFS_x, msgCurrentFieldContent);
                        //    currXmlNodeIndex = currXmlNodeIndex - 1;
                        //    isOccurFS_x = false;
                        //    break;
                        //}
                        if (TvList != null && TvList.Count > 0)
                        {
                            FindFinalFS(ref rowViewList, ref TvList, ref isFoundFS_x, msgCurrentFieldContent);
                            currXmlNodeIndex = currXmlNodeIndex - 1;
                            isOccurFS_x      = false;
                            break;
                        }
                        //FS*表示除了枚举的情况之外的所有通用情况
                        if (fieldName.Value == "FS*")
                        {
                            isOccurFS_x = false;
                            if (TvList != null && TvList.Count > 0)
                            {
                                FindFinalFS(ref rowViewList, ref TvList, ref isFoundFS_x, msgCurrentFieldContent);
                                break;
                            }
                        }
                        else if (fieldName.Value == "FS**")
                        {
                            currXmlNodeIndex = currXmlNodeIndex - 1;
                            isFSrepeat       = true;

                            isOccurFS_x = false;
                            if (TvList != null && TvList.Count > 0)
                            {
                                FindFinalFS(ref rowViewList, ref TvList, ref isFoundFS_x, msgCurrentFieldContent);
                                break;
                            }
                        }
                        else
                        {
                            //如果当前消息域为空,且接下来都不是直接的FS,则直接跳过,XML节点下标向上跳回一个
                            //if (string.IsNullOrEmpty(msgCurrentFieldContent))
                            //{
                            //    currXmlNodeIndex = currXmlNodeIndex - 1;
                            //    break;
                            //    //isFoundFS_x = false;
                            //    //continue;
                            //}

                            isFoundFS_x = false;
                            string   tempcontent      = msgCurrentFieldContent;
                            string   tempStringBehind = fieldName.Value.Substring(2, fieldName.Value.Length - 2);
                            string[] identifyArray    = tempStringBehind.Split('|');
                            int      tempLength       = 0;
                            string   tempIde          = "";
                            foreach (string ideItem in identifyArray)
                            {
                                tempLength = ideItem.Length;
                                try
                                {
                                    tempIde = tempcontent.Substring(0, tempLength);
                                }
                                catch
                                {
                                    tempIde = "";
                                }
                                if (tempIde == ideItem)
                                {
                                    isFoundFS_x = true;
                                    TvList.Clear();
                                    break;
                                }
                            }
                            if (isFoundFS_x)
                            {
                                if (TvList != null && TvList.Count > 0)
                                {
                                    FindFinalFS(ref rowViewList, ref TvList, ref isFoundFS_x, msgCurrentFieldContent);

                                    TvList.Clear();
                                    break;
                                }
                                FSCountIndex++;
                            }
                            else
                            {
                            }
                        }
                    }
                    else
                    {
                        //出现FS_x但是又没匹配上,接下来的都跳过
                        if (isOccurFS_x && !isFoundFS_x)
                        {
                            continue;
                        }

                        #region 普通节点,加入列表中( 永远为当前一个FS中的内容 )
                        tv.FieldName = fieldName.Value;
                        int size;
                        int.TryParse(fieldSize.Value, out size);
                        tv.FieldSize = size;
                        if (CurrentNode.ChildNodes[i].HasChildNodes)
                        {
                            Dictionary <string, string> dic = new Dictionary <string, string>();
                            foreach (XmlNode valueItem in CurrentNode.ChildNodes[i].ChildNodes)
                            {
                                XmlAttribute attrComment   = valueItem.Attributes["Comment"];
                                XmlAttribute attrOperation = valueItem.Attributes["Operation"];
                                if (attrOperation != null)
                                {
                                    //进行&运算
                                    if (attrOperation.Value.StartsWith("&"))
                                    {
                                        //&运算
                                        string ampValue = attrOperation.Value.Replace("&", "");
                                        dic.Add(valueItem.InnerText + "&amp;" + ampValue, attrComment.Value);
                                    }
                                }
                                else if (null != attrComment &&
                                         !dic.ContainsKey(valueItem.InnerText))
                                {
                                    dic.Add(valueItem.InnerText, attrComment.Value);
                                }
                            }
                            tv.FieldValue = dic;
                        }
                        TvList.Add(tv);
                        #endregion
                    }
                }
                else
                {
                }
            }
            if (TvList.Count > 0)
            {
                FindFinalFS(ref rowViewList, ref TvList, ref isFoundFS_x, msgCurrentFieldContent);
                isOccurFS_x = false;
            }
            return(rowViewList);
        }