From 59e20195f258309757ee73f406936d05079896d9 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期四, 24 八月 2023 14:33:10 +0800 Subject: [PATCH] 修改常量、复制单文件、多文件方法 --- DataLoader/CS/Importor.cs | 122 ++++++++++++++++++++++++++++++++++++++-- 1 files changed, 114 insertions(+), 8 deletions(-) diff --git a/DataLoader/CS/Importor.cs b/DataLoader/CS/Importor.cs index 5a717d0..845ad19 100644 --- a/DataLoader/CS/Importor.cs +++ b/DataLoader/CS/Importor.cs @@ -332,19 +332,125 @@ /// </summary> private static void CopyFiles(ViewData vd) { - //mf.path = subPath + "\\" + mf.name; + if (string.IsNullOrEmpty(vd.Meta.guid)) vd.Meta.guid = vd.Meta.eventid; - //if (File.Exists(source)) - //{ - // File.Copy(source, target, true); - //} + switch (vd.Ext) + { + case StaticData.MPT: + copyMultiFile(vd, StaticData.MPT_EXT); + break; + case StaticData.JPG: + copyMultiFile(vd, StaticData.JPG_EXT); + break; + case StaticData.IMG: + copyMultiFile(vd, StaticData.IMG_EXT); + break; + case StaticData.TIF: + copyMultiFile(vd, StaticData.TIF_EXT); + break; + case StaticData.TIFF: + copyMultiFile(vd, StaticData.TIFF_EXT); + break; + case StaticData.SHP: + copyMultiFile(vd, StaticData.SHP_EXT); + break; + case StaticData.OSGB: + copyFolderFile(vd); + break; + case StaticData.GDB: + copyFolderFile(vd); + break; + default: + copySingleFile(vd); + break; + } } - private static int GetSubPath(string target, int start = 1) + /// <summary> + /// 澶嶅埗鏂囦欢澶� + /// </summary> + private static int copyFolderFile(ViewData vd) { + if (!Directory.Exists(vd.FilePath)) return -1; + + int count = 0; + string[] files = Directory.GetFiles(vd.FilePath, "*", SearchOption.AllDirectories); + foreach (string file in files) + { + try + { + // + count++; + } + catch (Exception ex) + { + LogOut.Error(ex.StackTrace); + } + } + + return count; + } + + /// <summary> + /// 澶嶅埗澶氫釜鏂囦欢 + /// </summary> + private static int copyMultiFile(ViewData vd, List<string> exts) + { + int count = copySingleFile(vd); + if (count < 0) return -1; + + string target = Path.Combine(CommonProp.TargetPath, vd.Meta.path); + foreach (string ext in exts) + { + try + { + File.Copy(vd.FilePath.Replace(vd.Ext, ext), target.Replace(vd.Ext, ext), true); + count++; + } + catch (Exception ex) + { + LogOut.Error(ex.StackTrace); + } + } + + return count; + } + + /// <summary> + /// 澶嶅埗鍗曟枃浠� + /// </summary> + private static int copySingleFile(ViewData vd) + { + if (!File.Exists(vd.FilePath)) return -1; + + vd.Meta.path = Path.Combine("" + GetSubPath(), vd.Meta.guid + vd.Ext); + string target = Path.Combine(CommonProp.TargetPath, vd.Meta.path); + if (File.Exists(target)) return 0; + + try + { + File.Copy(vd.FilePath, target, true); + + return 1; + } + catch (Exception ex) + { + LogOut.Error(ex.StackTrace); + return -1; + } + } + + /// <summary> + /// 鑾峰彇瀛愮洰褰� + /// </summary> + private static int GetSubPath() + { + int start = 0; + int.TryParse(Tools.GetSetting("StartPath"), out start); + while (true) { - string path = Path.Combine(target, start.ToString()); + string path = Path.Combine(CommonProp.TargetPath, start.ToString()); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); @@ -352,7 +458,7 @@ } string[] files = Directory.GetFiles(path); - if (files.Length < 2001) + if (files.Length <= StaticData.MAX_FILES) { return start; } -- Gitblit v1.9.3