/// <summary> /// Initialises a new instance of the <see cref="SpeedCaptureMessage"/> class /// and specifies the capture location <paramref name="location"/> and the captured /// <paramref name="speeds"/>. /// </summary> /// <param name="location">The capture location.</param> /// <param name="speeds">The captured speeds.</param> /// <exception cref="System.ArgumentNullException"> /// Thrown when <paramref name="speeds"/> is <see langword="null"/>. /// </exception> public SpeedCaptureMessage(SpeedCaptureLocation location, KeyValuePair<string, int>[] speeds) { Guard.NotNull(speeds, "speeds"); Location = location; Speeds = Array.AsReadOnly(speeds); }
/// <summary> /// Initialises a new instance of the <see cref="SpeedCaptureModel"/> class. /// </summary> /// <param name="driver">The driver which posted the speed.</param> /// <param name="location">The capture location.</param> /// <param name="speed">The captured speed.</param> /// <exception cref="System.ArgumentNullException"> /// Thrown when <paramref name="driver"/> is <see langword="null"/>. /// </exception> public SpeedCaptureModel(DriverModel driver, SpeedCaptureLocation location, int speed) { Guard.NotNull(driver, "driver"); Driver = driver; Location = location; Speed = speed; }
/// <summary> /// Initialises a new instance of the <see cref="SetDriverSpeedMessage"/> class and /// specifies if the Id of the driver, the speed capture location and the speed. /// </summary> /// <param name="driverId">The Id of the driver.</param> /// <param name="location">The speed capture location.</param> /// <param name="speed">The driver's speed.</param> /// <exception cref="System.ArgumentOutOfRangeException"> /// Thrown when <paramref name="driverId"/> or <paramref name="speed"/> is negative. /// </exception> public SetDriverSpeedMessage(int driverId, SpeedCaptureLocation location, int speed) : base(driverId) { Guard.InRange(speed >= 0, "speed"); Location = location; Speed = speed; }
private void UpdateCollection(SpeedCaptureLocation location, int driverId, int speed) { var collection = GetInnerCollection(location); var existing = collection.Where(x => x.Driver.Id == driverId).FirstOrDefault(); if(existing != null) { if(speed <= existing.Speed) { return; } collection.Remove(existing); } if(collection.Count < MaxCollectionSize) { int insertIndex = collection.Count; for(int i = 0; i < collection.Count; ++i) { if(speed > collection[i].Speed) { insertIndex = i; break; } } collection.Insert(insertIndex, CreateSpeedCaptureModel(location, driverId, speed)); } else if(speed > collection.Last().Speed) { for(int i = 0; i < collection.Count; ++i) { if(speed > collection[i].Speed) { var previous = collection[i]; for(int j = i + 1; j < collection.Count; ++j) { var temp = collection[j]; collection[j] = previous; previous = temp; } collection[i] = CreateSpeedCaptureModel(location, driverId, speed); break; } } } NotifyIsEmptyChanged(); }
private ObservableCollection<SpeedCaptureModel> GetInnerCollection(SpeedCaptureLocation location) { switch(location) { case SpeedCaptureLocation.S1: return InnerS1; case SpeedCaptureLocation.S2: return InnerS2; case SpeedCaptureLocation.S3: return InnerS3; case SpeedCaptureLocation.Straight: return InnerStraight; default: throw Guard.ArgumentOutOfRange("location"); } }
private SpeedCaptureModel CreateSpeedCaptureModel(SpeedCaptureLocation location, int driverId, int speed) { return new SpeedCaptureModel(DriverLocator.GetDriver(driverId), location, speed); }
/// <summary> /// Gets the capture collection for the specified <paramref name="location"/>. /// </summary> /// <param name="location">the capture location.</param> /// <returns>The capture collection for the specified <paramref name="location"/>.</returns> /// <exception cref="System.ArgumentOutOfRangeException"> /// Thrown when <paramref name="location"/> is not valid. /// </exception> public ReadOnlyObservableCollection<SpeedCaptureModel> GetCollection(SpeedCaptureLocation location) { switch(location) { case SpeedCaptureLocation.S1: return S1; case SpeedCaptureLocation.S2: return S2; case SpeedCaptureLocation.S3: return S3; case SpeedCaptureLocation.Straight: return Straight; default: throw Guard.ArgumentOutOfRange("location"); } }