private snoop_form_info info(snoop_around_form self) { lock (this) { var find = snoops_.Values.FirstOrDefault(x => x.form == self); Debug.Assert(find != null); return find; } }
private void add_values(snoop_around_form snoop, ref bool stop) { logger.Debug("entered test_snoop_form.add_values"); while (!stop) { Thread.Sleep(3000); if (stop) break; Dictionary<string, int> v; switch (add_snoop_idx++) { case 0: v = v0; break; case 1: v = v1; break; default: v = v2; break; } bool all_done = add_snoop_idx >= 3; snoop.set_values(v, all_done, all_done); if (all_done) break; } logger.Debug("exited test_snoop_form.add_values"); }
public test_snoop_form() { InitializeComponent(); var snoop_a = new snoop_around_form(); snoop_a.set_parent_rect(this, new Rectangle(a.Location, a.Size) ); snoop_a.on_snoop = add_values; }
internal snoop_filter(log_view view) { view_ = view; // add the most of possible snoops foreach ( info_type type in Enum.GetValues(typeof(info_type))) if (info_type_io.is_snoopable(type)) { var form = new snoop_around_form(); form.on_apply = on_apply; form.on_snoop = on_snoop; unused_.Add( new snoop_form_info { form = form } ); } }
private void on_snoop(snoop_around_form self, ref bool keep_running) { var info = this.info(self); if (info.snoop_selection.Count > 0) { // in this case, user selected at least something, // and then applied the selection - thus, no re-snooping self.reuse_last_values(); return; } // we cannot be visible if users doesn't have any rows int sel = view_.sel_row_idx; if (sel <= 0) sel = 0; if ( info.snoop_sel >= 0) if (Math.Abs(info.snoop_sel - sel) <= app.inst.reuse_snoop_surrounding) { // we already snooped near by, reuse that self.reuse_last_values(); return; } // here, I know for sure I need to (re)snoop int all = view_.item_count; bool snoop_all = all <= app.inst.snoop_all_if_entries_less_than; int min = 0, max = all; if (!snoop_all) { var surrounding = util.surrounding(sel, app.inst.snoop_surrounding_entries, 0, all); min = surrounding.Item1; max = surrounding.Item2; } var type = info_key(self); int snoop_idx = 0; Dictionary< string, int> values = new Dictionary<string, int>(); // update int snoop_update_ui_step = (max - min) / app.inst.snoop_update_ui_times; for (int idx = min; idx < max; ++idx) { var i = view_.item_at(idx) as filter.match; var cur_value = i.line.part(type); if ( !values.ContainsKey(cur_value)) values.Add(cur_value, 0); ++values[cur_value]; if (++snoop_idx % snoop_update_ui_step == 0) if (keep_running) // ... set to a copy, since we're modifying this one self.set_values(values.ToDictionary(x => x.Key, x => x.Value), false, false); else break; } if (keep_running) { self.set_values(values, true, snoop_all); info.snoop_sel = sel; } }
private info_type info_key(snoop_around_form self) { lock (this) { var find = snoops_.FirstOrDefault(x => x.Value.form == self); return find.Key; } }
private void on_apply(snoop_around_form self, List<string> selection, bool used) { var new_sel = new HashSet<string>(selection); var info = this.info(self); bool same_snoop = info.snoop_selection.SetEquals(new_sel); if (same_snoop && info.selection_used == used) return; // nothing changed if (same_snoop && selection.Count == 0) // nothing is selected, it doesn't matter return; lock (this) { info.selection_used = used; info.snoop_selection = new_sel; if (!same_snoop) { bool has_sel = new_sel.Count > 0; if (info.apply_index >= 0) // all snoops with a higher index, are cleared (the selection changed, thus, they need to be re-done) foreach (var snoop in snoops_.Values) if (snoop.apply_index > info.apply_index) snoop.clear(); if (!has_sel) // user cleared this snoop info.clear(); if (has_sel && info.apply_index < 0) { // need to find out the apply_index int max_apply = snoops_.Values.Max(x => x.apply_index); info.apply_index = max_apply + 1; } // all snoops that did not have a selection yet, they need re-doing foreach (var snoop in snoops_.Values) if (snoop.apply_index < 0) snoop.clear(); } } view_.reapply_quick_filter(); }