From 994d438b4b06011eb7656357a367392bb30467c5 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期二, 22 八月 2023 17:33:33 +0800 Subject: [PATCH] 处理数据导入流程-1 --- DataLoader/CS/Importor.cs | 118 ++++++++++++++++++++++------------------------------------ 1 files changed, 45 insertions(+), 73 deletions(-) diff --git a/DataLoader/CS/Importor.cs b/DataLoader/CS/Importor.cs index 6f5251a..0b5fd01 100644 --- a/DataLoader/CS/Importor.cs +++ b/DataLoader/CS/Importor.cs @@ -1,68 +1,68 @@ 锘縰sing DataLoader.Model; -using Npgsql; using System; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Data.Common; 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 + /// <summary> + /// 鑾峰彇鏂囦欢 + /// </summary> + public static void GetFiles(ObservableCollection<ViewData> viewDatas) { - get + string[] files = Directory.GetFiles(CommonProp.SourcePath); + for (int i = 0, c = files.Length; i < c; i++) { - if (_ph == null) _ph = new PostgreHelper(); + 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); - return _ph; + SetSysMeta(vd); } } - private static readonly string insertMeta = "insert into lf.sys_meta (eventid, metaid, dirid, depid, verid, name, type, guid, path, sizes, tab, rows, create_user, create_time) values (@eventid, @metaid, @dirid, @depid, @verid, @name, @type, @guid, @path, @sizes, @tab, @rows, @create_user, now()) returning id"; - - public static string GetFilePathByGuid(string guid) + /// <summary> + /// 鏁版嵁瀵煎叆 + /// </summary> + public static void ImportFiles(ObservableCollection<ViewData> viewDatas) { - string sql = "select path from lf.sys_meta where guid = @guid limit 1"; + Parallel.ForEach(viewDatas, (vd, ParallelLoopState) => + { + try + { + // - DbParameter dp = new NpgsqlParameter("@guid", guid); - object obj = Helper.GetScalar(sql, dp); + SysMeta meta = new SysMeta(); + // - return obj == null ? null : obj.ToString(); + int id = DBHelper.InsertMeta(meta); + vd.Status = id > 0 ? "鎴愬姛銆�" : "澶辫触锛�"; + } + catch (Exception ex) + { + LogOut.Error(ex.StackTrace); + vd.Status = string.Format("澶辫触锛歿0}锛�", ex.Message); + } + }); } - public static bool IsFileExists(string guid) + /// <summary> + /// 澶嶅埗鏂囦欢 + /// </summary> + private static void CopyFile(string source, string target) { - string sql = "select count(*) from lf.sys_meta where guid = @guid"; - - DbParameter dp = new NpgsqlParameter("@guid", guid); - object obj = Helper.GetScalar(sql, dp); - - return obj != null && Convert.ToInt32(obj) > 0; - } - - public static int InsertMeta(SysMeta meta) - { - List<DbParameter> list = Tools.GetParams<SysMeta>(insertMeta, meta); - - object obj = Helper.GetScalar(insertMeta, list.ToArray()); - - return obj == null ? 0 : Convert.ToInt32(obj); + if (File.Exists(source)) + { + File.Copy(source, target, true); + } } public static void GetFiles(ObservableCollection<ViewData> viewDatas, string source) @@ -97,7 +97,7 @@ public static void ImportFiles(ObservableCollection<ViewData> viewDatas, string target, int start) { - Parallel.ForEach(viewDatas, (vd, ParallelLoopState) => + /*Parallel.ForEach(viewDatas, (vd, ParallelLoopState) => { try { @@ -118,19 +118,7 @@ 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) @@ -140,19 +128,11 @@ { try { - vd.Status = "鐢熸垚MD5鐮�..."; - string guid = MD5Helper.GetMD5Hash(vd.FilePath); - if (IsFileExists(guid)) - { - vd.Status = "宸插瓨鍦紒"; - continue; - } - vd.Status = "鎻掑叆鏁版嵁搴�..."; start = GetSubPath(target, start); - SysMeta mf = GetMetaFile(vd, start, guid); + SysMeta mf = GetMetaFile(vd, start, ""); - int metaId = InsertMeta(mf); + int metaId = 0; // InsertMeta(mf); if (metaId == 0) { vd.Status = "鍏冩暟鎹嚭閿欙紒"; @@ -211,14 +191,6 @@ mf.create_user = vd.Meta.create_user; return mf; - } - - private static void CopyFile(string source, string target) - { - if (File.Exists(source)) - { - File.Copy(source, target, true); - } } } } -- Gitblit v1.9.3