private void OnSessionInfoUpdated(object sender, iRacingSdkWrapper.SdkWrapper.SessionInfoUpdatedEventArgs e) { foreach (var model in _sdkViewModels) { model.OnSessionInfoUpdated(e.SessionInfo, e.UpdateTime); } }
private void OnSessionInfoUpdated(object sender, iRacingSdkWrapper.SdkWrapper.SessionInfoUpdatedEventArgs e) { // Update the list of drivers: simply clear the old list and re-fill it with the drivers from iRacingSimulator _drivers.Clear(); _drivers.AddRange(Sim.Instance.Drivers); // Update the grid this.RefreshGrid(); }
private void OnSessionInfoUpdated(object sender, iRacingSdkWrapper.SdkWrapper.SessionInfoUpdatedEventArgs e) { // iRacing session info updated - send to all viewmodels //this.Dispatcher.Invoke(() => //{ foreach (var model in _sdkModels) { model.Value.OnSessionInfoUpdated(e); } //}); }
private void OnSessionInfoUpdated(object sender, iRacingSdkWrapper.SdkWrapper.SessionInfoUpdatedEventArgs e) { // Update the list of drivers: simply clear the old list and re-fill it with the drivers from iRacingSimulator _drivers.Clear(); // ObservableCollection does not support AddRange so we just call Add in a loop // Note: this is probably not a good idea as it notifies the grid of updates for every driver, rather than just once foreach (var driver in Sim.Instance.Drivers) { _drivers.Add(driver); } // Update the grid this.RefreshGrid(); }
// do things when session info updates private void OnSessionInfoUpdated(object sender, iRacingSdkWrapper.SdkWrapper.SessionInfoUpdatedEventArgs sessionArgs) { try { if (!closing) { if (sessionArgs.SessionInfo.IsValidYaml) // check if yaml is valid { Deserializer deserializer = new Deserializer(namingConvention: new PascalCaseNamingConvention(), ignoreUnmatched: true); // create a deserializer var input = new StringReader(sessionArgs.SessionInfo.Yaml); // read the yaml var sessionInfo = deserializer.Deserialize <SDKReturn>(input); // deserialize the yaml #region Track info var track = sessionInfo.WeekendInfo.TrackDisplayName; if (track != currentTrack) { currentTrack = track; // currently, in the real CWTS, nascar stops the cautoin clock at 10 laps to go, so we need to see if we're at one of those tracks if (currentTrack == "Canadian Tire Motorsport Park" || currentTrack == "Pocono Raceway") // if we're at one of the two tracks { // let the user know about the IRL rules var msgBoxResult = MessageBox.Show("It looks like you're either at Canadian Tire or Pocono. \nThese tracks have the caution clock turn off at 10 laps to go in the real CWTS. \nClick OK to set the caution clock to turn off at 10 laps, or cancel to leave it at 20.", "", MessageBoxButtons.OKCancel); if (msgBoxResult == DialogResult.OK) { cautionClockCutoffLap = 10; numUDLapCutoff.Value = 10; } } } #endregion #region Session Info foreach (var session in sessionInfo.SessionInfo.Sessions) // look through all the sessions (normally they're Practice, Qualifying, and Race) { if (session.SessionType == "Race") // find the race session { var raceSession = session; // the session we're dealing with is the race session, just using this to shorten the variable to less than 50 characters int lapsComplete = Convert.ToInt32(raceSession.ResultsLapsComplete); // get the laps complete raceLengthLaps = Convert.ToInt32(raceSession.SessionLaps); if (lapsComplete >= -1) // if ResultsLapsComplete is -1, we haven't entered the race yet { isRaceSession = true; lapsComplete += 1; // laps are 0 indexed, need to add 1 to get it to display correctly lblCurrentLap.Text = string.Format("Lap {0} of {1}", lapsComplete.ToString(), raceLengthLaps); // set label on form to show what lap we're on try { if ((Convert.ToInt32(raceLengthLaps)) - (Convert.ToInt32(lapsComplete)) <= cautionClockCutoffLap) // check if we're less than 20 to go in the race { cautionClockActive = false; // turn off caution clock } } catch { MessageBox.Show("It looks like the session you're in is a timed race."); } } } } #endregion #region Radio Info / Admin check if (!userIsAdmin) // if user is admin, no need to keep running this block, people being removed from admin is so rare I'm not worried about dealing with that { foreach (var radio in sessionInfo.RadioInfo.Radios) // look through all the radios (normally only 1) { foreach (var freq in radio.Frequencies) // look through all the frequencies { if (freq.FrequencyName == "@ADMIN") // check to see if there's a radio named ADMIN { userIsAdmin = true; // if so, user is admin, so we know they can control cautions lblUserIsAdmin.Text = "Admin: True"; chkControlsCautions.Enabled = true; } else { if (!userIsAdmin) // this shouldn't even be reached if user is admin, but just in case { lblUserIsAdmin.Text = "Admin: False"; } } } } } #endregion } else { Console.WriteLine("Not valid YAML!!"); // this shouldn't ever really be reached, if so, there's something wrong with the wrapper } } } catch (Exception exc) { WriteToLogFile("OnSessionInfoUpdated", exc.Message.ToString()); } }
// Do things when session info updates (seems to be whenever a car crosses the line) private void OnSessionInfoUpdated(object sender, iRacingSdkWrapper.SdkWrapper.SessionInfoUpdatedEventArgs sessionArgs) { if (isClosing) { return; // if program is closing, just return so we don't waste time doing this stuff } if (!sessionArgs.SessionInfo.IsValidYaml) { return; // if the yaml isn't valid, no reason to bother with the rest } try { DeserializerBuilder deserializerBuilder = new DeserializerBuilder(); deserializerBuilder.WithNamingConvention(new PascalCaseNamingConvention()); Deserializer deserializer = deserializerBuilder.Build(); var input = new StringReader(sessionArgs.SessionInfo.Yaml); // read the yaml var sessionInfo = deserializer.Deserialize <SDKReturn>(input); // deserialize the yaml #region Radios lblIsAdmin.Text = $"User is Admin: {isAdmin}"; // update label foreach (Frequencies r in sessionInfo.RadioInfo.Radios[0].Frequencies) { if (r.FrequencyName == "@ADMIN") { isAdmin = true; // if user has the ADMIN radio channel, we can safely assume they're an admin in the session } } #endregion #region Drivers Info if ((driversInSession == null) || (driversInSession.Count != sessionInfo.DriverInfo.Drivers.Count)) // if driver list is empty, or one of the lists is longer than the other { driversInSession = sessionInfo.DriverInfo.Drivers; // set local driver list equal to drivers in the server } #endregion #region Race Session Info foreach (var session in sessionInfo.SessionInfo.Sessions) // look through all the sessions (normally they're Practice, Qualifying, and Race) { if (session.SessionType == "Race") // find the race part session (ignore qual and practice parts of the active server, if they exist) { var raceSession = session; // the session we're dealing with is the race session, just using this to shorten the variable to less than 50 characters currentLapRace = raceSession.ResultsLapsComplete; // get the laps complete, this is helpful for when someone in top 10 is not on lead lap lblCurrentLap.Text = $"Current Lap: {currentLapRace + 1} of {raceSession.SessionLaps}"; // update current lap label #region close pits if (!isPitsClosed && !isYellowOut) // make sure pits are open { if (!IsSegmentEnded(1)) // check if segment 1 is ended { // if not, we're in segment 1 if (currentLapRace >= (segment1EndLap - userSettings.ClosePitsLap)) // if it's 5 laps or less away from segment 1 { ClosePits(); // close pits } } else { // otherwise we're in segment 2 if (currentLapRace >= segment2EndLap - userSettings.ClosePitsLap) // 5 laps or less { ClosePits(); // close pits } } } #endregion currentPositions = raceSession.ResultsPositions; // update positions to equal live results if (currentPositions != null) // make sure currentPositions list is not null, otherwise program will crash { IEnumerable <Positions> carsOnLeadLapQuery = // get cars on lead lap from position in currentPositions where position.Lap == 0 select position; lblCarsOnLead.Text = $"Cars on Lead Lap: {carsOnLeadLap.Count()} of {currentPositions.Count}"; // update label carsOnLeadLap = carsOnLeadLapQuery.ToList(); // convert cars on lead query lap to list if (!IsSegmentEnded(1) || (IsSegmentEnded(1) && !IsSegmentEnded(2))) // if segment 1 is not ended { if (currentLapRace >= segment1EndLap + 1 && segment1Top10[9].CarIdx == -1 || currentLapRace >= segment2EndLap + 1 && segment2Top10[9].CarIdx == -1) { // if we're on the lap of a segment end, start checking if we should throw caution if (!isYellowOut) // make sure yellow hasn't come out { GetSegmentResults(false); } else // if it has { GetSegmentResults(true); } } } } } } #endregion } catch (Exception exc) { Console.WriteLine(exc.Message.ToString()); } }