| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Collections.ObjectModel; |
| | | using System.Data; |
| | | using System.IO; |
| | | using System.Linq; |
| | | using System.Security.Cryptography; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using static System.Net.Mime.MediaTypeNames; |
| | | |
| | | namespace DataLoader.CS |
| | | { |
| | | public class Importor |
| | | { |
| | | #region 加载 |
| | | /// <summary> |
| | | /// 获取文件 |
| | | /// </summary> |
| | | public static void GetFiles(ObservableCollection<ViewData> viewDatas) |
| | | public static void GetFiles(ObservableCollection<ViewData> viewDatas, string path) |
| | | { |
| | | string[] files = Directory.GetFiles(CommonProp.SourcePath, "*", SearchOption.AllDirectories); |
| | | GetSubFiles(viewDatas, path); |
| | | |
| | | int i = 1; |
| | | foreach(string file in files) |
| | | string[] directories = Directory.GetDirectories(path); |
| | | if (null == directories || directories.Length == 0) return; |
| | | |
| | | foreach (string sub in directories) |
| | | { |
| | | if (IsGdbFile(sub)) |
| | | { |
| | | SetSysMeta(viewDatas, sub, "gdb"); |
| | | continue; |
| | | } |
| | | if (IsOsgbFile(sub)) |
| | | { |
| | | SetSysMeta(viewDatas, sub, "osgb"); |
| | | continue; |
| | | } |
| | | |
| | | GetFiles(viewDatas, sub); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置元数据 |
| | | /// </summary> |
| | | private static void SetSysMeta(ObservableCollection<ViewData> viewDatas, string path, string ext) |
| | | { |
| | | ViewData vd = new ViewData(); |
| | | vd.ID = viewDatas.Count + 1; |
| | | vd.FilePath = path; |
| | | vd.Ext = ext; |
| | | vd.Status = "准备"; |
| | | viewDatas.Add(vd); |
| | | |
| | | SetSysMeta(vd); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取子文件 |
| | | /// </summary> |
| | | private static void GetSubFiles(ObservableCollection<ViewData> viewDatas, string path) |
| | | { |
| | | string[] files = Directory.GetFiles(path); |
| | | if (null == files || files.Length == 0) return; |
| | | |
| | | foreach (string file in files) |
| | | { |
| | | string ext = Path.GetExtension(file).ToLower(); |
| | | if (!StaticData.ALL_EXTENSION.Contains(ext) || IsExcludFile(file)) continue; |
| | | if (!StaticData.ALL_EXTENSION.Contains(ext) || IsExcludeFile(file)) continue; |
| | | |
| | | ViewData vd = new ViewData(); |
| | | vd.ID = i++; |
| | | vd.ID = viewDatas.Count + 1; |
| | | vd.FilePath = file; |
| | | vd.Ext = ext; |
| | | vd.Status = "准备"; |
| | |
| | | private static void SetSysMeta(ViewData vd) |
| | | { |
| | | FileInfo fi = new FileInfo(vd.FilePath); |
| | | SysMeta meta = new SysMeta(); |
| | | meta.eventid = Guid.NewGuid().ToString(); |
| | | meta.metaid = 0; |
| | | meta.verid = 0; |
| | | meta.name = fi.Name; |
| | | meta.type = fi.Extension.ToLower().Replace(".", ""); |
| | | meta.guid = null; |
| | | meta.path = vd.FilePath; // * |
| | | meta.sizes = GetFileSizes(vd); |
| | | meta.tab = null; // * |
| | | meta.rows = 0; |
| | | meta.create_user = CommonProp.UserId; |
| | | //meta.create_time = DateTime.Now; |
| | | meta.bak = null; |
| | | meta.geom = null; |
| | | meta.layer = null; |
| | | meta.depcode = CommonProp.Depcode; |
| | | meta.dircode = CommonProp.Dircode; |
| | | meta.ismeta = 0; |
| | | meta.sensortype = CommonProp.SensorType; |
| | | meta.acq_time = CommonProp.AcqTime; |
| | | |
| | | vd.Meta = new SysMeta(); |
| | | vd.Meta.name = fi.Name; |
| | | //vd.Meta.dirid = Common.DirId; |
| | | //vd.Meta.depid = 1; |
| | | vd.Meta.verid = 0; |
| | | vd.Meta.type = fi.Extension.ToLower().Replace(".", ""); |
| | | vd.Meta.sizes = Tools.SizeToMb(fi.Length); |
| | | vd.Meta.create_user = CommonProp.UserId; |
| | | vd.Meta = meta; |
| | | vd.Sizes = meta.sizes; |
| | | } |
| | | |
| | | private static double GetFileSizes(ViewData vd) |
| | | { |
| | | //Tools.SizeToMb(fi.Length); // * |
| | | |
| | | |
| | | return 0; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 是否为GDB文件 |
| | | /// </summary> |
| | | private static bool IsGdbFile(string path) |
| | | { |
| | | if (!Directory.Exists(path)) return false; |
| | | |
| | | DirectoryInfo info = new DirectoryInfo(path); |
| | | if (!info.Name.ToLower().EndsWith(StaticData.GDB)) return false; |
| | | |
| | | string gdb = Path.Combine(path, StaticData.NGDB); |
| | | |
| | | return File.Exists(gdb); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 是否为OSGB文件 |
| | | /// </summary> |
| | | private static bool IsOsgbFile(string path) |
| | | { |
| | | if (!Directory.Exists(path)) return false; |
| | | |
| | | string meta = Path.Combine(path, "metadata.xml"); |
| | | string data = Path.Combine(path, "Data"); |
| | | |
| | | return File.Exists(meta) && Directory.Exists(data); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 是/否为排除文件 |
| | | /// </summary> |
| | | private static bool IsExcludFile(string file) |
| | | private static bool IsExcludeFile(string file) |
| | | { |
| | | bool isExclud = false; |
| | | bool isExclude = false; |
| | | |
| | | string name = Path.GetFileName(file).ToLower(); |
| | | foreach (string ss in StaticData.MAPPER_EXCLUDE_EXT) |
| | | foreach (string ext in StaticData.MAPPER_EXCLUDE_EXT) |
| | | { |
| | | if (name.EndsWith(ss)) |
| | | if (name.EndsWith(ext)) |
| | | { |
| | | isExclud = true; |
| | | isExclude = true; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | return isExclud; |
| | | return isExclude; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 数据导入 |
| | | /// 获取文件的MD5码 |
| | | /// </summary> |
| | | private static string GetFileMD5(string file) |
| | | { |
| | | if ("1" != Tools.GetSetting("GetMD5") || !File.Exists(file)) return null; |
| | | |
| | | return MD5Helper.GetMD5Hash(file); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取多个文件的MD5码 |
| | | /// </summary> |
| | | private static string GetFilesMD5(string path) |
| | | { |
| | | if ("1" != Tools.GetSetting("GetMD5") || !Directory.Exists(path)) return null; |
| | | |
| | | string[] files = Directory.GetFiles(path, "*", SearchOption.AllDirectories); |
| | | if (null == files || files.Length == 0) return null; |
| | | |
| | | List<string> list = new List<string>(); |
| | | foreach (string file in files) |
| | | { |
| | | string md5 = MD5Helper.GetMD5Hash(file); |
| | | if (string.IsNullOrEmpty(md5)) list.Add(md5); |
| | | } |
| | | |
| | | if (list.Count == 0) return null; |
| | | |
| | | string str = string.Join(",", list.ToArray()); |
| | | byte[] bytes = Encoding.Unicode.GetBytes(str); |
| | | |
| | | return MD5Helper.GetMD5Hash(bytes); |
| | | } |
| | | #endregion |
| | | |
| | | #region 导入 |
| | | /// <summary> |
| | | /// 导入文件 |
| | | /// </summary> |
| | | public static void ImportFiles(ObservableCollection<ViewData> viewDatas) |
| | | { |
| | |
| | | if (File.Exists(source)) |
| | | { |
| | | File.Copy(source, target, true); |
| | | } |
| | | } |
| | | |
| | | public static void GetFiles(ObservableCollection<ViewData> viewDatas, string source) |
| | | { |
| | | string[] files = Directory.GetFiles(source); |
| | | for (int i = 0, c = files.Length; i < c; i++) |
| | | { |
| | | 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); |
| | | |
| | | SetSysMeta(vd); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | return mf; |
| | | } |
| | | #endregion |
| | | } |
| | | } |