public void VoteForPlaylistEntry(int index, Guid accessToken) { this.accessControl.VerifyVotingPreconditions(accessToken); PlaylistEntry entry = this.CurrentPlaylist.VoteFor(index); this.accessControl.RegisterVote(accessToken, entry); }
/// <summary> /// Returns whether a vote for the given access token and entry is already registered. /// </summary> public bool IsVoteRegistered(Guid accessToken, PlaylistEntry entry) { if (entry == null) { throw new ArgumentNullException("entry"); } AccessEndPoint endPoint = this.VerifyAccessToken(accessToken); return(endPoint.IsRegistered(entry)); }
/// <summary> /// Adds the specified song to the end of the playlist as guest. /// </summary> /// <remarks> /// <para>This method is intended only for guest access tokens.</para> /// <para> /// As soon as the song is added to the playlist, the entry is marked as "shadow voted". /// This means that it won't be favoured over other songs, like a regular vote, but stays at /// the end of the playlist. /// </para> /// <para> /// Shadow votes still decrease the available votes of the guest like regular votes, this /// prevents guests from spamming songs to the playlist. /// </para> /// </remarks> /// <param name="song">The song to add to the end of the playlist.</param> /// <param name="accessToken">The access token. Must have guest permission.</param> /// <exception cref="InvalidOperationException">The guest system is disabled.</exception> /// <exception cref="AccessException">The access token isn't a guest token.</exception> public void AddGuestSongToPlaylist(Song song, Guid accessToken) { if (song == null) { throw new ArgumentNullException(nameof(song)); } this.accessControl.VerifyVotingPreconditions(accessToken); PlaylistEntry entry = this.CurrentPlaylist.AddShadowVotedSong(song); this.accessControl.RegisterShadowVote(accessToken, entry); }
/// <summary> /// Registers a vote for the given access token and decrements the count of the remainig votes. /// </summary> /// <exception cref="InvalidOperationException"> /// There are no votes left for the given access token, or a the same entry is registered twice. /// </exception> public void RegisterVote(Guid accessToken, PlaylistEntry entry) { if (entry == null) { throw new ArgumentNullException("entry"); } this.VerifyVotingPreconditions(accessToken); AccessEndPoint endPoint = this.VerifyAccessToken(accessToken); if (!endPoint.RegisterEntry(entry) && !entry.IsShadowVoted) { throw new InvalidOperationException("Entry already registered"); } }
public bool RegisterEntry(PlaylistEntry entry) { if (this.registeredEntries.Add(entry)) { this.entryCount.OnNext(this.registeredEntries.Count); // We remove the entry if it has no votes no a shadow vote entry.WhenAnyValue(x => x.Votes, x => x.IsShadowVoted, (votes, isShadowVoted) => votes == 0 && !isShadowVoted) .FirstAsync(x => x) .Subscribe(x => { this.registeredEntries.Remove(entry); this.entryCount.OnNext(this.registeredEntries.Count); }); return(true); } return(false); }
/// <summary> /// Registers a vote for the given access token and decrements the count of the remainig votes. /// </summary> /// <exception cref="InvalidOperationException"> /// There are no votes left for the given access token, or a the same entry is registered twice. /// /// -- or-- /// /// The access token isn't a guest token. /// </exception> public void RegisterShadowVote(Guid accessToken, PlaylistEntry entry) { if (entry == null) { throw new ArgumentNullException("entry"); } if (!entry.IsShadowVoted) { throw new ArgumentException("Entry must be shadow voted"); } this.VerifyVotingPreconditions(accessToken); AccessEndPoint endPoint = this.VerifyAccessToken(accessToken); if (endPoint.AccessPermission.FirstAsync().Wait() != AccessPermission.Guest) { throw new InvalidOperationException("Access token has to be a guest token."); } endPoint.RegisterEntry(entry); }
public bool IsRegistered(PlaylistEntry entry) { return(this.registeredEntries.Contains(entry)); }