예제 #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);
        }
        //利用界面填入的信息来刷新一个SystemStru
        private void ReFreshSys(SystemStru sys)
        {
            //刷新基本信息
            sys.Name = _typeTb.Text;
            sys.Type = _typeTb.Text;

            //刷新机箱信息
            foreach (DataGridViewRow row in _consDgv.Rows)
            {
                var cntSn   = int.Parse((string)row.Cells[0].Value); //机箱序号
                var cntName = (string)row.Cells[1].Value;            //机箱的名字
                sys.CntNames[cntSn] = cntName;
            }

            //刷新机箱连接信息
            for (int i = 0; i < _dgvsOpt.DataGridViweList.Count; i++)
            {
                var curDgv   = _dgvsOpt.DataGridViweList[i];
                var linkList = new List <SystemStruLink>();//连接集合
                foreach (DataGridViewRow row in curDgv.Rows)
                {
                    var sysLink = new SystemStruLink(
                        int.Parse((string)row.Cells[_dgvColumnTitle_end1CntNum].Value),
                        int.Parse((string)row.Cells[_dgvColumnTitle_end1PosNum].Value),
                        int.Parse((string)row.Cells[_dgvColumnTitle_end2CntNum].Value),
                        int.Parse((string)row.Cells[_dgvColumnTitle_end2PosNum].Value),
                        (LinkType)Enum.Parse(typeof(LinkType), (string)row.Cells[_dgvColumnTitle_linkType].Value),
                        (LinkLanes)Enum.Parse(typeof(LinkLanes), (string)row.Cells[_dgvColumnTitle_dataWidth].Value));
                    linkList.Add(sysLink);
                }
                sys.LinksArray[i] = linkList;
            }
        }
예제 #3
0
        public override ModelBase CreateObjectByName(string objectName)
        {
            SystemStru sys;
            string     xmlPath = string.Format(@"{0}\{1}.xml", PathManager.GetSysPath(), objectName);

            if (!File.Exists(xmlPath))
            {
                MessageBox.Show("CreateObject_SystemStru:没有该SystemStru对应的XML文件!");
                return(null);
            }

            XDocument xd = XDocument.Load(xmlPath);
            //根元素的Attribute
            XElement rt      = xd.Element("SystemStru");
            int      cntsNum = int.Parse(rt.Attribute("CntsNum").Value);

            sys      = new SystemStru(cntsNum);
            sys.Name = rt.Attribute("Name").Value;
            sys.Type = rt.Attribute("Type").Value;

            //取CntNames的值赋值到CntsName
            XElement cntNames = rt.Element("CntNames");

            foreach (var e in cntNames.Elements())
            {
                int    cntSn   = int.Parse(e.Attribute("CntSn").Value);
                string cntName = e.Attribute("CntName").Value;
                sys.CntNames[cntSn] = cntName;
            }

            //取links赋值到backPlane.linkDir
            XElement links = rt.Element("Links");

            for (int i = 0; i < cntsNum; i++)
            {
                List <SystemStruLink> linksList = new List <SystemStruLink>();
                //找到同一槽位的links,然后添加到list
                var slotLinks = from link in links.Elements()
                                where int.Parse(link.Attribute("FirstEndId").Value) == i
                                select link;
                foreach (var link in slotLinks)
                {
                    LinkType  type    = (LinkType)Enum.Parse(typeof(LinkType), link.Attribute("Type").Value);
                    LinkLanes laneNum = (LinkLanes)Enum.Parse(typeof(LinkLanes), link.Attribute("DataWidth").Value);

                    var tempLink = new SystemStruLink(i
                                                      , int.Parse(link.Attribute("FirstEndPos").Value)
                                                      , int.Parse(link.Attribute("SecondEndId").Value)
                                                      , int.Parse(link.Attribute("SecondEndPos").Value)
                                                      , type
                                                      , laneNum);
                    linksList.Add(tempLink);
                }
                sys.LinksArray[i] = linksList;
            }
            return(sys);
        }