public override int GetHashCode() { int hash = 1; if (postedTime_ != null) { hash ^= PostedTime.GetHashCode(); } if (Narration.Length != 0) { hash ^= Narration.GetHashCode(); } hash ^= lines_.GetHashCode(); if (assignedGuest_ != null) { hash ^= AssignedGuest.GetHashCode(); } if (EnteredByUserId.Length != 0) { hash ^= EnteredByUserId.GetHashCode(); } if (IsManualEntry != false) { hash ^= IsManualEntry.GetHashCode(); } if (id_ != null) { hash ^= Id.GetHashCode(); } return(hash); }
/// <summary> /// Initialises a new instance of the <see cref="SetDriverPitTimeMessage"/> class and /// specifies if the Id of the driver, the pit time and the lap number on which the /// driver pitted. /// </summary> /// <param name="driverId">The Id of the driver.</param> /// <param name="pitTime">The pit time, inclusive of the time taken to travel the pit lane.</param> /// <exception cref="System.ArgumentOutOfRangeException"> /// Thrown when <paramref name="driverId"/> is not positive. /// </exception> /// <exception cref="System.ArgumentNullException"> /// Thrown when <paramref name="pitTime"/> is <see langword="null"/>. /// </exception> public SetDriverPitTimeMessage(int driverId, PostedTime pitTime) : base(driverId) { Guard.NotNull(pitTime, "pitTime"); PitTime = pitTime; }
public override int GetHashCode() { int hash = 1; if (postedTime_ != null) { hash ^= PostedTime.GetHashCode(); } if (Narration.Length != 0) { hash ^= Narration.GetHashCode(); } hash ^= lines_.GetHashCode(); if (id_ != null) { hash ^= Id.GetHashCode(); } if (WasManuallyEntered != false) { hash ^= WasManuallyEntered.GetHashCode(); } if (enteredBy_ != null) { hash ^= EnteredBy.GetHashCode(); } return(hash); }
public override int GetHashCode() { int hash = 1; if (Description.Length != 0) { hash ^= Description.GetHashCode(); } if (preTaxFeeSubtotal_ != null) { hash ^= PreTaxFeeSubtotal.GetHashCode(); } hash ^= taxesFees_.GetHashCode(); if (postedTime_ != null) { hash ^= PostedTime.GetHashCode(); } hash ^= taxes_.GetHashCode(); hash ^= fees_.GetHashCode(); if (parentLine_ != null) { hash ^= ParentLine.GetHashCode(); } hash ^= folioSwaps_.GetHashCode(); return(hash); }
/// <summary> /// Initialises a new instance of the <see cref="ReplaceDriverLapTimeMessage"/> class and /// specifies if the Id of the driver and the previous lap time replacement. /// </summary> /// <param name="driverId">The Id of the driver.</param> /// <param name="replacement">The previous lap time replacement.</param> /// <exception cref="System.ArgumentOutOfRangeException"> /// Thrown when <paramref name="driverId"/> is not positive. /// </exception> /// <exception cref="System.ArgumentNullException"> /// Thrown when <paramref name="replacement"/> is <see langword="null"/>. /// </exception> public ReplaceDriverLapTimeMessage(int driverId, PostedTime replacement) : base(driverId) { Guard.NotNull(replacement, "replacement"); Replacement = replacement; }
/// <summary> /// Initialises a new instance of the <see cref="SetDriverLapTimeMessage"/> class and /// specifies if the Id of the driver and the lap time set by the driver. /// </summary> /// <param name="driverId">The Id of the driver.</param> /// <param name="lapTime">The lap time.</param> /// <exception cref="System.ArgumentOutOfRangeException"> /// Thrown when <paramref name="driverId"/> is not positive. /// </exception> /// <exception cref="System.ArgumentNullException"> /// Thrown when <paramref name="lapTime"/> is <see langword="null"/>. /// </exception> public SetDriverLapTimeMessage(int driverId, PostedTime lapTime) : base(driverId) { Guard.NotNull(lapTime, "lapTime"); LapTime = lapTime; }
/// <summary> /// Initialises a new instance of the <see cref="SetDriverSectorTimeMessage"/> class and /// specifies if the Id of the driver, the sector number, and the sector time. /// </summary> /// <param name="driverId">The Id of the driver.</param> /// <param name="sectorNumber">The sector number.</param> /// <param name="sectorTime">The sector time.</param> /// <exception cref="System.ArgumentOutOfRangeException"> /// Thrown when <paramref name="driverId"/> or <paramref name="sectorNumber"/> is not positive. /// </exception> /// <exception cref="System.ArgumentNullException"> /// Thrown when <paramref name="sectorTime"/> is <see langword="null"/>. /// </exception> public SetDriverSectorTimeMessage(int driverId, int sectorNumber, PostedTime sectorTime) : base(driverId) { Guard.InRange(sectorNumber > 0, "sectorNumber"); Guard.NotNull(sectorTime, "sectorTime"); SectorNumber = sectorNumber; SectorTime = sectorTime; }
public static string LapTime(PostedTime value) { if(value == null) { return String.Empty; } return LapTime(value.Time); }
/// <summary> /// Initialises a new instance of the <see cref="ReplaceDriverSectorTimeMessage"/> class and /// specifies if the Id of the driver, the sector number, and the previous sector time /// replacement. /// </summary> /// <param name="driverId">The Id of the driver.</param> /// <param name="sectorNumber">The sector number.</param> /// <param name="replacement">The previous sector time replacement.</param> /// <exception cref="System.ArgumentOutOfRangeException"> /// Thrown when <paramref name="driverId"/> or <paramref name="sectorNumber"/> is not positive. /// </exception> /// <exception cref="System.ArgumentNullException"> /// Thrown when <paramref name="replacement"/> is <see langword="null"/>. /// </exception> public ReplaceDriverSectorTimeMessage(int driverId, int sectorNumber, PostedTime replacement) : base(driverId) { Guard.InRange(sectorNumber > 0, "sectorNumber"); Guard.NotNull(replacement, "replacement"); SectorNumber = sectorNumber; Replacement = replacement; }
/// <summary> /// Initialises a new instance of the <see cref="LapHistoryEntry"/> class. /// </summary> /// <param name="s1">The sector one time set.</param> /// <param name="s2">The sector two time set.</param> /// <param name="s3">The sector three time set.</param> /// <param name="lap">The overall lap time set.</param> /// <exception cref="System.ArgumentNullException"> /// Thrown when all arguments are <see langword="null"/>. /// </exception> /// <exception cref="System.ArgumentException"> /// Thrown when specified times are not all for the same lap. /// </exception> public LapHistoryEntry(PostedTime s1, PostedTime s2, PostedTime s3, PostedTime lap) { CheckOneIsNotNull(s1, s2, s3, lap); CheckLapNumbersAreEqual(s1, s2, s3, lap); S1 = s1; S2 = s2; S3 = s3; Lap = lap; }
public void can_create() { int lapNumber = 10; var time = TimeSpan.FromSeconds(90); var type = PostedTimeType.PersonalBest; var actual = new PostedTime(time, type, lapNumber); Assert.Equal(lapNumber, actual.LapNumber); Assert.Equal(time, actual.Time); Assert.Equal(type, actual.Type); }
public void ctor_throws_if_all_times_are_null() { var time = new PostedTime(TimeSpan.FromSeconds(54.6), PostedTimeType.Normal, 1); Assert.DoesNotThrow(() => new LapHistoryEntry(time, null, null, null)); Assert.DoesNotThrow(() => new LapHistoryEntry(null, time, null, null)); Assert.DoesNotThrow(() => new LapHistoryEntry(null, null, time, null)); Assert.DoesNotThrow(() => new LapHistoryEntry(null, null, null, time)); Assert.Throws<ArgumentNullException>(() => new LapHistoryEntry(null, null, null, null)); }
public static string SectorTime(PostedTime value) { if(value == null) { return String.Empty; } TimeSpan time = value.Time; return F("{0}.{1:0}", time.Minutes * 60 + time.Seconds, time.Milliseconds / 100); }
public IActionResult AddCuberSolve(PostedTime solve) { if (solve.Time > 0) { CuberService.AddSolve(solve); return(Ok()); } else { return(Content("Invalid request. The solve cannot have a negative time")); } }
/// <summary> /// Adds a single solve to a cuber /// </summary> /// <param name="solve"></param> public void AddSolve(PostedTime solve) { var conn = new MySqlConnection(ConnectionString); conn.Open(); var query = @"INSERT INTO solve (time, event, cuber_id) VALUES (@time, @event, @cuberId)"; var cmd = new MySqlCommand(query, conn); cmd.Parameters.AddWithValue("@cuberId", solve.CuberId); cmd.Parameters.AddWithValue("@time", solve.Time); cmd.Parameters.AddWithValue("@event", solve.Event); cmd.ExecuteNonQuery(); conn.Close(); }
public void can_create() { var time = TimeSpan.FromSeconds(45.5); var s1 = new PostedTime(time, PostedTimeType.Normal, 1); var s2 = new PostedTime(time, PostedTimeType.Normal, 1); var s3 = new PostedTime(time, PostedTimeType.Normal, 1); var lap = new PostedTime(time, PostedTimeType.Normal, 1); var actual = new LapHistoryEntry(s1, s2, s3, lap); Assert.Same(s1, actual.S1); Assert.Same(s2, actual.S2); Assert.Same(s3, actual.S3); Assert.Same(lap, actual.Lap); Assert.Equal(1, actual.LapNumber); }
public void MergeFrom(AccountingTransactionWithGuest other) { if (other == null) { return; } if (other.postedTime_ != null) { if (postedTime_ == null) { postedTime_ = new global::Google.Protobuf.WellKnownTypes.Timestamp(); } PostedTime.MergeFrom(other.PostedTime); } if (other.Narration.Length != 0) { Narration = other.Narration; } lines_.Add(other.lines_); if (other.assignedGuest_ != null) { if (assignedGuest_ == null) { assignedGuest_ = new global::HOLMS.Types.CRM.Guests.Guest(); } AssignedGuest.MergeFrom(other.AssignedGuest); } if (other.EnteredByUserId.Length != 0) { EnteredByUserId = other.EnteredByUserId; } if (other.IsManualEntry != false) { IsManualEntry = other.IsManualEntry; } if (other.id_ != null) { if (id_ == null) { id_ = new global::HOLMS.Types.Primitive.Uuid(); } Id.MergeFrom(other.Id); } }
public void MergeFrom(AccountingTransaction other) { if (other == null) { return; } if (other.postedTime_ != null) { if (postedTime_ == null) { postedTime_ = new global::Google.Protobuf.WellKnownTypes.Timestamp(); } PostedTime.MergeFrom(other.PostedTime); } if (other.Narration.Length != 0) { Narration = other.Narration; } lines_.Add(other.lines_); if (other.id_ != null) { if (id_ == null) { id_ = new global::HOLMS.Types.Primitive.Uuid(); } Id.MergeFrom(other.Id); } if (other.WasManuallyEntered != false) { WasManuallyEntered = other.WasManuallyEntered; } if (other.enteredBy_ != null) { if (enteredBy_ == null) { enteredBy_ = new global::HOLMS.Types.IAM.StaffMemberIndicator(); } EnteredBy.MergeFrom(other.EnteredBy); } }
public void MergeFrom(PostedChargeCredit other) { if (other == null) { return; } if (other.Description.Length != 0) { Description = other.Description; } if (other.preTaxFeeSubtotal_ != null) { if (preTaxFeeSubtotal_ == null) { preTaxFeeSubtotal_ = new global::HOLMS.Types.Primitive.MonetaryAmount(); } PreTaxFeeSubtotal.MergeFrom(other.PreTaxFeeSubtotal); } taxesFees_.Add(other.taxesFees_); if (other.postedTime_ != null) { if (postedTime_ == null) { postedTime_ = new global::Google.Protobuf.WellKnownTypes.Timestamp(); } PostedTime.MergeFrom(other.PostedTime); } taxes_.Add(other.taxes_); fees_.Add(other.fees_); if (other.parentLine_ != null) { if (parentLine_ == null) { parentLine_ = new global::HOLMS.Types.Money.Accounting.AccountingTransactionLineIndicator(); } ParentLine.MergeFrom(other.ParentLine); } folioSwaps_.Add(other.folioSwaps_); }
private void ReplaceCurrentMinimum(PostedTime replacement) { if(InnerItems.Count == 1 || replacement.CompareTo(Minimum) < 0) { Minimum = replacement; } }
private void ReplaceCurrentStatistics(PostedTime replacement) { ReplaceCurrentMinimum(replacement); ReplaceCurrentMaximum(replacement); ReplaceCurrentMean(replacement); UpdateRange(); ReplaceCurrentTypeCounts(replacement); UpdateCurrentAndDelta(); }
/// <summary> /// Replaces the current item with the specified <paramref name="replacement"/>. /// </summary> /// <param name="replacement">The replacement item.</param> /// <exception cref="System.ArgumentNullException"> /// Thrown when <paramref name="replacement"/> is <see langword="null"/>. /// </exception> /// <exception cref="System.InvalidOperationException"> /// Thrown when the collection is empty. /// </exception> public void ReplaceCurrent(PostedTime replacement) { Guard.NotNull(replacement, "replacement"); if(InnerItems.Count == 0) { throw Guard.PostedTimeCollectionModel_CurrentCannotBeReplaced(); } InnerItems[InnerItems.Count - 1] = replacement; ReplaceCurrentStatistics(replacement); }
private void ReplaceCurrentMean(PostedTime replacement) { if(replacement.Time != Current.Time) { SumOfValues -= Current.Time.Ticks; SumOfValues += replacement.Time.Ticks; Mean = TimeSpan.FromTicks(SumOfValues / InnerItems.Count); } }
/// <summary> /// Resets all state information associated with this driver. /// </summary> public void Reset() { CarNumber = 0; _columnsWithValue = new BitVector32(); CurrentSectorNumber = 0; IsExpectingPitTimes = false; LapNumber = 0; LastGapMessage = null; LastIntervalMessage = null; LastLapTime = null; LastSectors = new PostedTime[3]; Name = null; Position = 0; Status = DriverStatus.InPits; }
/// <summary> /// Adds the specified <paramref name="item"/> to this collection. /// </summary> /// <param name="item">The item to add to this collection.</param> /// <exception cref="System.ArgumentNullException"> /// Thrown when <paramref name="item"/> is <see langword="null"/>. /// </exception> public void Add(PostedTime item) { Guard.NotNull(item, "item"); InnerItems.Add(item); UpdateStatistics(item); }
/// <summary> /// Tries to set the new fastest lap time using the given qually time. /// </summary> /// <param name="driverId">The Id of the driver which posted the time.</param> /// <param name="quallyTime">The qually time.</param> private void TrySetLapUsingQuallyTime(int driverId, TimeSpan quallyTime) { var driver = DriverLocator.GetDriver(driverId); var postedTime = new PostedTime(quallyTime, PostedTimeType.Normal, driver.LapsCompleted); TrySetLap(driverId, postedTime); }
/// <summary> /// Tries to set the new fastest sector time for the one-based specified sector number. /// </summary> /// <param name="sectorNumber">The one-based sector time to set.</param> /// <param name="driverId">The Id of the driver which posted the time.</param> /// <param name="time">The time.</param> private void TrySetSector(int sectorNumber, int driverId, PostedTime time) { if(time.Type == PostedTimeType.SessionBest) { SetSector(sectorNumber, driverId, time.Time, time.LapNumber); } }
/// <summary> /// Tries to set the new fastest lap time. /// </summary> /// <param name="driverId">The Id of the driver which posted the time.</param> /// <param name="time">The time.</param> private void TrySetLap(int driverId, PostedTime time) { var isSessionBest = time.Type == PostedTimeType.SessionBest || // We only receive session best lap times during a race session so we determine here // if the specified time should be promoted. (CurrentSessionType != SessionType.Race && (Lap == null || time.Time < Lap.Time)); if(isSessionBest) { SetLap(driverId, time.Time, time.LapNumber); } }
/// <summary> /// Sets this driver's last sector time. /// </summary> /// <param name="sectorNumber">The one-based sector number.</param> /// <param name="time">The sector time.</param> /// <exception cref="System.ArgumentOutOfRangeException"> /// Thrown when <paramref name="sectorNumber"/> is zero or greater than three. /// </exception> /// <exception cref="System.ArgumentNullException"> /// Thrown when <paramref name="time"/> is <see langword="null"/>. /// </exception> public void SetLastSector(int sectorNumber, PostedTime time) { Guard.InRange(IsValidSectorNumber(sectorNumber), "sectorNumber"); Guard.NotNull(time, "time"); LastSectors[sectorNumber - 1] = time; }
private void UpdateStatistics(PostedTime item) { UpdateCurrentAndDelta(); UpdateMinimum(item); UpdateMaximum(item); UpdateMean(item); UpdateRange(); UpdateCount(); UpdateTypeCounts(item); }
private void UpdateMean(PostedTime item) { SumOfValues += item.Time.Ticks; Mean = TimeSpan.FromTicks(SumOfValues / InnerItems.Count); }
private void ReplaceCurrentTypeCounts(PostedTime replacement) { if(replacement.Type == Current.Type) { return; } switch(Current.Type) { case PostedTimeType.PersonalBest: PersonalBestCount = Math.Max(PersonalBestCount - 1, 0); break; case PostedTimeType.SessionBest: SessionBestCount = Math.Max(SessionBestCount - 1, 0); break; } switch(replacement.Type) { case PostedTimeType.PersonalBest: ++PersonalBestCount; break; case PostedTimeType.SessionBest: ++SessionBestCount; break; } }
private void UpdateMaximum(PostedTime item) { if(Maximum == null || item.CompareTo(Maximum) > 0) { Maximum = item; } }
private void CheckLapNumbersAreEqual(PostedTime s1, PostedTime s2, PostedTime s3, PostedTime lap) { int lapNumber = (s1 ?? s2 ?? s3 ?? lap).LapNumber; CheckLapNumber(s1, lapNumber, "s1"); CheckLapNumber(s2, lapNumber, "s2"); CheckLapNumber(s3, lapNumber, "s3"); CheckLapNumber(lap, lapNumber, "lap"); }
private void UpdateMinimum(PostedTime item) { if(Minimum == null || item.CompareTo(Minimum) < 0) { Minimum = item; } }
private void CheckOneIsNotNull(PostedTime s1, PostedTime s2, PostedTime s3, PostedTime lap) { if(s1 == null && s2 == null && s3 == null && lap == null) { throw Guard.LapHistoryEntry_AtLeastOneTimeMustBeSpecified(); } }
private void UpdateTypeCounts(PostedTime item) { if(item.Type == PostedTimeType.PersonalBest) { ++PersonalBestCount; } else if(item.Type == PostedTimeType.SessionBest) { ++SessionBestCount; } }
private static void CheckLapNumber(PostedTime time, int expectedLapNumber, string paramName) { if(time != null && time.LapNumber != expectedLapNumber) { throw Guard.LapHistoryEntry_AllTimesMustBeForSameLap(paramName); } }