| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取时间客串 |
| | | /// 时间字符串 |
| | | /// </summary> |
| | | public static string GetTime |
| | | public static string TimeStr |
| | | { |
| | | get |
| | | { |
| | |
| | | /// <summary> |
| | | /// 创建MPT |
| | | /// </summary> |
| | | public static string CreateMpt(string path, ref string err) |
| | | public static string CreateMpt(string sourcePath, ref string err) |
| | | { |
| | | string tbp = null; |
| | | string time = TimeStr; |
| | | string targetPath = Path.Combine(Tools.TempDir, time); |
| | | |
| | | try |
| | | { |
| | | tbp = GetNewTbp(); |
| | | if (!Directory.Exists(targetPath)) Directory.CreateDirectory(targetPath); |
| | | |
| | | MoveFilesToTemp(sourcePath, targetPath); |
| | | string tbp = GetNewTbp(time); |
| | | string js = GetNewJs(time, tbp, targetPath); |
| | | |
| | | return null; |
| | | } |
| | |
| | | } |
| | | finally |
| | | { |
| | | if (tbp != null && File.Exists(tbp)) File.Delete(tbp); |
| | | |
| | | if (Directory.Exists(targetPath)) Directory.Delete(targetPath, true); |
| | | } |
| | | } |
| | | |
| | | /// <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) |
| | | { |
| | | string imgPath = Path.Combine(targetPath, "img"); |
| | | //if (!Directory.Exists(imgPath)) Directory.CreateDirectory(imgPath); |
| | | |
| | | string demPath = Path.Combine(targetPath, "dem"); |
| | | //if (!Directory.Exists(demPath)) Directory.CreateDirectory(demPath); |
| | | |
| | | string shpPath = Path.Combine(targetPath, "shp"); |
| | | //if (!Directory.Exists(shpPath)) Directory.CreateDirectory(shpPath); |
| | | |
| | | File.Move(Path.Combine(sourcePath, "数字正射影像图"), imgPath); |
| | | File.Move(Path.Combine(sourcePath, "数字高程模型"), demPath); |
| | | File.Move(Path.Combine(sourcePath, "中线裁剪范围"), shpPath); |
| | | } |
| | | |
| | | /// <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> |
| | | /// 重启TB程序 |
| | | /// </summary> |
| | | private static void ReloadTB() |