Exemple #1
0
        //网络保存为文件
        public Error Save(string sPath)
        {
            string strExpand;
            XmlDocument doc;
            IfIOStrategy Saver;

            //1.获取扩展名
            strExpand = GetExpandName(sPath).ToLower();
            //2.选定保存算法
            switch (strExpand)
            {
                case ".sst":
                    Saver = new SSTStrategy();
                    break;
                case ".xml":
                    Saver = new XMLStrategy();
                    break;
                case ".tri":
                    Saver = new TRIStrategy();
                    break;
                case ".mat":
                    Saver = new MATStrategy();
                    break;
                default:
                    return new Error("文件格式错误");
            }
            //所有网络数据都保存为xml格式
            doc = this.ToXML();
            Saver.SaveFile(doc, sPath);
            return new Error("OK");
        }
Exemple #2
0
        //网络文件读取函数
        public static cNet Read(string sPath,ref Error eRet)
        {
            string strExpand;
            cNet NewNet;
            IfIOStrategy Reader;
			
            //1.获取扩展名
            strExpand = cNet.GetExpandName(sPath).ToLower();
            //2.选定构造算法
            switch (strExpand)
            {
                case ".sst":
                    Reader = new SSTStrategy();
                    break;
                case ".xml":
                    Reader = new XMLStrategy();
                    break;
                case ".tri":
                    Reader = new TRIStrategy();
                    break;
                case ".mat":
                    Reader = new MATStrategy();
                    break;
                case ".kwt":
                    Reader = new KWTStrategy();
                    break;
                default:
                    eRet = new Error("文件格式错误");
                    return null;
            }
			
            //3.构造网络
            NewNet = Reader.ReadFile(sPath);
            if (NewNet == null)
            {
                eRet = new Error("文件格式错误");
            }
            else
            {
                eRet = new Error("OK");
            }
            return NewNet;
        }