| | |
| | | using System.IO; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using System.Threading.Tasks; |
| | | using System.Windows.Forms; |
| | | |
| | | namespace DataLoader.CS |
| | | { |
| | | public class Importor |
| | | { |
| | | private static List<String> Exclusions = new List<string>() { |
| | | "jp2.aux.xml", |
| | | ".midx", ".strmi", |
| | | ".rrd", ".img.aux.xml", ".hdr", ".img.enp", ".img.xml", |
| | | ".tfw", ".tif.ovr", ".tif.aux.xml", ".tif.enp", ".tif.xml", ".prj", |
| | | ".shx", ".dbf", ".cpg" //, ".prj" |
| | | }; |
| | | |
| | | private static PostgreHelper _ph = null; |
| | | |
| | | public static PostgreHelper Helper |
| | |
| | | ViewData vd = new ViewData(); |
| | | vd.ID = i + 1; |
| | | vd.FilePath = files[i]; |
| | | vd.Ext = System.IO.Path.GetExtension(files[i]); |
| | | vd.Status = "准备"; |
| | | viewDatas.Add(vd); |
| | | |
| | |
| | | |
| | | vd.Meta = new SysMeta(); |
| | | vd.Meta.name = fi.Name; |
| | | vd.Meta.dirid = 1; |
| | | vd.Meta.dirid = Tool.DirId; |
| | | vd.Meta.depid = 1; |
| | | vd.Meta.verid = 0; |
| | | vd.Meta.type = fi.Extension.ToLower().Replace(".", ""); |
| | |
| | | vd.Meta.create_user = Tool.UserId; |
| | | } |
| | | |
| | | public static void ImportFiles(ObservableCollection<ViewData> viewDatas, string target) |
| | | public static void ImportFiles(ObservableCollection<ViewData> viewDatas, string target, int start) |
| | | { |
| | | Parallel.ForEach(viewDatas, (vd, ParallelLoopState) => |
| | | { |
| | | try |
| | | { |
| | | vd.Status = "生成MD5码..."; |
| | | string guid = MD5Helper.GetMD5Hash(vd.FilePath); |
| | | if (!Exclusions.Contains(vd.Ext) && IsFileExists(guid)) |
| | | { |
| | | vd.Status = "已存在!"; |
| | | return; |
| | | } |
| | | |
| | | vd.Status = "获取数据目录..."; |
| | | int subPath = GetSubPath(target, start); |
| | | SysMeta mf = GetMetaFile(vd, subPath, guid); |
| | | |
| | | vd.Status = "复制文件..."; |
| | | CopyFile(vd.FilePath, Path.Combine(target, mf.path)); |
| | | |
| | | vd.Status = "准备入库"; |
| | | vd.Meta = mf; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogOut.Error(ex.Message + "\r\n" + ex.StackTrace); |
| | | vd.Status = "失败!"; |
| | | } |
| | | }); |
| | | |
| | | foreach (ViewData vd in viewDatas) |
| | | { |
| | | int metaId = InsertMeta(vd.Meta); |
| | | vd.Status = metaId == 0 ? "元数据出错!" : "完成。"; |
| | | } |
| | | } |
| | | |
| | | public static void ImportFiles2(ObservableCollection<ViewData> viewDatas, string target) |
| | | { |
| | | int start = 1; |
| | | foreach (ViewData vd in viewDatas) |