public async Task <IMapSearchResult> FindBeatmap(IMapSearchArgs args, CancellationToken cancellationToken) { if (args == null || string.IsNullOrEmpty(args.OsuFilePath)) { return(null); } if (!File.Exists(args.OsuFilePath)) { _logger.Log($"Osu file supplied in search args was not found on disk! ({args.OsuFilePath})", LogLevel.Error); return(null); } (Beatmap beatmap, CancelableAsyncLazy <IPpCalculator> ppTask)result; try { result = await LazerMapLoader.LoadLazerBeatmapWithPerformanceCalculator(args.OsuFilePath, args.PlayMode, _modParser.GetModsFromEnum((int)args.Mods), _logger, cancellationToken); } catch (OperationCanceledException) { throw; } catch (Exception ex) { ex.Data["PreventedCrash"] = 1; ex.Data["location"] = args.OsuFilePath; _logger.Log(ex, LogLevel.Critical); return(null); } if (result.beatmap == null) { var ex = new BeatmapLoadFailedException(); ex.Data["location"] = args.OsuFilePath; _logger.Log(ex, LogLevel.Critical); _logger.Log($"Failed to load beatmap located at {args.OsuFilePath}", LogLevel.Warning); return(null); } return(new MapSearchResult(args) { BeatmapsFound = { result.beatmap }, SharedObjects = { result.ppTask } }); }
private async Task ConsumerTask(CancellationToken token) { while (true) { //Forcefully queue removal of cache entries //TODO: more than anything this is a hack, needs proper debounce logic instead of using memorycache. memoryCache.Trim(100); if (token.IsCancellationRequested) { return; } if (filesChanged.TryDequeue(out var fsArgs)) { _settings.Add(_names.LoadingRawBeatmaps.Name, true); Interlocked.Increment(ref _numberOfBeatmapsCurrentlyBeingLoaded); _logger.Log($">Processing beatmap located at {fsArgs.FullPath}", LogLevel.Debug); Beatmap beatmap; try { beatmap = await BeatmapHelpers.ReadBeatmap(fsArgs.FullPath); } catch (Exception ex) { ex.Data["PreventedCrash"] = 1; ex.Data["location"] = fsArgs.FullPath; _logger.Log(ex, LogLevel.Critical); Interlocked.Decrement(ref _numberOfBeatmapsCurrentlyBeingLoaded); continue; } if (beatmap == null) { var ex = new BeatmapLoadFailedException(); ex.Data["location"] = fsArgs.FullPath; ex.Data["changeType"] = fsArgs.ChangeType; _logger.Log(ex, LogLevel.Critical); _logger.Log($"Failed to load beatmap located at {fsArgs.FullPath}", LogLevel.Warning); Interlocked.Decrement(ref _numberOfBeatmapsCurrentlyBeingLoaded); continue; } _databaseController.StoreTempBeatmap(beatmap); _logger.Log(">Added new Temporary beatmap {0} - {1} [{2}]", LogLevel.Information, beatmap.ArtistRoman, beatmap.TitleRoman, beatmap.DiffName); if (Interlocked.Decrement(ref _numberOfBeatmapsCurrentlyBeingLoaded) == 0) { _settings.Add(_names.LoadingRawBeatmaps.Name, false); } if (lastMapSearchArgs != null && ( (lastMapSearchArgs.Artist == beatmap.Artist && lastMapSearchArgs.Title == beatmap.Title && lastMapSearchArgs.Diff == beatmap.DiffName ) || lastMapSearchArgs.MapId == beatmap.MapId )) { NewOsuEvent?.Invoke(this, new MapSearchArgs($"OsuMemory-FolderWatcherReplay", OsuEventType.MapChange) { Artist = beatmap.Artist, MapHash = beatmap.Md5, Title = beatmap.Title, Diff = beatmap.DiffName, EventType = OsuEventType.MapChange, PlayMode = beatmap.PlayMode, Status = lastMapSearchArgs.Status, MapId = beatmap.MapId > 0 ? beatmap.MapId : -123 }); } } Thread.Sleep(5); } }