Esempio n. 1
0
        private void FindNearestBeginEventPosition(ref bool isCorrectBeginEvent, string currentFilePath, ref long newStreamPosition, int stepSize = 1)
        {
            int attemptToFoundBeginEventLine = 0;

            while (!isCorrectBeginEvent && attemptToFoundBeginEventLine < 10)
            {
                string beginEventLine;
                using (FileStream fileStreamCheckPosition =
                           new FileStream(currentFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    fileStreamCheckPosition.Seek(newStreamPosition, SeekOrigin.Begin);
                    using (StreamReader fileStreamCheckReader = new StreamReader(fileStreamCheckPosition))
                        beginEventLine = fileStreamCheckReader.ReadLineWithoutNull();
                }

                if (beginEventLine == null)
                {
                    isCorrectBeginEvent = false;
                    break;
                }

                isCorrectBeginEvent = LogParserLGF.ItsBeginOfEvent(beginEventLine);
                if (!isCorrectBeginEvent)
                {
                    newStreamPosition            -= stepSize;
                    attemptToFoundBeginEventLine += 1;
                }
            }
        }
Esempio n. 2
0
        public override bool GoToEvent(long eventNumber)
        {
            Reset();

            int  fileIndex          = -1;
            long currentLineNumber  = -1;
            long currentEventNumber = 0;
            bool moved = false;

            foreach (string logFile in _logFilesWithData)
            {
                fileIndex        += 1;
                currentLineNumber = -1;

                IEnumerable <string> allLines = File.ReadLines(logFile);
                foreach (string line in allLines)
                {
                    currentLineNumber += 1;
                    if (LogParserLGF.ItsBeginOfEvent(line))
                    {
                        currentEventNumber += 1;
                    }

                    if (currentEventNumber == eventNumber)
                    {
                        moved = true;
                        break;
                    }
                }

                if (currentEventNumber == eventNumber)
                {
                    moved = true;
                    break;
                }
            }

            if (moved && fileIndex >= 0 && currentLineNumber >= 0)
            {
                InitializeStream(currentLineNumber, fileIndex);
                _eventCount             = eventNumber - 1;
                _currentFileEventNumber = eventNumber;

                return(true);
            }
            else
            {
                return(false);
            }
        }
        private long GetEventCount()
        {
            long eventCount = 0;

            foreach (var logFile in _logFilesWithData)
            {
                using (StreamReader logFileStream = new StreamReader(File.Open(logFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
                {
                    do
                    {
                        string logFileCurrentString = logFileStream.ReadLine();
                        if (LogParserLGF.ItsBeginOfEvent(logFileCurrentString))
                        {
                            eventCount++;
                        }
                    } while (!logFileStream.EndOfStream);
                }
            }

            return(eventCount);
        }
Esempio n. 4
0
        private bool NextLineIsBeginEvent()
        {
            if (CurrentFile == null || _stream == null)
            {
                return(false);
            }

            bool nextIsBeginEvent;
            long currentStreamPosition = _stream.GetPosition();

            using (FileStream fileStreamCheckReader = new FileStream(CurrentFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                using (StreamReader checkReader = new StreamReader(fileStreamCheckReader))
                {
                    checkReader.SetPosition(currentStreamPosition);
                    string lineContent = checkReader.ReadLineWithoutNull();
                    nextIsBeginEvent = LogParserLGF.ItsBeginOfEvent(lineContent);
                }
            }

            return(nextIsBeginEvent);
        }