public void ProcessFile() { int retries = 0; retryOpeningLogfile: retries++; if (retries > 1) { if (retries == 4) { if (!File.Exists(fileToProcess)) { ReportUserError("File doesn't exist."); } else if (new FileInfo(fileToProcess).Length == 0) { ReportUserError("File is empty."); } else { ReportUserError("Failed to open/read file."); } } Thread.Sleep(500); } header = TryReadHeader(fileToProcess); if (header == null) { goto retryOpeningLogfile; } TcpPort = header.Port; var cancellationToken = cts.Token; try { using (fileStream = new FileStream(fileToProcess, FileMode.Open, FileAccess.Read, FileShare.Read)) { var processor = new LogProcessor(fileStream, new KrofilerLogEventVisitor(this), null); processor.Process(cancellation, runner != null); } if (cancellation.IsCancellationRequested) { completionSource.SetCanceled(); } else { completionSource.SetResult(true); } } catch (Exception e) { if (cancellation.IsCancellationRequested) { completionSource.SetCanceled(); } else { completionSource.SetException(e); } } Finished?.Invoke(this); }
internal LogBufferHeader(LogStreamHeader streamHeader, LogReader reader) { StreamHeader = streamHeader; var id = reader.ReadInt32(); if (id != Id) { throw new LogException($"Invalid buffer header ID (0x{id:X})."); } Length = reader.ReadInt32(); TimeBase = CurrentTime = reader.ReadUInt64(); PointerBase = reader.ReadInt64(); ObjectBase = reader.ReadInt64(); ThreadId = reader.ReadInt64(); MethodBase = CurrentMethod = reader.ReadInt64(); }