public void GetAllSessinsMod(List <FileForRead> fileList) { if (fileList.Count > 0) { _readBySession.Read(fileList); Logging.AddInf($"Готово!"); WorkDone.Done(); } else { Logging.AddWrn("Выберите файлы!"); } }
internal void Read(List <FileForRead> fileList) { Parser parser = new Parser(); List <Task> readTasks = new List <Task>(); Logging.AddInf($"Start {DateTime.Now.ToString()}"); if (fileList.Count > 0) { foreach (var file in fileList.Where(x => x.Enable)) { string filePath = file.FilePath; WorkDone.Start(fileList.Count); if (File.Exists(filePath)) { WorkDone.BeginParseFile(0); Proto proto = Proto.NULL; Direct direct = Direct.NULL; readTasks.Add(Task.Run((() => { Logging.AddInf($"{filePath} read"); int strCounter = 1; StringBuilder session = new StringBuilder(); using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) using (StreamReader reader = new StreamReader(stream, srcEncoding)) { string line; while ((line = reader.ReadLine()) != null) { if (strCounter > _fileInfoStringCount) { if (!Parser.CheckEndSession(ref line)) { session.Append($"{line}\n"); } else { parser.ParsePerSession(session, ref proto, ref direct); WorkDone.SesDone(); session.Clear(); } } else { if (strCounter == _headerNumberString) { parser.IsFileInfo(ref proto, ref direct, $"{line}\r\n"); } strCounter++; } } } WorkDone.FlDone(); }))); } else { Logging.AddErr($"{filePath} is not exist!"); } } var t = Task.WhenAll(readTasks); t.Wait(); } else { Logging.AddWrn($"file collection empty..."); } Logging.AddInf($"finish {DateTime.Now.ToString()}"); }