Exemplo n.º 1
0
        public void LoadXRefList(ref string msg)
        {
            try
            {
                XmlDocument docXRef = new XmlDocument();
                XmlDocument docXShm = new XmlDocument();
                if (File.Exists(XRefListPath))
                {
                    docXRef.Load(XRefListPath);
                }
                if (File.Exists(XShmListPath))
                {
                    docXShm.Load(XShmListPath);
                }

                // initialize blocklist
                BlockListMgr.Init(docXRef.SelectNodes("xref//Blocks//Block"));
                IOAddressMgr.Init(docXRef.SelectNodes("xref//IOConnections//Connection"));
                CompoundBlockMgr.Init(docXRef.SelectNodes("xref//CompoundBlocks//CompoundBlock"));
                BuildListMgr.Init(docXRef.SelectNodes("xref//BuildManager//Plan"));
                // force to save if file not exist
                if (!File.Exists(XRefListPath))
                {
                    BlockListMgr.Dirty = true;
                }

                // initialize shared memory list
                XmlNodeList ShmVariableList = docXShm.SelectNodes("xref//SharedMemory//Variable");
                SharedMemoryMgr.Init(ShmVariableList, ref msg);
                if (!string.IsNullOrEmpty(msg))
                {
                    // loaded from PIV file, force to save to new file
                    SharedMemoryMgr.Dirty = true;
                }
                else
                {
                    // check is old version xref.data or not. In new version, xref.data is seperated
                    // into xref.data & xshm.data two files.
                    if (ShmVariableList == null || ShmVariableList.Count <= 0)
                    {
                        XmlNodeList RefVariableList = docXRef.SelectNodes("xref//SharedMemory//Variable");
                        if (RefVariableList != null && RefVariableList.Count > 0)
                        {
                            SharedMemoryMgr.Init(RefVariableList, ref msg);
                            msg = "A shared memory variable database from xref.data was imported into xshm.data.";
                            // loaded from PIV file, force to save to new file
                            BlockListMgr.Dirty    = true;
                            SharedMemoryMgr.Dirty = true;
                        }
                    }
                }
                // force to save if file not exist
                if (!File.Exists(XShmListPath))
                {
                    SharedMemoryMgr.Dirty = true;
                }
            }
            catch (Exception)
            {
            }
        }