private void AddFilterTrace(FilterTrace filterTrace) { // Check filters if (DoesTracePassFilters(filterTrace, FilterInclude.Include) && DoesTracePassFilters(filterTrace, FilterInclude.Exclude)) { // cull traces if (maxTraces > 0) { while (lvTraces.Items.Count >= maxTraces) { lvTraces.Items.RemoveAt(0); } } // Create a new row. ListViewItem item = new ListViewItem(filterTrace.DeviceId.ToString()); for (int i = 1; i < lvTraces.Columns.Count; i++) { switch (i) { case 1: item.SubItems.Add(filterTrace.TypeToStr()); break; case 2: item.SubItems.Add(filterTrace.GetTimestampDelta(prevTrace).ToString()); break; case 3: if (filterTrace.Buffer != null) { item.SubItems.Add(filterTrace.Buffer.Length.ToString()); } else { item.SubItems.Add(Convert.ToString(0)); } break; case 4: item.SubItems.Add(filterTrace.BufToHex()); break; case 5: item.SubItems.Add(filterTrace.BufToChars()); break; } } lvTraces.TopItem = lvTraces.Items.Add(item); prevTrace = filterTrace; } }
private bool DoesTracePassFilters(FilterTrace filterTrace, FilterInclude include) { List<FilterMatch> filters; if (include == FilterInclude.Include) filters = filterControl.IncludeFilters; else filters = filterControl.ExcludeFilters; if (filters.Count == 0) return true; bool check = true; foreach (FilterMatch filter in filters) { switch (filter.FilterType) { case FilterType.Length: switch (filter.LengthMatch) { case LengthMatch.GreaterThen: check = filterTrace.Buffer.Length > filter.Length; break; case LengthMatch.LessThen: check = filterTrace.Buffer.Length < filter.Length; break; case LengthMatch.EqualTo: check = filterTrace.Buffer.Length == filter.Length; break; } break; case FilterType.Hex: check = filterTrace.BufToHex().Contains(filter.Filter); break; case FilterType.Ascii: check = filterTrace.BufToChars().Contains(filter.Filter); break; } if (include == FilterInclude.Include) { if (check) return true; else continue; } else { if (check) return false; else continue; } } if (include == FilterInclude.Include) return false; else return true; }
private void AddFilterTrace(FilterTrace filterTrace) { // Check filters if (DoesTracePassFilters(filterTrace, FilterInclude.Include) && DoesTracePassFilters(filterTrace, FilterInclude.Exclude)) { // cull traces if (maxTraces > 0) { while (lvTraces.Items.Count >= maxTraces) lvTraces.Items.RemoveAt(0); } // Create a new row. ListViewItem item = new ListViewItem(filterTrace.DeviceId.ToString()); for (int i = 1; i < lvTraces.Columns.Count; i++) { switch (i) { case 1: item.SubItems.Add(filterTrace.TypeToStr()); break; case 2: item.SubItems.Add(filterTrace.GetTimestampDelta(prevTrace).ToString()); break; case 3: if (filterTrace.Buffer != null) item.SubItems.Add(filterTrace.Buffer.Length.ToString()); else item.SubItems.Add(Convert.ToString(0)); break; case 4: item.SubItems.Add(filterTrace.BufToHex()); break; case 5: item.SubItems.Add(filterTrace.BufToChars()); break; } } lvTraces.TopItem = lvTraces.Items.Add(item); prevTrace = filterTrace; } }
private bool DoesTracePassFilters(FilterTrace filterTrace, FilterInclude include) { List <FilterMatch> filters; if (include == FilterInclude.Include) { filters = filterControl.IncludeFilters; } else { filters = filterControl.ExcludeFilters; } if (filters.Count == 0) { return(true); } bool check = true; foreach (FilterMatch filter in filters) { switch (filter.FilterType) { case FilterType.Length: switch (filter.LengthMatch) { case LengthMatch.GreaterThen: check = filterTrace.Buffer.Length > filter.Length; break; case LengthMatch.LessThen: check = filterTrace.Buffer.Length < filter.Length; break; case LengthMatch.EqualTo: check = filterTrace.Buffer.Length == filter.Length; break; } break; case FilterType.Hex: check = filterTrace.BufToHex().Contains(filter.Filter); break; case FilterType.Ascii: check = filterTrace.BufToChars().Contains(filter.Filter); break; } if (include == FilterInclude.Include) { if (check) { return(true); } else { continue; } } else { if (check) { return(false); } else { continue; } } } if (include == FilterInclude.Include) { return(false); } else { return(true); } }