示例#1
0
        public void CheckAction(Account user, DateTime lastCheck)
        {
            var    api           = _spotifyService.GetSpotifyWebApi(_spotifyService.GetSpotifyToken(user));
            string currentUserId = (_spotifyWrapper.GetSpotifyProfile(_spotifyService.GetSpotifyToken(user)) as SpotifyProfileModel).Id;
            Paging <SimplePlaylist> playlists = _spotifyService.GetUserPlaylists(api, user);

            if (playlists == null)
            {
                return;
            }
            _newTracks = new List <PlaylistTrack>();
            for (int i = 0; i < playlists.Items.Count; i++)
            {
                Paging <PlaylistTrack> tracks = _spotifyService.GetPlaylistTracks(api, playlists.Items[i].Id, user);

                for (int j = 0; j < tracks.Items.Count; j++)
                {
                    if (tracks.Items[j].AddedAt >= lastCheck && tracks.Items[j].AddedBy.Id != currentUserId)
                    {
                        if (_lastTriggerDate == null)
                        {
                            _lastTriggerDate = tracks.Items[j].AddedAt;
                        }
                        else if (_lastTriggerDate < tracks.Items[j].AddedAt)
                        {
                            _lastTriggerDate = tracks.Items[j].AddedAt;
                        }
                        _newTracks.Add(tracks.Items[j]);
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Drop down list changed event to bind the playlist to the view
        /// </summary>
        /// <returns></returns>
        public async Task BindPlaylist(ChangeEventArgs e)
        {
            if (IsRandifying || IsPlaylistLoading)
            {
                return;
            }

            var playlistId = e.Value.ToString();

            try
            {
                IsPlaylistLoading    = true;
                Seconds              = 0;
                NumberOfLoadedTracks = 0;

                Stopwatch = new Stopwatch();
                Stopwatch.Start();
                PlaylistTracks.Clear();

                try
                {
                    var tracks = new List <PlaylistTrack>();

                    CurrentPlaylist = Playlists.FirstOrDefault(o => o.Id == playlistId);
                    var page = await SpotifyService.GetPlaylistTracks(AuthenticationService.User, AuthenticationService.AuthenticationToken, CurrentPlaylist);

                    do
                    {
                        foreach (var playlistTrack in page.Items)
                        {
                            tracks.Add(playlistTrack);
                        }

                        Seconds = Stopwatch.Elapsed.Seconds;
                        NumberOfLoadedTracks = tracks.Count();

                        StateHasChanged();

                        if (page.HasNextPage)
                        {
                            page = await SpotifyService.GetNextPage(page, AuthenticationService.AuthenticationToken);
                        }
                        else
                        {
                            page = null;
                        }
                    }while (page != null);

                    PlaylistTracks = tracks;
                }
                catch (Exception ex)
                {
                    PageException = ex;
                }

                NumberOfLoadedTracks = PlaylistTracks.Count();
                IsPlaylistLoading    = false;
                Stopwatch.Stop();

                StateHasChanged();
            }
            catch (Exception ex)
            {
                PageException = ex;
            }
        }