public void UpdateSessionBasics(SessionType type, SessionPhase phase) { if (phase == SessionPhase.None) { return; } if (_session == null) { _session = CreateSession(type); Logger.Log($"{type} session started - new weekend"); SessionStarted?.Invoke(this, EventArgs.Empty); } else if (type != _session.Type) { if (IsInProgress(_session.Phase)) { EndTimedPhase(); } Logger.Log($"{_session.Type} session ended"); SessionEnded?.Invoke(this, EventArgs.Empty); var isPartOfWeekend = type > _session.Type; _session = isPartOfWeekend ? CreateSession(type, _session.WeekendId) : CreateSession(type); var message = isPartOfWeekend ? $"{type} session started - part of existing weekend" : $"{type} session started - new weekend"; Logger.Log(message, Severity.Verbose); SessionStarted?.Invoke(this, EventArgs.Empty); } // We capture this so we the nested methods can use the up-to-date session var oldPhase = _session.Phase; _session.UpdateSessionInfo(type, phase); // If we are in the same session, check if we are advancing through the timed phases if (type == _session.Type) { if (IsStarting(oldPhase) && IsInProgress(_session.Phase)) { StartTimedPhase(); } if (IsInProgress(oldPhase) && IsEnding(_session.Phase)) { EndTimedPhase(); } } }
private RaceSession CreateSession(SessionType type, Guid?weekendId = null) { var session = new RaceSession(type, weekendId); return(session); }