Esempio n. 1
0
        private static void EnqueueCoverRequest(AudioArtist target)
        {
            lock (_syncRoot)
            {
                if (_requestQueue.ContainsKey(target.Id))
                {
                    if (_requestQueue[target.Id].All(t => t != target))
                        _requestQueue[target.Id].Add(target);
                }
                else
                {
                    _requestQueue.Add(target.Id, new List<AudioArtist>() { target });
                }
            }

            if (!_isQueueWorking)
                Task.Run(() => StartQueueProcessing()); //вся обработка очереди производится в 1 потоке
        }
Esempio n. 2
0
        private async Task LoadArtists(CancellationToken token)
        {
            var audio = await DataService.GetUserTracks();

            if (audio.Items == null || token.IsCancellationRequested)
            {
                return;
            }

            var tracks = audio.Items;

            try
            {
                var artists = await DataService.GetArtistsFromTracks(tracks, token);
                if (artists != null)
                {
                    Artists = new ObservableCollection<AudioArtist>(artists);

                    SelectedArtist = Artists.FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
                LoggingService.Log(ex);
            }
        }
Esempio n. 3
0
        private async void SearchLocalArtists(CancellationToken token)
        {
            SearchResults = null;
            OnTaskStarted("results");

            SearchResults = null;

            try
            {
                var artists = await ServiceLocator.LocalMusicService.SearchArtists(_query);

                if (token.IsCancellationRequested)
                {
                    Debug.WriteLine("Local artists search cancelled");
                    return;
                }

                if (artists != null && artists.Count > 0)
                {
                    var results = new List<AudioArtist>();
                    foreach (var artist in artists)
                    {
                        var a = new AudioArtist(){Title = artist.Title};

                        var albums = await ServiceLocator.LocalMusicService.GetArtistAlbums(artist.Id);

                        if (token.IsCancellationRequested)
                        {
                            Debug.WriteLine("Local artists search cancelled");
                            return;
                        }

                        if (!albums.IsNullOrEmpty())
                        {
                            foreach (var album in albums)
                            {
                                var tracks = await ServiceLocator.LocalMusicService.GetAlbumTracks(album.Id);
                                if (token.IsCancellationRequested)
                                {
                                    Debug.WriteLine("Local artists search cancelled");
                                    return;
                                }

                                if (!tracks.IsNullOrEmpty())
                                    album.Tracks = tracks.Cast<Audio>().ToList();
                            }
                        }

                        a.Albums = albums;
                        results.Add(a);
                    }

                    SearchResults = new ObservableCollection<object>(results);
                }
                else
                {
                    OnTaskError("results", ErrorResources.LoadSearchErrorEmpty);
                }
            }
            catch (Exception ex)
            {
                LoggingService.Log(ex);

                OnTaskError("results", ErrorResources.LoadSearchErrorCommon);
            }

            OnTaskFinished("results");
        }
        private bool UpdateArtist(AudioArtist cachedArtist, AudioArtist updatedArtist)
        {
            bool changed = false;

            if (!cachedArtist.Title.Equals(updatedArtist.Title, StringComparison.OrdinalIgnoreCase))
            {
                cachedArtist.Title = updatedArtist.Title;
                changed = true;
            }

            return changed;
        }
Esempio n. 5
0
        public static Task<List<AudioArtist>> GetArtistsFromTracks(IEnumerable<Audio> tracks, CancellationToken token)
        {
            return Task.Run(() =>
            {
                var artists = new Dictionary<string, AudioArtist>();

                foreach (var track in tracks)
                {
                    if (token.IsCancellationRequested)
                        break;

                    //parse artist

                    var artistName = track.Artist;
                    var artistId = Md5Helper.Md5(artistName.ToLowerInvariant()); //artistid = md5(artistName)
                    if (!artists.ContainsKey(artistId))
                    {
                        var artist = new AudioArtist();
                        artist.Id = artistId;
                        artist.Title = artistName;
                        artists.Add(artistId, artist);
                    }

                    artists[artistId].Tracks.Add(track);
                }

                return artists.Values.OrderBy(a => a.Title).ToList();
            });
        }
Esempio n. 6
0
 /// <summary>
 /// Получить обложку
 /// </summary>
 /// <param name="target"></param>
 public static Task<ImageSource> GetCover(AudioArtist target)
 {
     return GetImage(target.Title);
 }
Esempio n. 7
0
 /// <summary>
 /// Ставит трек в очередь на получение обложки. Когда очередь подойдет, треку будет присвоена обложка.
 /// </summary>
 /// <param name="target"></param>
 public static void RequestCover(AudioArtist target)
 {
     //ставим трек в очередь и сразу возвращаем null
     EnqueueCoverRequest(target);
 }