Example #1
0
        /// <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);
        }