private void LoadAmpache() { if (!IsConnected) { try { IsLoading = true; var tmp = new Authenticate(AmpacheSource.AmpacheRootAddress.Get(), AmpacheSource.UserName.Get(), AmpacheSource.UserPassword.Get()); factory = new AmpacheSelectionFactory(tmp); pingTimer = new System.Threading.Timer((o) => tmp.Ping(), null, TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(5)); Artists = factory.GetInstanceSelectorFor <AmpacheArtist>().SelectAll().ToList(); Albums = factory.GetInstanceSelectorFor <AmpacheAlbum>().SelectAll().ToList(); Playlists = factory.GetInstanceSelectorFor <AmpachePlaylist>().SelectAll().ToList(); IsConnected = true; // hydrate albums var artists = Artists.ToDictionary(k => k.Id, v => v); foreach (var alb in Albums) { if (artists.ContainsKey(alb.ArtistId)) { alb.Hydrate(artists[alb.ArtistId]); } } } catch (Exception e) { Hyena.Log.ErrorFormat("{0}: message {1}\n{2}", e.GetType().Name, e.Message, e.StackTrace); IsConnected = false; } IsLoading = false; } }
private void LoadSongs() { var sel = factory.GetInstanceSelectorFor <AmpacheSong>(); IEnumerable <AmpacheSong> songs = Enumerable.Empty <AmpacheSong>(); if (SelectedPlaylist != null) { songs = sel.SelectBy(SelectedPlaylist); } else if (SelectedAlbum != null) { songs = sel.SelectBy(SelectedAlbum); } else if (SelectedArtist != null) { songs = sel.SelectBy(SelectedArtist); } var artists = Artists.ToDictionary(k => k.Id, v => v); var albums = Albums.ToDictionary(k => k.Id, v => v); foreach (AmpacheSong item in songs) { item.Hydrate(albums[item.AlbumId], artists[item.ArtistId]); } Songs = new HashSet <AmpacheSong>(songs); }