/// <summary>
 /// Tries to add the provided PlaylistSong to the SongHistory. Returns false if the PlaylistSong is null, or its hash is null/empty.
 /// </summary>
 /// <param name="song"></param>
 /// <returns></returns>
 /// <exception cref="InvalidOperationException">Thrown when trying to access data before Initialize is called on HistoryManager.</exception>
 public bool TryAdd(PlaylistSong song, HistoryFlag flag)
 {
     if (!IsInitialized)
     {
         throw new InvalidOperationException("HistoryManager is not initialized.");
     }
     if (song == null)
     {
         return(false);
     }
     return(TryAdd(song.Hash, song.ToString(), flag));
 }
Beispiel #2
0
        public void TryAdd_PlaylistSong()
        {
            var path           = Path.Combine(Path.Combine(HistoryTestPathDir, "BeatSyncHistory.json"));
            var historyManager = new HistoryManager(path);

            historyManager.Initialize();
            string       hash     = "LKSJDFLKJASDLFKJ";
            string       songName = "TestName";
            string       songKey  = "aaaa";
            string       mapper   = "SomeMapper";
            PlaylistSong song     = new PlaylistSong(hash, songName, songKey, mapper);
            var          success  = historyManager.TryAdd(song, 0);

            Assert.IsTrue(success);
            success = historyManager.TryGetValue(hash, out var retrieved);
            Assert.IsTrue(success);
            Assert.AreEqual(song.ToString(), retrieved.SongInfo);
        }
 public HistoryEntry(PlaylistSong song, HistoryFlag flag = 0)
 {
     SongInfo = song.ToString();
     Flag     = flag;
     Date     = DateTime.Now;
 }