private void MetricsCalculatedEventHandler(object sender, MetricsCalculatedEventArgs e) { if (!mStarted) { return; } // just saving these most recent values for ride recap mCurDuration = e.ElapsedTime; mCurDistanceKm = e.DistanceKm; mCurDistanceMi = e.DistanceMi; // calculate kiloJoules (calories) burned int kiloJoules = (int)Math.Round((e.APwatts * e.ElapsedTime.TotalSeconds) / 1000.0, 0); if (e.SpeedKph != this.mCurAvgKph || e.SpeedMph != this.mCurAvgMph || e.APwatts != this.mCurAPwatts || kiloJoules != this.mCurKiloJoules) { this.mCurAvgKph = e.SpeedKph; this.mCurAvgMph = e.SpeedMph; this.mCurAPwatts = e.APwatts; this.mCurAPwattsPerKg = e.APwattsPerKg; this.mCurKiloJoules = kiloJoules; OnMetricsChangedEvent(new MetricsChangedEventArgs(e.SpeedKph, e.SpeedMph, e.APwatts, e.APwattsPerKg, kiloJoules)); } }
private void OnMetricsCalculatedEvent(MetricsCalculatedEventArgs e) { EventHandler <MetricsCalculatedEventArgs> handler = MetricsCalculatedEvent; if (handler != null) { try { handler(this, e); } catch (Exception ex) { // Don't let downstream exceptions bubble up Logger.LogError(ex, $"Caught in {this.GetType()} (OnMetricsCalculatedEvent)"); } } }