Exemplo n.º 1
0
        public void Reset()
        {
            if (_stream != null)
            {
                _stream?.Dispose();
                _stream = null;
            }

            _indexCurrentFile = 0;
            UpdateEventLogFilesFromDirectory();
            _currentFileEventNumber = 0;
            _currentRow             = null;
        }
Exemplo n.º 2
0
        private bool InitializeReadFileStream()
        {
            if (_stream == null)
            {
                if (_logFilesWithData.Length <= _indexCurrentFile)
                {
                    _currentRow = null;
                    return(false);
                }

                string currentFile = _logFilesWithData[_indexCurrentFile];
                if (!File.Exists(currentFile))
                {
                    return(false);
                }

                InitializeStream(_indexCurrentFile);
                _currentFileEventNumber = 0;
            }

            return(true);
        }
Exemplo n.º 3
0
        public async Task StartReadEvents(CancellationToken cancellationToken)
        {
            while (CurrentFile != null)
            {
                if (!InitializeReadFileStream())
                {
                    return;
                }

                RaiseBeforeReadFileEvent(out bool cancelBeforeReadFile);
                if (cancelBeforeReadFile)
                {
                    NextFile();
                    await StartReadEvents(cancellationToken);

                    return;
                }

                _position               = null;
                _currentRow             = null;
                _currentFileEventNumber = 1;
                var      currentLogFile     = _logFilesWithData[_indexCurrentFile];
                FileInfo currentLogFileInfo = new FileInfo(currentLogFile);

                try
                {
                    XEFileEventStreamer xeReader = new XEFileEventStreamer(_stream);
                    await xeReader.ReadEventStream(() =>
                    {
                        _position = new ExtendedEventsPosition(
                            _currentFileEventNumber,
                            CurrentFile,
                            null,
                            null,
                            false,
                            currentLogFileInfo.CreationTimeUtc,
                            currentLogFileInfo.LastWriteTimeUtc);
                        RaiseOnReadMetadata(new OnReadMetadataArgs(_position));
                        return(Task.CompletedTask);
                    },
                                                   (eventData) =>
                    {
                        _position = new ExtendedEventsPosition(
                            _currentFileEventNumber,
                            CurrentFile,
                            eventData.UUID.ToString(),
                            eventData.Timestamp,
                            false,
                            currentLogFileInfo.CreationTimeUtc,
                            currentLogFileInfo.LastWriteTimeUtc);

                        _currentRow = new ExtendedEvent(_currentFileEventNumber, eventData);
                        RaiseOnRead(new OnReadEventArgs(_currentRow, _position, _currentFileEventNumber));
                        _currentFileEventNumber++;

                        return(Task.CompletedTask);
                    }, cancellationToken);

                    _currentRow = null;
                    if (_position != null)
                    {
                        _position = new ExtendedEventsPosition(
                            _position.EventNumber,
                            _position.CurrentFileData,
                            _position.EventUUID,
                            _position.EventPeriod,
                            true,
                            currentLogFileInfo.CreationTimeUtc,
                            currentLogFileInfo.LastWriteTimeUtc
                            );
                    }
                    RaiseOnRead(new OnReadEventArgs(_currentRow, _position, _currentFileEventNumber));

                    NextFile();
                }
                catch (Exception ex)
                {
                    RaiseOnError(new OnErrorEventArgs(ex));
                    break;
                }
            }
        }