Beispiel #1
0
        public async void TagRegardingTask(List <Tags> tags, SocialMediaVM acc)
        {
            try
            {
                if (tags.Count() > 0)
                {
                    foreach (var item in tags)
                    {
                        if (item.IsBlocked != true)
                        {
                            int count = 0; int limit = 0;
                            int SearchTrackByTagTask = Int16.Parse(ConfigurationSettings.AppSettings["spotifySearchTrackByTagTask"].ToString());

                            while (limit < SearchTrackByTagTask)
                            {
                                var tracksResult = SearchTrack(acc.Id, item.TagName, acc.AccessDetails, count);
                                if (tracksResult.items.Count() > 0)
                                {
                                    foreach (var track in tracksResult.items)
                                    {
                                        if (_trackSuggestionRepo.Get().Where(x => x.SocialId == acc.Id && x.TrackId == track.id).FirstOrDefault() == null)
                                        {
                                            var suggestedTrack = new SuggestedTracks {
                                                Provider = SocialMediaProviders.Spotify.ToString(), SocialId = acc.Id, TrackId = track.id, TrackName = track.name, uri = track.uri, SourceName = "#" + item.TagName, SourceType = "Tag"
                                            };
                                            _trackSuggestionRepo.Add(suggestedTrack);
                                            _unitOfWork.Commit();
                                            limit++;
                                            await Task.Delay(100000);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #2
0
        public async void FollowingPlaylistTask(SocialMediaVM acc)
        {
            try
            {
                var playlists = GetUserPlaylists(acc.Id, acc.SMId, acc.AccessDetails);
                if (playlists.items.Count() > 0)
                {
                    foreach (var playlist in playlists.items)
                    {
                        if (playlist.owner.id != acc.SMId)
                        {
                            int limit = 0;
                            int count = 0;
                            int spotifyFollowingPlaylistTask = Int16.Parse(ConfigurationSettings.AppSettings["spotifyFollowingPlaylistTask"].ToString());

                            while (count < spotifyFollowingPlaylistTask)
                            {
                                var tracks = GetPlaylistTracks(playlist.id, playlist.owner.id, acc.Id, acc.AccessDetails, limit);
                                foreach (var item in tracks.items)
                                {
                                    if (CheckArtistFollowedByUser(acc.Id, item.added_by.id, acc.AccessDetails, item.added_by.type) == false)
                                    {
                                        if (Follow(acc.Id, item.added_by.id, acc.AccessDetails, item.added_by.type))
                                        {
                                            _userService.SaveActivity(new Activities {
                                                SMId = item.added_by.id, socialId = acc.Id, Activity = Activity.Follow.ToString(), ActivityDate = DateTime.UtcNow, Tag = '@' + playlist.name, Username = item.added_by.id, UserType = item.added_by.type
                                            });
                                            count++;
                                            await Task.Delay(100000);
                                        }
                                    }
                                    if (CheckArtistFollowedByUser(acc.Id, item.added_by.id, acc.AccessDetails, item.added_by.type) == false)
                                    {
                                        if (Follow(acc.Id, item.track.artists[0].id, acc.AccessDetails, item.track.artists[0].type))
                                        {
                                            _userService.SaveActivity(new Activities {
                                                SMId = item.track.artists[0].id, socialId = acc.Id, Activity = Activity.Follow.ToString(), ActivityDate = DateTime.UtcNow, Tag = '@' + playlist.name, Username = item.added_by.id, UserType = item.track.artists[0].type
                                            });
                                            count++;
                                            await Task.Delay(100000);
                                        }
                                    }
                                    if (_trackSuggestionRepo.Get().Where(x => x.SocialId == acc.Id && x.TrackId == item.track.id).FirstOrDefault() == null)
                                    {
                                        var suggestedTrack = new SuggestedTracks {
                                            Provider = SocialMediaProviders.Spotify.ToString(), SocialId = acc.Id, TrackId = item.track.id, TrackName = item.track.name, uri = item.track.uri, SourceName = "@" + playlist.name, SourceType = "Playlist"
                                        };
                                        _trackSuggestionRepo.Add(suggestedTrack);
                                        _unitOfWork.Commit();
                                        count++;
                                    }
                                }

                                limit++;
                            }//tracks for loop
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }