/// <summary> /// Constructor. /// </summary> /// <param name="timeStamp">TimeStamp.</param> /// <param name="eventType">EventType.</param> /// <param name="eventDetail">EventDetail.</param> /// <param name="baseEventType">BaseEventType.</param> /// <param name="isEventStart">IsEventStart.</param> /// <param name="isEventEnd">IsEventEnd.</param> /// <param name="lineNumber">LineNumber.</param> public LogUnit( DateTime timeStamp, string eventType, string eventDetail, string baseEventType, bool isEventStart, bool isEventEnd, int lineNumber) { TimeStamp = timeStamp; EventType = eventType; EventDetail = eventDetail; BaseEventType = baseEventType; IsEventStart = isEventStart; IsEventEnd = isEventEnd; LineNumber = lineNumber; Units = new LogUnit[0]; }
/// <summary> /// Constructor. /// </summary> /// <param name="logContent">The log content to build this object from.</param> public LogData(string logContent) { Units = new LogUnit[0]; Stack <LogUnit> unitStack = new Stack <LogUnit>(); Stack <List <LogUnit> > listStack = new Stack <List <LogUnit> >(); List <LogUnit> units = new List <LogUnit>(); if (String.IsNullOrWhiteSpace(logContent)) { return; } using (StringReader reader = new StringReader(logContent)) { string line = null; int lineNumber = -1; while ((line = reader.ReadLine()) != null) { lineNumber++; LogUnit unit = LogUnit.ParseLine(line, lineNumber); if (unit != null) { if (unit.IsEventStart) { unitStack.Push(unit); listStack.Push(units); units = new List <LogUnit>(); } else if (unit.IsEventEnd) { LogUnit parent = unitStack.Pop(); if (parent == null) { return; } LogUnit u = new LogUnit( parent.TimeStamp, parent.BaseEventType, parent.EventDetail, parent.BaseEventType, false, false, parent.LineNumber, units.ToArray()); units = listStack.Pop(); if (units == null) { return; } units.Add(u); } else { units.Add(unit); } } } } // clear out stack if there any left while (unitStack.Count > 0) { LogUnit parent = unitStack.Pop(); if (parent == null) { return; } LogUnit u = new LogUnit( parent.TimeStamp, parent.BaseEventType, parent.EventDetail, parent.BaseEventType, false, false, parent.LineNumber, units.ToArray()); units = listStack.Pop(); if (units == null) { return; } units.Add(u); } Units = units.ToArray(); }