public void updateGauge(DiagnosticGauge gauge) { lock (gaugeLocker) { if (gauge.status == GaugeStatus.Started) { gauges.Push(gauge); } else { Stack<DiagnosticGauge> hand = new Stack<DiagnosticGauge>(); bool found = false; while (!found && gauges.Count > 0) { var candidate = gauges.Pop(); if (candidate == gauge) { candidate.update(gauge); gauges.Push(candidate); found = true; } else { hand.Push(candidate); } } while (hand.Count > 0) { gauges.Push(hand.Pop()); } if (!found) { gauges.Push(gauge); } } } }
protected void addGauge(DiagnosticGauge g) { if (App.diagnosticWindow != null) { App.diagnosticWindow.Dispatcher.adopt(delegate { lock (gaugeHistoryLock) { if (App.diagnosticWindow != null) { var oldFromTotal = App.diagnosticWindow.gaugeSource.FirstOrDefault(eg => eg.Equals(g)); if (oldFromTotal != default(DiagnosticGauge)) { App.diagnosticWindow.gaugeSource.Remove(oldFromTotal); } App.diagnosticWindow.gaugeSource.Add(g); var old = App.diagnosticWindow.inProgressSource.FirstOrDefault(eg => eg.Equals(g)); switch (g.status) { case GaugeStatus.Started: App.diagnosticWindow.inProgressSource.Add(g); break; case GaugeStatus.InProgress: if (old != default(DiagnosticGauge)) App.diagnosticWindow.inProgressSource.Remove(old); App.diagnosticWindow.inProgressSource.Add(g); break; case GaugeStatus.Completed: if (old != default(DiagnosticGauge)) App.diagnosticWindow.inProgressSource.Remove(old); break; case GaugeStatus.Failed: if (old != default(DiagnosticGauge)) App.diagnosticWindow.inProgressSource.Remove(old); break; } } }; }); } }
protected void addGaugeFromHistory(DiagnosticGauge g) { if (App.diagnosticWindow != null) { App.diagnosticWindow.Dispatcher.adopt(delegate { lock (gaugeHistoryLock) { var oldFromTotal = App.diagnosticWindow.gaugeSource.ToList().Where(eg => eg.Equals(g)); foreach (var oft in oldFromTotal) { App.diagnosticWindow.gaugeSource.Remove(oft); } var allOfThisGauge = oldFromTotal.Concat(new List<DiagnosticGauge> { g }).OrderByDescending(aotg => aotg.finished); var latest = allOfThisGauge.FirstOrDefault(); if (latest != default(DiagnosticGauge)) App.diagnosticWindow.gaugeSource.Add(latest); var old = App.diagnosticWindow.inProgressSource.FirstOrDefault(eg => eg.Equals(g)); if (latest != default(DiagnosticGauge)) { if (old != default(DiagnosticGauge)) App.diagnosticWindow.inProgressSource.Remove(old); switch (latest.status) { case GaugeStatus.Started: App.diagnosticWindow.inProgressSource.Add(latest); break; case GaugeStatus.InProgress: App.diagnosticWindow.inProgressSource.Add(latest); break; case GaugeStatus.Completed: break; case GaugeStatus.Failed: break; } } }; }); } }