/// <summary> /// Occurs each time split gets completed. Allows for UI update by marshalling the call accordingly. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SplitGoalCompletedEventHandler(object sender, SplitsManager.SplitGoalCompletedEventArgs e) { if (!m_dispatcher.CheckAccess()) // are we currently on the UI thread? { // We're not in the UI thread, ask the dispatcher to call this same method in the UI thread, then exit m_dispatcher.BeginInvoke(new SplitGoalCompletedEventHandlerDelegate(SplitGoalCompletedEventHandler), new object[] { sender, e }); return; } SplitItem splitItem = new SplitItem(e.SplitNumber) { SplitNumber = e.SplitNumberStr, Time = e.SplitTimeStr, Speed = e.SplitSpeedStr, TotalDistance = e.TotalDistanceStr, TotalTime = e.TotalTimeStr, Delta = e.DeltaTimeStr, SplitsInKm = e.SplitsInKm }; if (lvSplits.Items.ContainsKey(splitItem.SplitNumber)) { SplitListViewItem item = (SplitListViewItem)lvSplits.Items[splitItem.SplitNumber]; item.SplitItem = splitItem; // Replace with current splitItem object and refresh item.Refresh(); } else { // This should not happen lvSplits.Items.Add(new SplitListViewItem(splitItem)); lvSplits.Sort(); } Logger.LogInformation($"SplitGoalCompletedEventHandler {splitItem.SplitNumber}, {splitItem.Time}, {splitItem.Speed}, {splitItem.TotalDistance}, {splitItem.TotalTime}"); }
/// <summary> /// Occurs each time a split gets updated or completes. Allows for UI update by marshalling the call accordingly. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SplitEventHandler(object sender, SplitsManagerV2.SplitEventArgs e) { if (!m_dispatcher.CheckAccess()) // are we currently on the UI thread? { // We're not in the UI thread, ask the dispatcher to call this same method in the UI thread, then exit m_dispatcher.BeginInvoke(new SplitEventHandlerDelegate(SplitEventHandler), new object[] { sender, e }); return; } SplitItem splitItem = new SplitItem(e.SplitNumber, e.SplitTimeStr, e.SplitSpeedStr, e.TotalDistanceStr, e.TotalTimeStr, e.DeltaTimeStr, e.SplitsInKm, e.AheadOfGoalTime); //SplitItem splitItem = new SplitItem(e.SplitNumber) //{ // SplitNumber = e.SplitNumberStr, // Time = e.SplitTimeStr, // Speed = e.SplitSpeedStr, // TotalDistance = e.TotalDistanceStr, // TotalTime = e.TotalTimeStr, // Delta = e.DeltaTimeStr, // will return empty string if not a goal based split // SplitsInKm = e.SplitsInKm, // AheadOfGoalTime = e.AheadOfGoalTime // null if not a goal based split //}; if (lvSplits.Items.ContainsKey(splitItem.SplitNumber)) { SplitListViewItem item = (SplitListViewItem)lvSplits.Items[splitItem.SplitNumber]; item.SplitItem = splitItem; // Replace with current splitItem object and refresh item.Refresh(); } else { if (e.SplitNumber > 1) { // remove any color coding from previous split string prevSplit = (e.SplitNumber - 1).ToString(); if (lvSplits.Items.ContainsKey(prevSplit)) { SplitListViewItem item = (SplitListViewItem)lvSplits.Items[prevSplit]; item.ClearDeltaBackground(); } } lvSplits.Items.Add(new SplitListViewItem(splitItem)); lvSplits.Sort(); } //Logger.LogInformation($"SplitEventHandler {splitItem.SplitNumber}, {splitItem.Time}, {splitItem.Speed}, {splitItem.TotalDistance}, {splitItem.TotalTime}"); }