Exemple #1
0
        public LiveJournalReader(FileInfo file, IJournalParser parser)
        {
            File    = file;
            _parser = parser;

            Context = new JournalLogFileInfo(File);
        }
        public LogJournalReader(FileInfo file, IJournalParser parser)
        {
            File    = file;
            _parser = parser;
            _stream = new Lazy <StreamReader>(GetStreamReader);

            Context = ReadFileInfo();
        }
 public JournalEntry(JournalLogFileInfo context, IJournalEntry journalEntry)
 {
     Context = context;
     Entry   = journalEntry;
 }
Exemple #4
0
 public JournalLine(JournalLogFileInfo context, string line)
 {
     Context = context;
     Line    = line;
 }
        private JournalLogFileInfo ReadFileInfo()
        {
            FileHeader     fileHeader = null;
            var            info       = new JournalLogFileInfo(File);
            DateTimeOffset?lastEntry  = null;

            try
            {
                // Get a new reader for this action only
                using (var streamReader = GetStreamReader())
                {
                    // FileHeader *should* be the first line in the file, but at least try the first 5
                    var tolerance = 5;

                    while (!streamReader.EndOfStream && tolerance > 0 && fileHeader == null)
                    {
                        var line = streamReader.ReadLine();
                        if (string.IsNullOrWhiteSpace(line))
                        {
                            continue;
                        }

                        try
                        {
                            var(eventType, timestamp) = _parser.ParseCommonProperties(line);

                            if (timestamp > (lastEntry ?? DateTimeOffset.MinValue))
                            {
                                lastEntry = timestamp;
                            }

                            if (eventType?.Equals(nameof(FileHeader), StringComparison.InvariantCultureIgnoreCase) == true)
                            {
                                fileHeader = _parser.Parse <FileHeader>(line);
                            }
                        }
                        catch (JournalParseException)
                        {
                            // Cannot parse line, don't consider as potential fileheader
                        }

                        tolerance--;
                    }
                }

                if (fileHeader != null)
                {
                    info = new JournalLogFileInfo(File, fileHeader.GameVersion, fileHeader.Timestamp, lastEntry ?? fileHeader.Timestamp);
                }
            }
            catch (FileNotFoundException e)
            {
                Log.Error($"Could not read file '{e.FileName}'", e);
            }
            catch (IOException e)
            {
                Log.Error($"Could not read file '{File.FullName}'", e);
            }

            return(info);
        }