private void WorkerMakeTable(object param) { object[] aryParams = (object[])param; SourceInfo sourceInfo = aryParams[0] as SourceInfo; DataTable tbLog = (DataTable)aryParams[1]; Regex regexDivider = (Regex)aryParams[2]; Regex regexContents = (Regex)aryParams[3]; bool bIsSucess = false; int nPercent = 0; int nLineIndex = 0; List <Task> aryTasks = new List <Task>(); try { using (StreamReader reader = new StreamReader(sourceInfo.FullFilename)) { long lnSize = reader.BaseStream.Length; StringBuilder sbBuffer = new StringBuilder(); while (!reader.EndOfStream) { nLineIndex++; long lnPosition = reader.BaseStream.Position; int nCurPercent = (int)(lnPosition * 100 / lnSize * 0.9); if (nCurPercent != nPercent) { nPercent = nCurPercent; OnProcessUpdated?.Invoke(nPercent); } string sLine = reader.ReadLine(); if (regexDivider.IsMatch(sLine) && sbBuffer.Length > 0) { string sContents = sbBuffer.ToString(); Task task = Task.Factory.StartNew((object obj) => { try { string sContent = obj as string; Match match = regexContents.Match(sContent); if (match.Success) { lock (m_montior) { DataRow newRow = tbLog.NewRow(); newRow["source"] = sourceInfo.Name; newRow["line"] = nLineIndex; string sLogContents = sContent.Replace(match.Value, "").Trim(); if (!string.IsNullOrEmpty(sLogContents)) { newRow["content"] = sLogContents; foreach (StructInfo structInfo in ConfigManager.Current.AllStructures) { if (!string.IsNullOrEmpty(structInfo.RegexName)) { newRow[structInfo.Name] = match.Groups[structInfo.RegexName].Value.Trim(); } } tbLog.Rows.Add(newRow); } } } } catch (Exception ex) { Debug.WriteLine(ex); } }, sContents); aryTasks.Add(task); sbBuffer = new StringBuilder(); sbBuffer.AppendLine(sLine); continue; } sbBuffer.AppendLine(sLine); } } Task.WaitAll(aryTasks.ToArray()); bIsSucess = true; } catch (Exception ex) { } OnCompleted?.Invoke(bIsSucess, sourceInfo.Name, tbLog); }
private void parserEngine_OnProcessUpdated(int nPercent) { OnProcessUpdated?.Invoke(nPercent); }