DataLoader/CS/Importor.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
DataLoader/Model/Tool.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
DataLoader/Model/ViewData.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
DataLoader/CS/Importor.cs
@@ -28,14 +28,14 @@ private static readonly string insertMetaFile = "insert into lf.sys_meta_file(name, metaid, fileid, guid, path, sizes, create_user) values (@name, @metaid, @fileid, @guid, @path, @sizes, @create_user)"; public static int CountFilesByGuid(string guid) public static string GetFilePathByGuid(string guid) { string sql = "select count(*) from lf.sys_meta_file where guid=@guid"; string sql = "select path from lf.sys_meta_file where guid = @guid limit"; DbParameter dp = new NpgsqlParameter("@guid", guid); object obj = Helper.GetScalar(sql, dp); int rows = Helper.GetCount(sql, dp); return rows; return obj == null ? null : obj.ToString(); } public static int InsertMeta(SysMeta meta) @@ -60,6 +60,44 @@ public static void Import(ObservableCollection<ViewData> viewDatas, string source, string target) { string[] files = Directory.GetFiles(source); foreach (string file in files) { ViewData vd = new ViewData(); viewDatas.Add(vd); } for (int i = 0, c = files.Length; i < c; i++) { ViewData vd = new ViewData(); vd.ID = i + 1; vd.FilePath = files[i]; vd.Status = "准备"; viewDatas.Add(vd); SetSysMeta(vd); } } private static void SetSysMeta(ViewData vd) { FileInfo fi = new FileInfo(vd.FilePath); vd.Meta = new SysMeta(); vd.Meta.name = fi.Name; vd.Meta.dirid = 0; vd.Meta.depid = 0; vd.Meta.verid = 0; vd.Meta.type = "File"; vd.Meta.sizes = Tool.SizeToMb(fi.Length); vd.Meta.cs = null; vd.Meta.scale = null; vd.Meta.resolution = null; vd.Meta.gather = DateTime.Now; vd.Meta.batch = null; vd.Meta.descr = null; vd.Meta.create_user = Tool.UserId; } } } DataLoader/Model/Tool.cs
@@ -79,67 +79,16 @@ return list; } /*//2a0befb05146cd30213ee4b95038aca0 public static String getFileMd5(String filePath) public static double SizeToMb(long size) { FileStream fis = null; try if (size < 1050) { MessageDigest md = MessageDigest.getInstance("MD5"); fis = new FileStream(new File(filePath)); FileChannel fChannel = fis.getChannel(); Byte[] buffer =new Byte[1024 * 1024]; while (fChannel.read(buffer) != -1) { buffer.flip(); md.update(buffer); buffer.compact(); } byte[] b = md.digest(); return byteToHexString(b); return 0.001; } catch (Exception ex) { return null; } finally { try { if (null != fis) { fis.Dispose(); } } catch (Exception ex) { // } } String str = string.Format("{0:F3}", size / 1024.0 / 1024.0); return Double.Parse(str); } public static String byteToHexString(byte[] tmp) { // 每个字节用 16 进制表示的话,使用两个字符, char[] str = new char[16 * 2]; int k = 0; for (int i = 0; i < 16; i++) { // 转换成 16 进制字符的转换 byte byte0 = tmp[i]; // 取字节中高 4 位的数字转换 str[k++] = HEX_DIGITS[byte0 >> 4 & 0xf]; // >>> 为逻辑右移,将符号位一起右移, 取字节中低 4 位的数字转换 str[k++] = HEX_DIGITS[byte0 & 0xf]; } return new String(str); }*/ } } DataLoader/Model/ViewData.cs
@@ -76,5 +76,7 @@ PropertyChanged(this, new PropertyChangedEventArgs(propName)); } } public SysMeta Meta { set; get; } } }