| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取时间客串 |
| | | /// 时间字符串 |
| | | /// </summary> |
| | | public static string GetTime |
| | | public static string TimeStr |
| | | { |
| | | get |
| | | { |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 创建MPT |
| | | /// Mpt路径 |
| | | /// </summary> |
| | | public static string CreateMpt(string path, ref string err) |
| | | public static string MptPath |
| | | { |
| | | string tbp = null; |
| | | get |
| | | { |
| | | return Tools.GetSetting("mpt"); |
| | | } |
| | | } |
| | | |
| | | private static bool isBusy = false; |
| | | |
| | | /// <summary> |
| | | /// 创建Mpt |
| | | /// </summary> |
| | | public static string CreateMpt(string sourcePath, ref string err) |
| | | { |
| | | string time = TimeStr; |
| | | |
| | | try |
| | | { |
| | | tbp = GetNewTbp(); |
| | | if (isBusy) throw new Exception("已有一个生成Mpt的任务正在执行"); |
| | | |
| | | isBusy = true; |
| | | string targetPath = Path.Combine(Tools.TempDir, time); |
| | | if (!Directory.Exists(targetPath)) Directory.CreateDirectory(targetPath); |
| | | |
| | | return null; |
| | | MoveFilesToTemp(sourcePath, targetPath); |
| | | 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 }); |
| | | 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 (tbp != null && File.Exists(tbp)) File.Delete(tbp); |
| | | |
| | | ending(time, sourcePath); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取新Tbp文件 |
| | | /// </summary> |
| | | private static string GetNewTbp() |
| | | private static string GetNewTbp(string time) |
| | | { |
| | | string tbp = Path.Combine(SourcesPath, "tb.tbp"); |
| | | string newTbp = Path.Combine(SourcesPath, GetTime + ".tbp"); |
| | | string newTbp = Path.Combine(Tools.TempDir, time, time + ".tbp"); |
| | | |
| | | File.Copy(tbp, newTbp); |
| | | |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 移动文件至临时目录 |
| | | /// </summary> |
| | | private static void MoveFilesToTemp(string sourcePath, string targetPath) |
| | | { |
| | | 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 MoveFolder(string sourcePath, string targetPath) |
| | | { |
| | | if (!Directory.Exists(targetPath)) Directory.CreateDirectory(targetPath); |
| | | |
| | | DirectoryInfo di = new DirectoryInfo(sourcePath); |
| | | |
| | | FileInfo[] files = di.GetFiles(); |
| | | if (null == files || 0 == files.Length) return; |
| | | |
| | | foreach (FileInfo fi in files) |
| | | { |
| | | File.Move(fi.FullName, Path.Combine(targetPath, fi.Name)); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取新JS |
| | | /// </summary> |
| | | private static string GetNewJs(string tbp, string shp, string img, string dem) |
| | | private static string GetNewJs(string time, string tbp, string targetPath) |
| | | { |
| | | string js = Path.Combine(SourcesPath, "template.js"); |
| | | string img = GetFilePath(Path.Combine(targetPath, "img"), "*.tif"); |
| | | string dem = GetFilePath(Path.Combine(targetPath, "dem"), "*.tif"); |
| | | string shp = GetFilePath(Path.Combine(targetPath, "shp"), "*.shp"); |
| | | |
| | | string str = File.ReadAllText(js); |
| | | str = str.Replace("{tbp}", tbp) |
| | | .Replace("{shp}", shp) |
| | | .Replace("{img}", img) |
| | | .Replace("{dem}", dem) |
| | | .Replace("{shp}", shp) |
| | | .Replace("\\", "\\\\"); |
| | | |
| | | string newJs = Path.Combine(SourcesPath, GetTime + ".js"); |
| | | string newJs = Path.Combine(Tools.TempDir, time, time + ".js"); |
| | | File.WriteAllText(newJs, str); |
| | | |
| | | return newJs; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取文件路径 |
| | | /// </summary> |
| | | private static string GetFilePath(string path, string ext) |
| | | { |
| | | DirectoryInfo di = new DirectoryInfo(path); |
| | | FileInfo[] files = di.GetFiles(ext); |
| | | |
| | | return null == files || 0 == files.Length ? string.Empty : files[0].FullName; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | 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)); |
| | | } |
| | | } |
| | | } |