public void Analyze(string[] contentFilters, params string[] files) { var indexer = new SvcIndexer(); indexer.Progress += HandleIndexerProgress; foreach (var file in files) { OnProgress(file, FileAccess.Read, 1, 0); var reader = new StreamReader(file); // Filters, empty for now. string[] filters = contentFilters ?? new string[] { }; // Read file IEnumerable <TraceEvent> events = indexer.Index(reader); List <long> occurrences = new List <long>(); if (filters.Length > 0) { foreach (var filter in filters) { occurrences.AddRange(indexer.FindOccurrences(reader, filter)); } } // Only use Transport events = events.Where(e => e.Source == "Transport"); string outputfile = files.First() + ".csv"; OnProgress(outputfile, FileAccess.Write, 1, 0); using (StreamWriter sw = new StreamWriter(outputfile, true)) { sw.WriteLine("Date;DurationInMs;Method;URL"); foreach (var pair in events.GroupBy(e => e.ActivityID)) { var first = pair.OrderBy(p => p.TimeCreated).First(); var last = pair.OrderBy(p => p.TimeCreated).Last(); // If there is a filter but the first/last pair do not match, skip this pair. if (filters.Length > 0 && !occurrences.Where(o => first.ContainsPosition(o) || last.ContainsPosition(o)).Any()) { continue; } var duration = last.TimeCreated - first.TimeCreated; string date = first.TimeCreated.ToString("yyyy-MM-dd HH:mm:ss.fff"); string durationInMs = first == last ? "N/A" : ((long)duration.TotalMilliseconds).ToString(); string method = first.Method; string url = first.To; sw.WriteLine(string.Format("{0};{1};{2};{3}", "\"" + date.Replace("\"", "\"\"") + "\"", "\"" + durationInMs.Replace("\"", "\"\"") + "\"", "\"" + method.Replace("\"", "\"\"") + "\"", "\"" + url.Replace("\"", "\"\"") + "\"" )); } } OnProgress(outputfile, FileAccess.Write, 1, 1); } }
public void Analyze(string[] contentFilters, params string[] files) { var indexer = new SvcIndexer(); indexer.Progress += HandleIndexerProgress; foreach (var file in files) { OnProgress(file, FileAccess.Read, 1, 0); var reader = new StreamReader(file); // Filters, empty for now. string[] filters = contentFilters ?? new string[] { }; // Read file IEnumerable<TraceEvent> events = indexer.Index(reader); List<long> occurrences = new List<long>(); if (filters.Length > 0) { foreach (var filter in filters) { occurrences.AddRange(indexer.FindOccurrences(reader, filter)); } } // Only use Transport events = events.Where(e => e.Source == "Transport"); string outputfile = files.First() + ".csv"; OnProgress(outputfile, FileAccess.Write, 1, 0); using (StreamWriter sw = new StreamWriter(outputfile, true)) { sw.WriteLine("Date;DurationInMs;Method;URL"); foreach (var pair in events.GroupBy(e => e.ActivityID)) { var first = pair.OrderBy(p => p.TimeCreated).First(); var last = pair.OrderBy(p => p.TimeCreated).Last(); // If there is a filter but the first/last pair do not match, skip this pair. if (filters.Length > 0 && !occurrences.Where(o => first.ContainsPosition(o) || last.ContainsPosition(o)).Any()) { continue; } var duration = last.TimeCreated - first.TimeCreated; string date = first.TimeCreated.ToString("yyyy-MM-dd HH:mm:ss.fff"); string durationInMs = first == last ? "N/A" : ((long)duration.TotalMilliseconds).ToString(); string method = first.Method; string url = first.To; sw.WriteLine(string.Format("{0};{1};{2};{3}", "\"" + date.Replace("\"", "\"\"") + "\"", "\"" + durationInMs.Replace("\"", "\"\"") + "\"", "\"" + method.Replace("\"", "\"\"") + "\"", "\"" + url.Replace("\"", "\"\"") + "\"" )); } } OnProgress(outputfile, FileAccess.Write, 1, 1); } }
private void LoadFile(string filename) { DisableInput(); // Close old reader if (reader != null) { reader.Close(); reader.Dispose(); } // Empty datagrid _currentVisibleTraceEvents = null; dataGridView1.Rows.Clear(); // Open and index new file var filestream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete, 4096, FileOptions.RandomAccess); reader = new StreamReader(filestream, Encoding.ASCII); events = indexer.Index(reader); // Fill the source box cmbSouce.Items.Clear(); cmbSouce.Items.Add("Any"); int selectedIndex = 0; int currentIndex = 0; foreach (string source in events.Select(e => e.Source).Distinct()) { currentIndex++; cmbSouce.Items.Add(source); if (source == Configuration.Instance.LastSelectedSource) { selectedIndex = currentIndex; } } cmbSouce.SelectedIndex = selectedIndex; // Add indexes to grid filteredEvents = null; RefreshEventList(); EnableInput(); lblStatus.Text = "file loaded"; lblFilename.Text = filename; Text = "SvclogViewer - " + Path.GetFileName(filename); }