Beispiel #1
0
        /// <summary> 更换案例路径 P1= D:\WorkArea\3106  P2 = D:\WorkArea\数值模拟</summary>
        public void ChangePath(SimONData _simONData, string newFullPath, string tempOld)
        {
            string caseName = Path.GetFileNameWithoutExtension(newFullPath);


            string tempPath = Path.Combine(newFullPath, caseName);//  E:\\aaaa\\aaaa

            _simONData.FilePath = tempOld + KeyConfiger.SimONExtend;

            string oldFile = Path.Combine(newFullPath, Path.GetFileName(_simONData.FilePath)); //  E:\\aaaa\\数值模拟.dat

            string newStr = Path.Combine(newFullPath, caseName + Path.GetExtension(oldFile));  //  E:\\aaaa\\aaaa.dat

            // Todo :更改文件路径  E:\\数值模拟\\数值模拟_prd.dat To:E:\\aaaa\\aaaa_prd.dat
            Func <string, string> replace = old => old.Replace(tempOld, tempPath);

            string oldCaseName = Path.GetFileNameWithoutExtension(_simONData.FilePath);//    数值模拟

            // Todo :重新保存一份主文件 不加载INCLUDE 只处理主文件
            SimONData tempSimon = FileFactoryService.Instance.ThreadLoadFunc <SimONData>(() => new SimONData(newStr, null, k => false));
            var       allInc    = tempSimon.Key.FindAll <INCLUDE>();

            foreach (var item in allInc)
            {
                // Todo :不保存 防止覆盖原INCLUDE文件
                item.IsCreateFile = false;
                item.FileName     = item.FileName.Replace(oldCaseName, caseName);
                item.FilePath     = replace(item.FilePath);
            }
            tempSimon.Save();

            // Todo :修改所有INCLUDE文件名
            List <INCLUDE> includes = _simONData.Key.FindAll <INCLUDE>();

            foreach (var item in includes)
            {
                string includePath = Path.Combine(newFullPath, item.FileName);
                File.Move(includePath, replace(item.FilePath));
                item.FileName = item.FileName.Replace(oldCaseName, caseName);
                item.FilePath = replace(item.FilePath);
            }

            _simONData.FilePath = newStr;


            string hist = tempPath + KeyConfiger.HistroyFileName;

            string oldhist = Path.Combine(newFullPath, oldCaseName) + KeyConfiger.HistroyFileName;

            File.Move(oldhist, hist);
        }
        public static void ReName(this SimONData ecl, string oldFullPath, string newFullPath)
        {
            string oldCaseName = Path.GetFileName(oldFullPath);

            string caseName = Path.GetFileName(newFullPath);

            string oldPath = Path.GetDirectoryName(oldFullPath);

            string newPath = Path.GetDirectoryName(newFullPath);

            // Todo :更改主文件名称
            if (File.Exists(oldFullPath))
            {
                string newStr = newFullPath;//  E:\\aaaa\\aaaa.dat

                File.Move(oldFullPath, newFullPath);

                // Todo :重新保存一份主文件 不加载INCLUDE 只处理主文件
                SimONData tempSimon = FileFactoryService.Instance.ThreadLoadFunc <SimONData>(() => new SimONData(newStr, null, k => false));
                var       allInc    = tempSimon.Key.FindAll <INCLUDE>();

                foreach (var item in allInc)
                {
                    // Todo :不保存 防止覆盖原INCLUDE文件
                    item.IsCreateFile = false;
                    item.FileName     = item.FileName.Replace(oldCaseName, caseName);
                    //item.FilePath = item.FilePath.Replace(oldPath, newPath);
                }
                tempSimon.Save();

                // Todo :修改所有INCLUDE文件名
                List <INCLUDE> includes = ecl.Key.FindAll <INCLUDE>();

                foreach (var item in includes)
                {
                    string includePath    = Path.Combine(oldPath, item.FileName);
                    string includePathNew = Path.Combine(newPath, item.FileName);
                    File.Move(includePath, includePathNew);
                }

                ecl.FilePath = newStr;
            }
        }