管道基础大数据平台系统开发-【CS】-ExportMap
13693261870
2024-09-03 3cfb6aa02516135fb174ab1b30620f2007924663
ExportMap/cs/TBUtils.cs
@@ -41,33 +41,77 @@
            }
        }
        private static bool isBusy = false;
        /// <summary>
        /// 创建MPT
        /// 创建Mpt
        /// </summary>
        public static string CreateMpt(string sourcePath, ref string err)
        {
            string time = TimeStr;
            string targetPath = Path.Combine(Tools.TempDir, time);
            try
            {
                if (isBusy) throw new Exception("已有一个生成Mpt的任务正在执行");
                isBusy = true;
                string targetPath = Path.Combine(Tools.TempDir, time);
                if (!Directory.Exists(targetPath)) Directory.CreateDirectory(targetPath);
                MoveFilesToTemp(sourcePath, targetPath);
                string tbp = GetNewTbp(time);
                string js = GetNewJs(time, tbp, targetPath);
                return null;
                ReloadTB();
                //string cmd = string.Format("\"C:\\Program Files\\Skyline\\TerraBuilder\\TerraBuilder.exe\" -script \"{0}\"", js); // -DisablePrint
                //err = Tools.ExecCmd(new List<string> { cmd });
                err = Tools.ExecExe("\"C:/Program Files/Skyline/TerraBuilder/TerraBuilder.exe\"", string.Format("-script \"{0}\"", js));
                isBusy = false;
                return File.Exists(MptPath) ? MoveMpt(MptPath, sourcePath) : null;
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
                err = ex.Message;
                isBusy = false;
                return null;
            }
            finally
            {
                if (Directory.Exists(targetPath)) Directory.Delete(targetPath, true);
                ending(time, sourcePath);
            }
        }
        /// <summary>
        /// 测试
        /// </summary>
        public static bool Test(ref string err)
        {
            string time = TimeStr;
            try
            {
                if (isBusy) throw new Exception("已有一个生成Mpt的任务正在执行");
                isBusy = true;
                string js = Path.Combine(SourcesPath, "tb.js");
                string newTbp = Path.Combine(Tools.TempDir, time, time + ".tbp");
                File.Copy(Path.Combine(SourcesPath, "tb.tbp"), Path.Combine(SourcesPath, "tb01.tbp"), true);
                //string cmd = string.Format("\"C:/Program Files/Skyline/TerraBuilder/TerraBuilder.exe\" -script \"{0}\"", js); // -DisablePrint
                ReloadTB();
                //err = Tools.ExecCmdForWin(new List<string> { cmd });
                err = Tools.ExecExe("\"C:/Program Files/Skyline/TerraBuilder/TerraBuilder.exe\"", string.Format("-script \"{0}\"", js), false);
                isBusy = false;
                return File.Exists(MptPath);
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
                err = ex.Message;
                isBusy = false;
                return false;
            }
        }
@@ -89,15 +133,16 @@
        /// </summary>
        private static void MoveFilesToTemp(string sourcePath, string targetPath)
        {
            CopyFolder(Path.Combine(sourcePath, "数字正射影像图"), Path.Combine(targetPath, "img"));
            CopyFolder(Path.Combine(sourcePath, "数字高程模型"), Path.Combine(targetPath, "dem"));
            CopyFolder(Path.Combine(sourcePath, "中线裁剪范围"), Path.Combine(targetPath, "shp"));
            LogOut.Info("TB.移动文件 -> " + sourcePath);
            MoveFolder(Path.Combine(sourcePath, "数字正射影像图"), Path.Combine(targetPath, "img"));
            MoveFolder(Path.Combine(sourcePath, "数字高程模型"), Path.Combine(targetPath, "dem"));
            MoveFolder(Path.Combine(sourcePath, "中线裁剪范围"), Path.Combine(targetPath, "shp"));
        }
        /// <summary>
        /// 复制目录
        /// 移动目录
        /// </summary>
        private static void CopyFolder(string sourcePath, string targetPath)
        private static void MoveFolder(string sourcePath, string targetPath)
        {
            if (!Directory.Exists(targetPath)) Directory.CreateDirectory(targetPath);
@@ -153,10 +198,66 @@
        {
            List<string> list = new List<string>();
            list.Add("taskkill /f /t /im TerraBuilder.exe");
            list.Add("taskkill /f /t /im TBFuser.exe");
            list.Add("start /d \"C:\\Program Files\\Skyline\\TerraBuilder Fuser\" TBFuser.exe");
            //list.Add("taskkill /f /t /im TBFuser.exe");
            //list.Add("start /d \"C:\\Program Files\\Skyline\\TerraBuilder Fuser\" TBFuser.exe /b");
            Tools.ExecCmd(list, false);
            Tools.ExecCmd(list);
        }
        /// <summary>
        /// 移动Mpt文件
        /// </summary>
        private static string MoveMpt(string mpt, string targetPath)
        {
            string path = Path.Combine(targetPath, "Mpt");
            if (!Directory.Exists(path)) Directory.CreateDirectory(path);
            FileInfo fi = new FileInfo(mpt);
            string newMpt = Path.Combine(path, fi.Name);
            File.Move(mpt, newMpt);
            string mIdx = mpt.Replace(".mpt", ".mIdx");
            if (File.Exists(mIdx)) File.Move(mIdx, newMpt.Replace(".mpt", ".mIdx"));
            string Strmi = mpt.Replace(".mpt", ".Strmi");
            if (File.Exists(Strmi)) File.Move(Strmi, newMpt.Replace(".mpt", ".Strmi"));
            return newMpt;
        }
        /// <summary>
        /// 收尾工作
        /// </summary>
        private static void ending(string time, string sourcePath)
        {
            try
            {
                string path = Path.Combine(Tools.TempDir, time);
                if (!Directory.Exists(path)) return;
                string img = GetFilePath(Path.Combine(path, "img"), "*.tif");
                if (null != img) MoveFile(img, Path.Combine(sourcePath, "数字正射影像图"));
                string dem = GetFilePath(Path.Combine(path, "dem"), "*.tif");
                if (null != dem) MoveFile(dem, Path.Combine(sourcePath, "数字高程模型"));
                MoveFolder(Path.Combine(path, "shp"), Path.Combine(sourcePath, "中线裁剪范围"));
                Directory.Delete(path, true);
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
            }
        }
        /// <summary>
        /// 移动文件
        /// </summary>
        private static void MoveFile(string file, string targetPath)
        {
            FileInfo fi = new FileInfo(file);
            File.Move(file, Path.Combine(targetPath, fi.Name));
        }
    }
}