From a9d3642f93bdb25b5d72c8e28ee14d66ac7c4ea3 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期二, 27 六月 2023 17:21:25 +0800 Subject: [PATCH] 将TerraBuilder自动化创建mpt程序包装成Web服务 --- ExportMap/cs/TBUtils.cs | 19 ++++++++++++------- ExportMap/Controllers/TBController.cs | 14 ++++++-------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/ExportMap/Controllers/TBController.cs b/ExportMap/Controllers/TBController.cs index 65cb8df..a181217 100644 --- a/ExportMap/Controllers/TBController.cs +++ b/ExportMap/Controllers/TBController.cs @@ -17,18 +17,16 @@ { try { - if (string.IsNullOrEmpty(path) || string.IsNullOrEmpty(token)) - return ResponseMsg<string>.fail("path鍜宼oken鍙傛暟涓嶈兘涓虹┖"); - if (!ExportUtil.VerifyToken(token)) - return ResponseMsg<string>.fail("浠ょ墝鏃犳晥"); - if (!Directory.Exists(path)) - return ResponseMsg<string>.fail("鏂囦欢璺緞涓嶅瓨鍦�"); + if (string.IsNullOrEmpty(path) || string.IsNullOrEmpty(token)) return ResponseMsg<string>.fail("path鍜宼oken鍙傛暟涓嶈兘涓虹┖"); + + if (!ExportUtil.VerifyToken(token)) return ResponseMsg<string>.fail("浠ょ墝鏃犳晥"); + + if (!Directory.Exists(path)) return ResponseMsg<string>.fail("鏂囦欢璺緞涓嶅瓨鍦�"); string err = null; string rs = TBUtils.CreateMpt(path, ref err); - if (string.IsNullOrEmpty(rs)) - return ResponseMsg<string>.fail(null == err ? "澶辫触" : err); + if (string.IsNullOrEmpty(rs)) return ResponseMsg<string>.fail(null == err ? "澶辫触" : err); return ResponseMsg<string>.success("鎴愬姛", rs, 1); } diff --git a/ExportMap/cs/TBUtils.cs b/ExportMap/cs/TBUtils.cs index eb85942..26a139d 100644 --- a/ExportMap/cs/TBUtils.cs +++ b/ExportMap/cs/TBUtils.cs @@ -41,6 +41,8 @@ } } + private static bool isBusy = false; + /// <summary> /// 鍒涘缓Mpt /// </summary> @@ -50,6 +52,9 @@ try { + if (isBusy) throw new Exception("宸叉湁涓�涓敓鎴怣pt鐨勪换鍔℃鍦ㄦ墽琛�"); + + isBusy = true; string targetPath = Path.Combine(Tools.TempDir, time); if (!Directory.Exists(targetPath)) Directory.CreateDirectory(targetPath); @@ -60,17 +65,15 @@ string cmd = string.Format("\"C:\\Program Files\\Skyline\\TerraBuilder\\TerraBuilder.exe\" -script \"{0}\"", js); // -DisablePrint ReloadTB(); err = Tools.ExecCmd(cmd, false, false); - if (File.Exists(MptPath)) - { - return MoveMpt(MptPath, sourcePath); - } + isBusy = false; - return null; + 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 @@ -161,8 +164,8 @@ { 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); } @@ -205,6 +208,8 @@ if (null != dem) MoveFile(dem, Path.Combine(sourcePath, "鏁板瓧楂樼▼妯″瀷")); MoveFolder(Path.Combine(path, "shp"), Path.Combine(sourcePath, "涓嚎瑁佸壀鑼冨洿")); + + Directory.Delete(path, true); } catch (Exception ex) { -- Gitblit v1.9.3