From 2bdf37bae40dd37a90363679be3245cad797769a Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期二, 24 十月 2023 17:35:19 +0800
Subject: [PATCH] 测试TB生成MPT功能

---
 ExportMap/TerraBuilder/tb.js          |    6 +-
 ExportMap/cs/TBUtils.cs               |   37 +++++++++++-
 ExportMap/Controllers/TBController.cs |   43 ++++++++++++++
 ExportMap/cs/Tools.cs                 |   22 +-----
 ExportMap/ExportMap.csproj            |    1 
 ExportMap/TerraBuilder/说明.txt         |   15 +++++
 6 files changed, 101 insertions(+), 23 deletions(-)

diff --git a/ExportMap/Controllers/TBController.cs b/ExportMap/Controllers/TBController.cs
index a181217..6c9d451 100644
--- a/ExportMap/Controllers/TBController.cs
+++ b/ExportMap/Controllers/TBController.cs
@@ -7,6 +7,8 @@
 using System.Net.Http;
 using System.Web.Http;
 using System.IO;
+using System.Diagnostics;
+using System.Threading;
 
 namespace ExportMap.Controllers
 {
@@ -36,5 +38,46 @@
                 return ResponseMsg<string>.fail(ex.Message);
             }
         }
+
+        [HttpGet] // http://localhost/ExportMap/TB/Test
+        public ResponseMsg<string> Test()
+        {
+            try
+            {
+                Stopwatch sw = new Stopwatch();
+                sw.Start();
+                string err = null;
+                bool rs = TBUtils.Test(ref err);
+                sw.Stop();
+
+                return ResponseMsg<string>.success((rs ? "鎴愬姛" : "澶辫触") + "锛岃�楁椂锛�" + sw.ElapsedMilliseconds / 1000.0 + " s", rs.ToString());
+            }
+            catch (Exception ex)
+            {
+                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
+                return ResponseMsg<string>.fail(ex.Message);
+            }
+        }
+
+        [HttpGet]
+        public ResponseMsg<string> Wait(long seconds)
+        {
+            try
+            {
+                Stopwatch sw = new Stopwatch();
+                sw.Start();
+
+                Thread.Sleep(new TimeSpan(seconds * 10 * 1000 * 1000));
+
+                sw.Stop();
+
+                return ResponseMsg<string>.success("鎴愬姛", "鑰楁椂锛�" + sw.ElapsedMilliseconds / 1000.0 + " s");
+            }
+            catch (Exception ex)
+            {
+                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
+                return ResponseMsg<string>.fail(ex.Message);
+            }
+        }
     }
 }
diff --git a/ExportMap/ExportMap.csproj b/ExportMap/ExportMap.csproj
index fb26561..15a64ea 100644
--- a/ExportMap/ExportMap.csproj
+++ b/ExportMap/ExportMap.csproj
@@ -130,6 +130,7 @@
     <Content Include="Sources\璇存槑.txt" />
     <Content Include="TerraBuilder\tb.js" />
     <Content Include="TerraBuilder\template.js" />
+    <Content Include="TerraBuilder\璇存槑.txt" />
     <Content Include="UE.html" />
     <Content Include="up.html" />
     <Content Include="Web.config">
diff --git a/ExportMap/TerraBuilder/tb.js b/ExportMap/TerraBuilder/tb.js
index 3148eb8..f85ef2e 100644
--- a/ExportMap/TerraBuilder/tb.js
+++ b/ExportMap/TerraBuilder/tb.js
@@ -3,7 +3,7 @@
     var project = TerraBuilder.OpenProject("E:\\terrait\\TianJin\\ExportMap\\ExportMap\\TerraBuilder\\tb01.tbp");
     var shp = "D:\\LF\\data\\shp\\buffer_midline.shp";
 
-    var imgLayer = project.Layers.InsertLayer("D:\\LF\\data\\DOM\\CABQ_0641.tif", "imagery");
+    var imgLayer = project.Layers.InsertLayer("D:\\LF\\data\\DOM\\D0M_M.tif", "imagery");
     if (null != imgLayer) {
         imgLayer.ImageryPyramidFormat = 0;
 
@@ -16,7 +16,7 @@
         poly2.type = 0;
     }
 
-    var eleLayer = project.Layers.InsertLayer("D:\\LF\\data\\DEM\\DEM.tif", "Elevation");
+    var eleLayer = project.Layers.InsertLayer("D:\\LF\\data\\DEM\\DEM_M.tif", "Elevation");
     if (null != eleLayer) {
         eleLayer.ElevationPyramidFormat = 0;
 
@@ -34,8 +34,8 @@
         poly3.type = 0;
     }
 
-    project.CreateResolutionPyramids();
     //project.Settings.MPTFileName = "D:\\LF\\data\\mpt\\0A.MPT";
+    project.CreateResolutionPyramids();
 
     //project.Save();
     project.CreateMPT();
diff --git "a/ExportMap/TerraBuilder/\350\257\264\346\230\216.txt" "b/ExportMap/TerraBuilder/\350\257\264\346\230\216.txt"
new file mode 100644
index 0000000..9c9749d
--- /dev/null
+++ "b/ExportMap/TerraBuilder/\350\257\264\346\230\216.txt"
@@ -0,0 +1,15 @@
+cmd:
+cd "C:/Program Files/Skyline/TerraBuilder"
+
+TerraBuilder.exe -script E:/terrait/TianJin/ExportMap/ExportMap/TerraBuilder/tb.js
+
+
+D:\LF\data\DOM
+D:\LF\data\DEM
+D:\LF\data\mpt
+E:\terrait\TianJin\ExportMap\ExportMap\TerraBuilder
+
+
+http://localhost/ExportMap/TB/Test
+
+http://localhost/ExportMap/TB/Wait?seconds=30
diff --git a/ExportMap/cs/TBUtils.cs b/ExportMap/cs/TBUtils.cs
index 604bb37..e5398d6 100644
--- a/ExportMap/cs/TBUtils.cs
+++ b/ExportMap/cs/TBUtils.cs
@@ -49,7 +49,6 @@
         public static string CreateMpt(string sourcePath, ref string err)
         {
             string time = TimeStr;
-
             try
             {
                 if (isBusy) throw new Exception("宸叉湁涓�涓敓鎴怣pt鐨勪换鍔℃鍦ㄦ墽琛�");
@@ -62,9 +61,10 @@
                 string tbp = GetNewTbp(time);
                 string js = GetNewJs(time, tbp, targetPath);
 
-                string cmd = string.Format("\"C:\\Program Files\\Skyline\\TerraBuilder\\TerraBuilder.exe\" -script \"{0}\"", js); // -DisablePrint
                 ReloadTB();
-                err = Tools.ExecCmdForWin(new List<string> { cmd });
+                //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;
@@ -83,6 +83,37 @@
         }
 
         /// <summary>
+        /// 娴嬭瘯
+        /// </summary>
+        public static bool Test(ref string err)
+        {
+            string time = TimeStr;
+            try
+            {
+                if (isBusy) throw new Exception("宸叉湁涓�涓敓鎴怣pt鐨勪换鍔℃鍦ㄦ墽琛�");
+
+                isBusy = true;
+                string js = "E:/terrait/TianJin/ExportMap/ExportMap/TerraBuilder/tb.js";
+                File.Copy("E:/terrait/TianJin/ExportMap/ExportMap/TerraBuilder/tb.tbp", "E:/terrait/TianJin/ExportMap/ExportMap/TerraBuilder/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("D:/LF/data/mpt/tb.mpt");
+            }
+            catch (Exception ex)
+            {
+                LogOut.Error(ex.Message + "\r\n" + ex.StackTrace);
+                err = ex.Message;
+                isBusy = false;
+                return false;
+            }
+        }
+
+        /// <summary>
         /// 鑾峰彇鏂癟bp鏂囦欢
         /// </summary>
         private static string GetNewTbp(string time)
diff --git a/ExportMap/cs/Tools.cs b/ExportMap/cs/Tools.cs
index 4b7dc85..fc981b3 100644
--- a/ExportMap/cs/Tools.cs
+++ b/ExportMap/cs/Tools.cs
@@ -377,35 +377,23 @@
         /// 鎵ц鍛戒护
         /// </summary>
         /// <param name="list">鍛戒护闆嗗悎</param>
-        public static string ExecCmdForWin(List<string> list, bool noWin = false)
+        public static string ExecExe(string exe, string args, bool noWin = true)
         {
             string str = null;
             Process p = null;
             try
             {
                 p = new Process();
-                p.StartInfo.FileName = "cmd.exe";
+                p.StartInfo.FileName = exe;
                 p.StartInfo.UseShellExecute = false;
                 p.StartInfo.CreateNoWindow = noWin;
                 p.StartInfo.RedirectStandardInput = true;
                 p.StartInfo.RedirectStandardOutput = true;
                 p.StartInfo.RedirectStandardError = true;
+                if (!string.IsNullOrEmpty(args)) p.StartInfo.Arguments = args;
+
                 p.Start();
-
-                StreamWriter si = p.StandardInput;
-                StreamReader se = p.StandardError;
-
-                LogOut.Info("cmd = " + string.Join("锛�", list));
-                si.AutoFlush = true;
-                foreach (string cmd in list)
-                {
-                    si.WriteLine(cmd);
-                }
-                si.WriteLine("exit");
-
-                str = se.ReadToEnd();
-                se.Close();
-                si.Close();
+                p.WaitForExit();
             }
             catch (Exception ex)
             {

--
Gitblit v1.9.3