Beispiel #1
0
        private void OnRaceFinished(object sender, GameEndedArgs e)
        {
            var basic   = e.StartProperties.BasicProperties;
            var bestLap = e.Result?.GetExtraByType <Game.ResultExtraBestLap>();

            var carId   = basic?.CarId;
            var trackId = basic?.TrackId;

            if (trackId != null && basic.TrackConfigurationId != null)
            {
                trackId = $@"{trackId}/{basic.TrackConfigurationId}";
            }

            var time = carId == null || trackId == null || bestLap == null ||
                       bestLap.IsCancelled ? (TimeSpan?)null : bestLap.Time;

            if (SettingsHolder.Drive.WatchForSharedMemory)
            {
                var last = PlayerStatsManager.Instance.Last;

                if (last != null)
                {
                    if (carId == null)
                    {
                        carId = last.CarId;
                    }

                    if (trackId == null)
                    {
                        trackId = last.TrackId;
                    }

                    var sharedTime = last.BestLap;
                    if (sharedTime.HasValue)
                    {
                        time = sharedTime.Value;
                    }
                }
            }

            if (time.HasValue && carId != null && trackId != null)
            {
                Logging.Here();
                AddEntry(new LapTimeEntry(SourceId, carId, trackId, DateTime.Now, time.Value));
                NewEntryAdded?.Invoke(this, EventArgs.Empty);
            }
            else
            {
                Logging.Warning($"Can’t save new lap time: time={time}, car={carId}, track={trackId}");
            }
        }
        public Task AddHistoryAsync(MusicPlaybackItem item)
        {
            if (!EnablePlaybackHistory)
            {
                // User disabled history.
                return(Task.CompletedTask);
            }

            if (LibraryService.IsIndexing)
            {
                return(Task.CompletedTask);
            }

            var file = item.File;

            if (!file.IsExternal)
            {
                var fileExist = context.MediaFiles.Any(f => f.Id == file.Id);

                if (!fileExist)
                {
                    return(Task.CompletedTask);
                }

                _historyCache.Insert(0, item);
                NewEntryAdded?.Invoke(this, item);
                return(AddHistoryInternal(new DbPlaybackHistory
                {
                    RelatedMediaFileId = file.Id,
                    PlaybackTime = DateTimeOffset.Now
                }));
            }
            else
            {
                return(Task.CompletedTask);
            }
        }
Beispiel #3
0
 private static void OnNewEntryAdded(LogEntry entry)
 {
     NewEntryAdded?.Invoke(null, new NewEntryEventArgs(entry));
 }
Beispiel #4
0
 private void RaiseNewEntryAddedEvent(object sender, EventArgs e)
 {
     NewEntryAdded?.Invoke(this, EventArgs.Empty);
 }