Esempio n. 1
0
        private void OnSessionInfoUpdated(object sender, SdkWrapper.SessionInfoUpdatedEventArgs e)
        {
            // The session info has updated
            bool shouldUpdateGrid = false;

            // Let's check every driver for a new lap
            foreach (var driver in Sim.Instance.Drivers)
            {
                // Ignore if there are no results yet
                if (driver.CurrentResults == null)
                {
                    continue;
                }

                // Get the number of laps this driver has completed
                var currentLap = driver.CurrentResults.LapsComplete;

                // Check what lap this driver was on the last update
                int?previousLap = null;
                if (previousLaps.ContainsKey(driver.Id))
                {
                    // We already stored their previous lap
                    previousLap = previousLaps[driver.Id];

                    // Then update the lap number to the current lap
                    previousLaps[driver.Id] = currentLap;
                }
                else
                {
                    // We didn't store their lap yet, so add it
                    previousLaps.Add(driver.Id, currentLap);
                }

                // Check if their lap number has changed
                if (previousLap == null || previousLap.Value < currentLap)
                {
                    // Lap has changed, grab their laptime and add to the list of lap entries
                    var lastTime = driver.CurrentResults.LastTime;

                    var entry = new LapEntry();
                    entry.CustomerId = driver.CustId;
                    entry.Name       = driver.Name;
                    entry.CarNumber  = driver.CarNumber;

                    entry.Lap            = lastTime.LapNumber;
                    entry.Laptime        = lastTime.Value;
                    entry.LaptimeDisplay = lastTime.Display;

                    laps.Add(entry);

                    // After we checked every driver we need to update the grid to reflect the changes
                    shouldUpdateGrid = true;
                }
            }

            if (shouldUpdateGrid)
            {
                bindingSource.ResetBindings(false);
            }
        }
Esempio n. 2
0
        private void OnSessionInfoUpdated(object sender, SdkWrapper.SessionInfoUpdatedEventArgs e)
        {
            // The session info has updated
            bool shouldUpdateGrid = false;

            // Let's check every driver for a new lap
            foreach (var driver in Sim.Instance.Drivers)
            {
                // Ignore if there are no results yet
                if (driver.CurrentResults == null) continue;

                // Get the number of laps this driver has completed
                var currentLap = driver.CurrentResults.LapsComplete;

                // Check what lap this driver was on the last update
                int? previousLap = null;
                if (previousLaps.ContainsKey(driver.Id))
                {
                    // We already stored their previous lap
                    previousLap = previousLaps[driver.Id];
                    
                    // Then update the lap number to the current lap
                    previousLaps[driver.Id] = currentLap;
                }
                else
                {
                    // We didn't store their lap yet, so add it
                    previousLaps.Add(driver.Id, currentLap);
                }

                // Check if their lap number has changed
                if (previousLap == null || previousLap.Value < currentLap)
                {
                    // Lap has changed, grab their laptime and add to the list of lap entries
                    var lastTime = driver.CurrentResults.LastTime;

                    var entry = new LapEntry();
                    entry.CustomerId = driver.CustId;
                    entry.Name = driver.Name;
                    entry.CarNumber = driver.CarNumber;

                    entry.Lap = lastTime.LapNumber;
                    entry.Laptime = lastTime.Value;
                    entry.LaptimeDisplay = lastTime.Display;

                    laps.Add(entry);

                    // After we checked every driver we need to update the grid to reflect the changes
                    shouldUpdateGrid = true;
                }
            }

            if (shouldUpdateGrid)
            {
                bindingSource.ResetBindings(false);
            }
        }