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 ++++++++++++++++++++++++++++++++++++++-- JavaCode/App.config | 4 DataLoader/CS/StaticData.cs | 34 ++++++----- 3 files changed, 134 insertions(+), 26 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; } diff --git a/DataLoader/CS/StaticData.cs b/DataLoader/CS/StaticData.cs index 8b7764f..f03709d 100644 --- a/DataLoader/CS/StaticData.cs +++ b/DataLoader/CS/StaticData.cs @@ -6,37 +6,39 @@ { public class StaticData { + public const int MAX_FILES = 2000; + public static String ADMIN = "admin"; - public readonly static String ZIP = ".zip"; + public const String ZIP = ".zip"; - public readonly static String XLS = ".xls"; + public const String XLS = ".xls"; - public readonly static String XLSX = ".xlsx"; + public const String XLSX = ".xlsx"; - public readonly static String MDB = ".mdb"; + public const String MDB = ".mdb"; - public readonly static String SHP = ".shp"; + public const String SHP = ".shp"; - public readonly static String NGDB = "gdb"; + public const String NGDB = "gdb"; - public readonly static String GDB = ".gdb"; + public const String GDB = ".gdb"; - public readonly static String JPG = ".jpg"; + public const String JPG = ".jpg"; - public readonly static String IMG = ".img"; + public const String IMG = ".img"; - public readonly static String MPT = ".mpt"; + public const String MPT = ".mpt"; - public readonly static String D3DML = ".3dml"; + public const String D3DML = ".3dml"; - public readonly static String TIF = ".tif"; + public const String TIF = ".tif"; - public readonly static String TIFF = ".tiff"; + public const String TIFF = ".tiff"; - public readonly static String LAS = ".las"; + public const String LAS = ".las"; - public readonly static String OSGB = ".osgb"; + public const String OSGB = ".osgb"; /// <summary> /// 鏍呮牸鏁版嵁鎵╁睍鍚� @@ -51,7 +53,7 @@ /// <summary> /// 瀵嗙爜姝e垯琛ㄨ揪寮� /// </summary> - public readonly static String PWD_REG = "^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\\W!@#$%^&*`~()\\-_+=,.?;<>]+$)(?![a-z0-9]+$)(?![a-z\\W!@#$%^&*`~()\\-_+=,.?;<>]+$)(?![0-9\\W!@#$%^&*`~()\\-_+=,.?;<>]+$)[a-zA-Z0-9\\W!@#$%^&*`~()\\-_+=,.?;<>]{12,20}$"; + public const String PWD_REG = "^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\\W!@#$%^&*`~()\\-_+=,.?;<>]+$)(?![a-z0-9]+$)(?![a-z\\W!@#$%^&*`~()\\-_+=,.?;<>]+$)(?![0-9\\W!@#$%^&*`~()\\-_+=,.?;<>]+$)[a-zA-Z0-9\\W!@#$%^&*`~()\\-_+=,.?;<>]{12,20}$"; /// <summary> /// MPT鏂囦欢鎵╁睍鍚� diff --git a/JavaCode/App.config b/JavaCode/App.config index 16a5051..70e8b74 100644 --- a/JavaCode/App.config +++ b/JavaCode/App.config @@ -2,8 +2,8 @@ <configuration> <appSettings> <!--<add key="pgConn" value="Server=127.0.0.1;Port=5433;Database=langfang;User Id=postgres;Password=postgres;"/>--> - <!--<add key="pgConn" value="Server=192.168.20.205;Port=5433;Database=langfang;User Id=postgres;Password=Postgres!_14_Lf;"/>--> - <add key="pgConn" value="Server=192.168.20.83;Port=5433;Database=moon;User Id=postgres;Password=Postgres!_14_moon;"/> + <add key="pgConn" value="Server=192.168.20.205;Port=5433;Database=langfang;User Id=postgres;Password=Postgres!_14_Lf;"/> + <!--<add key="pgConn" value="Server=192.168.20.83;Port=5433;Database=moon;User Id=postgres;Password=Postgres!_14_moon;"/>--> </appSettings> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/> -- Gitblit v1.9.3