/// <summary> ///读取 /// </summary> /// <param name="path"></param> /// <returns></returns> public static PeriodRmsedNumeralStoarge Read(string path) { ObjectTableReader reader = new ObjectTableReader(path); var table = reader.Read(); return(Parse(table)); }
/// <summary> /// 静态读取方法,读完就释放资源。 /// </summary> /// <param name="path"></param> /// <param name="encoding"></param> /// <returns></returns> public static ObjectTableStorage Read(string path, Encoding encoding = null) { using (ObjectTableReader reader = new ObjectTableReader(path, encoding)) { return(reader.Read()); } }
/// <summary> /// 读取返回表集合。移除下划线以后的字符串。 /// </summary> /// <param name="inputPathes"></param> /// <param name="nameSplitter"></param> /// <returns></returns> public static ObjectTableManager Read(string[] inputPathes, string nameSplitter = "_") { new Log(typeof(ObjectTableManager)).Info("准备并行读取 " + inputPathes.Length + " 个文件!"); DateTime start = DateTime.Now; var data = new ConcurrentDictionary <string, ObjectTableStorage>(); Parallel.ForEach(inputPathes, (path) => { if (!File.Exists(path)) { return; } ObjectTableReader reader = new ObjectTableReader(path); var storage = reader.Read(); var key = Path.GetFileNameWithoutExtension(path); var fistDivChar = key.LastIndexOf(nameSplitter); var name = key; if (fistDivChar != -1) { name = name.Substring(0, fistDivChar); } storage.Name = name; data.TryAdd(storage.Name, storage); }); var tableManager = new ObjectTableManager(data); tableManager.OutputDirectory = Path.GetDirectoryName(inputPathes[0]); var span = DateTime.Now - start; new Log(typeof(ObjectTableManager)).Info("并行读取了" + tableManager.Count + " 个文件,耗时:" + span); return(tableManager); }