| | |
| | | /// </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); |
| | |
| | | } |
| | | |
| | | string[] files = Directory.GetFiles(path); |
| | | if (files.Length < 2001) |
| | | if (files.Length <= StaticData.MAX_FILES) |
| | | { |
| | | return start; |
| | | } |