public void BasicAddNewSongOpWorks() { SetupPlaylistsWithSongs(1, 1); using (var fp = GetProvider()) { var q = GetQaeConfig(fp); using (QuestomAssetsEngine qae = new QuestomAssetsEngine(q)) { var song = new BeatSaberSong() { SongID = "TESTSONG2", CustomSongPath = MakeTestSongDir() }; bool calledStatusChangeStarted = false; bool calledStatusChangeComplete = false; var newSongOp = new AddNewSongToPlaylistOp(song, "someplaylist0", false); qae.OpManager.OpStatusChanged += (sender, op) => { if (op.Status == OpStatus.Started) { calledStatusChangeStarted = true; } if (op.Status == OpStatus.Complete) { calledStatusChangeComplete = true; } }; qae.OpManager.QueueOp(newSongOp); while (qae.OpManager.IsProcessing) { System.Threading.Thread.Sleep(100); } //give it an extra bit of time to make sure events get fired System.Threading.Thread.Sleep(200); Assert.IsTrue(calledStatusChangeStarted, "Did not get OpStatusChanged event for status Started!"); Assert.IsTrue(calledStatusChangeComplete, "Did not get OpStatusChanged event for status Complete!"); qae.Save(); } using (QuestomAssetsEngine qae = new QuestomAssetsEngine(q)) { var cfg = qae.GetCurrentConfig(); var song = cfg.Playlists.FirstOrDefault(x => x.PlaylistID == "someplaylist0")?.SongList?.FirstOrDefault(x => x.SongID == "TESTSONG2"); Assert.NotNull(song, "Couldn't find the song the op was supposed to add!"); //todo: more tests on this } Assert.Pass(); } }
/// <summary> /// Queues an operation for adding a song to a playlist /// </summary> /// <param name="songID">The song ID to use for the imported song</param> /// <param name="songPath">The path, RELATIVE TO THE BEATONDATA ROOT, of where the custom song exists</param> /// <param name="playlist">The playlist to add the song to</param> private AssetOp QueueAddSongToPlaylistOp(string songID, string songPath, BeatSaberPlaylist playlist, Action completionCallback = null, bool suppressToast = false) { var qae = _getEngine(); var bsSong = new BeatSaberSong() { SongID = songID, //ref: was Path.GetFileName(toInst.DownloadPath), CustomSongPath = songPath //ref: was toInst.DownloadPath }; var addOp = new AddNewSongToPlaylistOp(bsSong, playlist.PlaylistID); addOp.OpFinished += (s, op) => { //TODO: i'd like for this to come back out of the config rather than being added here if (!playlist.SongList.Any(x => x.SongID == bsSong.SongID)) { playlist.SongList.Add(bsSong); } if (op.Status == OpStatus.Complete) { if (!suppressToast) { _showToast($"Song Added", $"{songID} was downloaded and added successfully", ClientModels.ToastType.Success); } } else if (op.Status == OpStatus.Failed) { if (op.Exception as AddSongException != null) { var ex = op.Exception as AddSongException; if (ex.FailType == AddSongFailType.SongExists) { //don't show toast for a song already existing } else if (ex.FailType == AddSongFailType.InvalidFormat) { if (!suppressToast) { _showToast($"Song Invalid", $"{songID} failed to import, it wasn't in a valid format.", ClientModels.ToastType.Error); } } else { if (!suppressToast) { _showToast($"Song Failed", $"{songID} failed to import!", ClientModels.ToastType.Error); } } } else { if (!suppressToast) { _showToast($"Song Failed", $"{songID} failed to import!", ClientModels.ToastType.Error); } } } completionCallback?.Invoke(); }; qae.OpManager.QueueOp(addOp); return(addOp); }