Ejemplo n.º 1
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 = "2";
            //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

                //DDC的状态、屏幕、FIT等,有 tempArrary[3]做为commandCode
                commandCode       = tempArrary[3].Substring(0, 1);
                MessageIdentifier = tempArrary[3].Substring(1, 1);
                attrID            = "3FSFSFS" + commandCode + MessageIdentifier;
                cur = XDCUnity.GetNodeDetail(root, attrID, attrProtocolType, attrDataType);
                if (null == cur)
                {
                    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 = "";
                }
                MessageIdentifier = 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";
                if (CurrentMessage.MsgASCIIString.Contains(XDCSplictorChar.FS + "'"))
                {
                    MessageIdentifier = "'";
                }
                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;
            }

            CurrentNode = cur;
        }
Ejemplo n.º 2
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);
        }