Merge branch 'archer-polyoke' into bruce-polyoke

This commit is contained in:
Matt Bruce 2016-09-05 14:19:42 -05:00
commit 6923b5f73a
3 changed files with 52 additions and 1 deletions

View File

@ -39,6 +39,10 @@ namespace KaraokePlayer.Classes
{ {
get { return string.Format("controllers/{0}/player/queue/0/", this.Id); } get { return string.Format("controllers/{0}/player/queue/0/", this.Id); }
} }
private string FavoritesPath
{
get { return string.Format("controllers/{0}/favorites/", this.Id); }
}
public string Id { get; set; } public string Id { get; set; }
public Song CurrentSong { get; set; } public Song CurrentSong { get; set; }
@ -115,6 +119,7 @@ namespace KaraokePlayer.Classes
{ {
CurrentSong = item.Song; CurrentSong = item.Song;
_songChanged(new ControllerSongChangedEventArgs(item.Song)); _songChanged(new ControllerSongChangedEventArgs(item.Song));
UpdateFavorites(item.Song);
} }
} }
@ -128,5 +133,35 @@ namespace KaraokePlayer.Classes
_state = newstate; _state = newstate;
_stateChanged(new ControllerStateChangedEventArgs(newstate)); _stateChanged(new ControllerStateChangedEventArgs(newstate));
} }
private void UpdateFavorites(Song song)
{
//get favorites
FavoriteSong favorite = null;
List<FavoriteSong> favorites = _client.Get(FavoritesPath).ResultAs<List<FavoriteSong>>();
if (favorites == null) favorites = new List<FavoriteSong>();
//unique song is based on the path
favorite = favorites.SingleOrDefault(f => f.Path == song.Path);
if (favorite == null)
{
favorite = new FavoriteSong();
favorite.Artist = song.Artist;
favorite.Title = song.Title;
favorite.Genre = song.Genre;
favorite.Path = song.Path;
favorite.Year = song.Year;
favorite.Count = 1;
favorites.Add(favorite);
}
else {
favorite.Count += 1;
}
//take the top 100 songs
var top100 = favorites.OrderByDescending(f => f.Count).Take(100);
_client.Set(FavoritesPath, top100);
}
} }
} }

View File

@ -0,0 +1,15 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Herse.Models
{
public class FavoriteSong : Song
{
[JsonProperty("count")]
public int Count { get; set; }
}
}

View File

@ -44,6 +44,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="FavoriteSong.cs" />
<Compile Include="FileType.cs" /> <Compile Include="FileType.cs" />
<Compile Include="PlayerState.cs" /> <Compile Include="PlayerState.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />