예제 #1
0
        public override void SaveXmlByName()
        {
            List <SystemStruLink> savedLinks = new List <SystemStruLink>(); //已经存入的连接
            string xmlPath = string.Format(@"{0}\{1}.xml", PathManager.GetSysPath(), this.Name);

            //先判断一些文件是否存在
            if (!PathManager.CheckFile(xmlPath))
            {
                return;
            }
            //保存XML文件
            XDocument xd = new XDocument(
                new XElement("SystemStru",
                             new XAttribute("Name", this.Name),
                             new XAttribute("Type", this.Type),
                             new XAttribute("CntsNum", this.CntsNum),
                             new XElement("CntNames"),
                             new XElement("Links")
                             )
                );
            XElement rt = xd.Element("SystemStru"); //xml文件根节点

            //录入机箱集合
            XElement Cnts = rt.Element("CntNames"); //机箱名根节点

            for (int i = 0; i < CntNames.Length; i++)
            {
                Cnts.Add(new XElement("Container",
                                      new XAttribute("CntSn", i.ToString()),
                                      new XAttribute("CntName", CntNames[i].ToString())));
            }

            //录入连接集合
            XElement links = rt.Element("Links");   //连接根节点

            foreach (var linkList in this.LinksArray)
            {
                if (linkList == null)
                {
                    continue;
                }
                foreach (var link in linkList)
                {
                    int equalNum = savedLinks.Where(lnk => SystemStruLink.IsEqual(link, lnk)).Count();
                    if (equalNum == 0)//该条连接的等效连接没有被访问过
                    {
                        links.Add(new XElement("Link",
                                               new XAttribute("FirstEndId", link.FirstEndId.ToString()),
                                               new XAttribute("FirstEndPos", link.FirstEndPostion.ToString()),
                                               new XAttribute("SecondEndId", link.SecondEndId.ToString()),
                                               new XAttribute("SecondEndPos", link.SecondEndPostion.ToString()),
                                               new XAttribute("Type", link.LinkType.ToString()),
                                               new XAttribute("DataWidth", link.LanesNum.ToString())
                                               ));
                        savedLinks.Add(link);
                    }
                }
            }
            xd.Save(xmlPath);
        }