| | |
| | | using 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.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace DataLoader.CS |
| | | { |
| | | public class Importor |
| | | { |
| | | private static PostgreHelper _ph = null; |
| | | |
| | | public static PostgreHelper Helper |
| | | { |
| | | get |
| | | { |
| | | if (_ph == null) _ph = new PostgreHelper(DbEnum.langfang); |
| | | |
| | | return _ph; |
| | | } |
| | | } |
| | | |
| | | private static readonly string insertMeta = "insert into lf.sys_meta(name, dirid, depid, verid, type, sizes, cs, scale, resolution, gather, batch, descr, create_user) values @name, @dirid, @depid, @verid, @type, @sizes, @cs, @scale, @resolution, @gather, @batch, @descr, @create_user) returning id"; |
| | | |
| | | 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) |
| | | { |
| | | string sql = "select count(*) from lf.sys_meta_file where guid=@guid"; |
| | | DbParameter dp = new NpgsqlParameter("@guid", guid); |
| | | |
| | | int rows = Helper.GetCount(sql, dp); |
| | | |
| | | return rows; |
| | | } |
| | | |
| | | public static int InsertMeta(SysMeta meta) |
| | | { |
| | | // string sql = "INSERT INTO public.data_files(mid, guid, name, ext, path, subs, remark) VALUES (@mid, @guid, @name, @ext, @path, @subs, @remark) returning id"; |
| | | List<DbParameter> list = Tool.GetParams<SysMeta>(insertMeta, meta); |
| | | |
| | | object obj = Helper.GetScalar(insertMeta, list.ToArray()); |
| | | |
| | | return obj == null ? 0 : Convert.ToInt32(obj); |
| | | } |
| | | |
| | | public static int InsertMetaFile(SysMetaFile metaFile) |
| | | { |
| | | List<DbParameter> list = Tool.GetParams<SysMetaFile>(insertMetaFile, metaFile); |
| | | |
| | | object obj = Helper.ExecuteNonQuery(insertMetaFile, list.ToArray()); |
| | | |
| | | return obj == null ? 0 : Convert.ToInt32(obj); |
| | | } |
| | | |
| | | public static void Import(ObservableCollection<ViewData> viewDatas, string source, string target) |
| | | { |
| | | |
| | | string[] files = Directory.GetFiles(source); |
| | | } |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.IO; |
| | | using System.Linq; |
| | | using System.Security.Cryptography; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace DataLoader.CS |
| | | { |
| | | public class MD5Helper |
| | | { |
| | | /// <summary> |
| | | /// æä»¶MD5æ ¡éª |
| | | /// </summary> |
| | | /// <param name="pathName">æä»¶ç»å¯¹è·¯å¾</param> |
| | | /// <returns>MD5æ ¡éªç </returns> |
| | | public static string getMD5Hash(string pathName) |
| | | { |
| | | try |
| | | { |
| | | FileStream oFileStream = new FileStream(pathName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); |
| | | MD5CryptoServiceProvider oMD5Hasher = new MD5CryptoServiceProvider(); |
| | | byte[] arrbytHashValue = oMD5Hasher.ComputeHash(oFileStream); // è®¡ç®æå®Stream 对象çåå¸å¼ |
| | | oFileStream.Close(); |
| | | |
| | | // ç±ä»¥è¿å符åéçåå
è¿å¶å¯¹ææçStringï¼å
¶ä¸æ¯ä¸å¯¹è¡¨ç¤ºvalue ä¸å¯¹åºçå
ç´ ï¼ä¾å¦âF-2C-4Aâ |
| | | string strHashData = BitConverter.ToString(arrbytHashValue); |
| | | |
| | | return strHashData.Replace("-", "").ToLower(); // æ¿æ¢- |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return ""; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åèæ°ç»æ ¡éª |
| | | /// </summary> |
| | | /// <param name="buffer">å¾
åèæ°ç»</param> |
| | | /// <returns>MD5æ ¡éªç </returns> |
| | | public static string getMD5Hash(byte[] buffer) |
| | | { |
| | | MD5CryptoServiceProvider oMD5Hasher = new MD5CryptoServiceProvider(); |
| | | try |
| | | { |
| | | // è®¡ç®æå®Stream 对象çåå¸å¼ï¼ç±ä»¥è¿å符åéçåå
è¿å¶å¯¹ææçStringï¼å
¶ä¸æ¯ä¸å¯¹è¡¨ç¤ºvalue ä¸å¯¹åºçå
ç´ ï¼ä¾å¦âF-2C-4Aâ |
| | | byte[] arrbytHashValue = oMD5Hasher.ComputeHash(buffer); |
| | | string strHashData = BitConverter.ToString(arrbytHashValue); |
| | | |
| | | return strHashData.Replace("-", "").ToLower(); // æ¿æ¢- |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return ""; |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | <SubType>Code</SubType> |
| | | </Compile> |
| | | <Compile Include="CS\Importor.cs" /> |
| | | <Compile Include="CS\MD5Helper.cs" /> |
| | | <Compile Include="Model\Tool.cs" /> |
| | | <Compile Include="CS\ModelHandler.cs" /> |
| | | <Compile Include="Model\NtstWeb.cs" /> |
| | |
| | | <TextBox x:Name="tbToken" Grid.Row="0" Grid.Column="3" Style="{StaticResource tb}" IsReadOnly="True"/> |
| | | <Button Grid.Row="0" Grid.Column="4" Content="ç» å½" Style="{StaticResource btn}" Click="Login_MouseLeftButtonDown"/> |
| | | |
| | | <Label Grid.Row="1" Grid.Column="0" Content="æºç®å½ï¼" VerticalAlignment="Center" HorizontalAlignment="Right" /> |
| | | <Label Grid.Row="1" Grid.Column="0" Content="æ°æ®ç®å½ï¼" VerticalAlignment="Center" HorizontalAlignment="Right" /> |
| | | <TextBox x:Name="tbSource" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3" Style="{StaticResource tb}" Text="{Binding Path=SourcePath, Mode=TwoWay}"/> |
| | | <Button x:Name="btnSource" Grid.Row="1" Grid.Column="4" Content="é æ©" Style="{StaticResource btn}" Click="Source_MouseLeftButtonDown"/> |
| | | |
| | |
| | | this.btnImport.IsEnabled = false; |
| | | lvView.DataContext = viewDatas; |
| | | lvView.SetBinding(ListView.ItemsSourceProperty, new Binding()); |
| | | } |
| | | |
| | | String file = "E:\\data\\mpt\\A4mpt20131125.mpt"; |
| | | string md5 = MD5Helper.getMD5Hash(file); |
| | | } |
| | | |
| | | // ç»å½ |
| | | private void Login_MouseLeftButtonDown(object sender, RoutedEventArgs e) |
| | |
| | | // 导å
¥ |
| | | private void Import_MouseLeftButtonDown(object sender, RoutedEventArgs e) |
| | | { |
| | | if (string.IsNullOrEmpty(SourcePath) || !Directory.Exists(SourcePath)) |
| | | { |
| | | MessageBox.Show("è¯·éæ©æ°æ®ç®å½ï¼"); |
| | | return; |
| | | } |
| | | if (string.IsNullOrEmpty(TargetPath) || !Directory.Exists(TargetPath)) |
| | | { |
| | | MessageBox.Show("è¯·éæ©å
¥åºç®å½ï¼"); |
| | | return; |
| | | } |
| | | string[] files = Directory.GetFiles(SourcePath); |
| | | if (null == files || files.Length == 0) |
| | | { |
| | | MessageBox.Show("æ°æ®ç®å½ä¸æ²¡ææä»¶ï¼"); |
| | | return; |
| | | } |
| | | |
| | | viewDatas.Clear(); |
| | | |
| | | Dispatcher.Invoke(new Action(delegate |
| | |
| | | using System.Collections.Generic; |
| | | using System.Configuration; |
| | | using System.Data.Common; |
| | | using System.IO; |
| | | using System.Linq; |
| | | using System.Reflection; |
| | | using System.Runtime.InteropServices.ComTypes; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using System.Windows; |
| | |
| | | public static string Uname = ""; |
| | | |
| | | public static string Token = ""; |
| | | |
| | | public static char[] HEX_DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; |
| | | |
| | | public static string FormatBytes(long bytes) |
| | | { |
| | |
| | | |
| | | return list; |
| | | } |
| | | |
| | | /*//2a0befb05146cd30213ee4b95038aca0 |
| | | public static String getFileMd5(String filePath) |
| | | { |
| | | FileStream fis = null; |
| | | try |
| | | { |
| | | 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); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return null; |
| | | } |
| | | finally |
| | | { |
| | | try |
| | | { |
| | | if (null != fis) |
| | | { |
| | | fis.Dispose(); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | // |
| | | } |
| | | } |
| | | } |
| | | |
| | | 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); |
| | | }*/ |
| | | } |
| | | } |