| | |
| | | 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; |
| | | using System.Windows.Documents; |
| | | |
| | | namespace DataLoader.CS |
| | | { |
| | |
| | | ViewData vd = new ViewData(); |
| | | vd.ID = viewDatas.Count + 1; |
| | | vd.FilePath = path; |
| | | vd.Ext = ext; |
| | | vd.Ext = "." + ext; |
| | | vd.Status = "准备"; |
| | | viewDatas.Add(vd); |
| | | |
| | | SetSysMeta(vd); |
| | | |
| | | DirectoryInfo di = new DirectoryInfo(vd.FilePath); |
| | | vd.Meta.name = di.Name; |
| | | vd.Meta.type = ext; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | viewDatas.Add(vd); |
| | | |
| | | SetSysMeta(vd); |
| | | |
| | | FileInfo fi = new FileInfo(vd.FilePath); |
| | | vd.Meta.name = fi.Name; |
| | | vd.Meta.type = fi.Extension.ToLower().Replace(".", ""); |
| | | } |
| | | } |
| | | |
| | |
| | | /// </summary> |
| | | 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.tab = null; |
| | | meta.rows = 0; |
| | | meta.create_user = CommonProp.UserId; |
| | | //meta.create_time = DateTime.Now; |
| | | meta.create_time = DateTime.Now; |
| | | meta.bak = null; |
| | | meta.geom = null; |
| | | meta.layer = null; |
| | |
| | | vd.Sizes = meta.sizes; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取文件大小 |
| | | /// </summary> |
| | | private static double GetFileSizes(ViewData vd) |
| | | { |
| | | //Tools.SizeToMb(fi.Length); // * |
| | | if (File.Exists(vd.FilePath)) |
| | | { |
| | | if (vd.Ext == StaticData.SHP) |
| | | { |
| | | List<string> files = GetShpFiles(vd.FilePath); |
| | | return GetFileSizes(files.ToArray()); |
| | | } |
| | | else |
| | | { |
| | | FileInfo fi = new FileInfo(vd.FilePath); |
| | | return Tools.SizeToMb(fi.Length); |
| | | } |
| | | } |
| | | |
| | | if (Directory.Exists(vd.FilePath)) |
| | | { |
| | | string[] files = Directory.GetFiles(vd.FilePath, "*", SearchOption.AllDirectories); |
| | | |
| | | return GetFileSizes(files); |
| | | } |
| | | |
| | | return 0; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取文件大小 |
| | | /// </summary> |
| | | private static double GetFileSizes(string[] files) |
| | | { |
| | | if (null == files || files.Length == 0) return 0; |
| | | |
| | | double sizes = 0; |
| | | foreach (string file in files) |
| | | { |
| | | FileInfo fi = new FileInfo(file); |
| | | sizes += Tools.SizeToMb(fi.Length); |
| | | } |
| | | |
| | | return sizes; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取SHP文件集合 |
| | | /// </summary> |
| | | private static List<string> GetShpFiles(string shpPath) |
| | | { |
| | | List<string> files = new List<string>(); |
| | | files.Add(shpPath); |
| | | |
| | | foreach (string ext in StaticData.SHP_EXT) |
| | | { |
| | | string file = shpPath.Replace(".shp", ext); |
| | | if (File.Exists(file)) |
| | | { |
| | | files.Add(file); |
| | | } |
| | | } |
| | | |
| | | return files; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 是否为GDB文件 |
| | | /// </summary> |
| | | private static bool IsGdbFile(string path) |