Пример #1
0
        public async Task SetAlbumArtworkAsync(ObservableCollection <AlbumViewModel> albumViewmodels, int delayMilliSeconds)
        {
            await Task.Delay(delayMilliSeconds);

            await Task.Run(() =>
            {
                try
                {
                    foreach (AlbumViewModel albvm in albumViewmodels)
                    {
                        try
                        {
                            albvm.ArtworkPath = ArtworkUtils.GetArtworkPath(albvm.Album.ArtworkID);
                        }
                        catch (Exception ex)
                        {
                            LogClient.Instance.Logger.Error("Error while setting artwork for album with Album artist = '{0}' and Title='{1}'. Exception: {2}", albvm.AlbumArtist, albvm.AlbumTitle, ex.Message);
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogClient.Instance.Logger.Error("Error while setting album artwork. Exception: {0}", ex.Message);
                }
            });
        }
Пример #2
0
        private async Task <long> DeleteUnusedArtworkFromDatabaseAsync()
        {
            long numberDeleted = 0;

            await Task.Run(() =>
            {
                using (SQLiteConnection conn = this.factory.GetConnection())
                {
                    conn.BeginTransaction();

                    foreach (Album alb in conn.Table <Album>().Where((a) => (a.ArtworkID != null && a.ArtworkID != string.Empty)))
                    {
                        if (!System.IO.File.Exists(ArtworkUtils.GetArtworkPath(alb.ArtworkID)))
                        {
                            alb.ArtworkID = string.Empty;
                            conn.Update(alb);
                            numberDeleted += 1;
                        }

                        // Report progress if at least 1 cover is deleted
                        if (numberDeleted > 0)
                        {
                            this.eventArgs.IndexingAction  = IndexingAction.UpdateArtwork;
                            this.eventArgs.ProgressPercent = 0;
                            this.IndexingStatusChanged(this.eventArgs);
                        }
                    }

                    conn.Commit();
                }
            });

            return(numberDeleted);
        }
Пример #3
0
        public async Task SetTrackArtworkAsync(ObservableCollection <TrackInfoViewModel> trackInfoViewModels, int delayMilliSeconds)
        {
            await Task.Delay(delayMilliSeconds);

            await Task.Run(() =>
            {
                try
                {
                    foreach (TrackInfoViewModel tivm in trackInfoViewModels)
                    {
                        try
                        {
                            tivm.ArtworkPath = ArtworkUtils.GetArtworkPath(tivm.TrackInfo.AlbumArtworkID);
                        }
                        catch (Exception ex)
                        {
                            LogClient.Instance.Logger.Error("Error while setting artwork for Track {0}. Exception: {1}", tivm.TrackInfo.Path, ex.Message);
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogClient.Instance.Logger.Error("Error while setting track artwork. Exception: {0}", ex.Message);
                }
            });
        }
Пример #4
0
        public async Task ShowNotificationAsync()
        {
            if (this.notification != null)
            {
                this.notification.DoubleClicked -= ShowMainWindow;
            }

            if (!XmlSettingsClient.Instance.Get <bool>("Behaviour", "ShowNotification"))
            {
                return;
            }

            try
            {
                if (this.notification != null)
                {
                    this.notification.Disable();
                }
            }
            catch (Exception ex)
            {
                LogClient.Instance.Logger.Error("Error while trying to disable the notification. Exception: {0}", ex.Message);
            }

            string artworkPath = string.Empty;

            TrackInfoViewModel playingTrackinfoVm = null; // Create a dummy track

            await Task.Run(() =>
            {
                try
                {
                    if (this.playbackService.PlayingTrack != null)
                    {
                        artworkPath                  = ArtworkUtils.GetArtworkPath(this.playbackService.PlayingTrack.AlbumArtworkID);
                        playingTrackinfoVm           = this.container.Resolve <TrackInfoViewModel>();
                        playingTrackinfoVm.TrackInfo = this.playbackService.PlayingTrack;
                    }
                }
                catch (Exception ex)
                {
                    LogClient.Instance.Logger.Error("Error while trying to show the notification. Exception: {0}", ex.Message);
                }
            });

            Application.Current.Dispatcher.Invoke(() =>
            {
                this.notification = new NotificationWindow(playingTrackinfoVm,
                                                           artworkPath,
                                                           (NotificationPosition)XmlSettingsClient.Instance.Get <int>("Behaviour", "NotificationPosition"),
                                                           XmlSettingsClient.Instance.Get <bool>("Behaviour", "ShowNotificationControls"),
                                                           XmlSettingsClient.Instance.Get <int>("Behaviour", "NotificationAutoCloseSeconds"));

                this.notification.DoubleClicked += ShowMainWindow;

                this.notification.Show();
            });
        }
Пример #5
0
        public async Task RefreshArtworkAsync(ObservableCollection <AlbumViewModel> albumViewModels, ObservableCollection <TrackInfoViewModel> trackInfoViewModels)
        {
            List <Album> dbAlbums = await this.albumRepository.GetAlbumsAsync();

            if (albumViewModels != null && albumViewModels.Count > 0)
            {
                await Task.Run(() =>
                {
                    foreach (AlbumViewModel albvm in albumViewModels)
                    {
                        try
                        {
                            // Get an up to date version of this album from the database

                            Album dbAlbum = dbAlbums.Where((a) => a.AlbumID.Equals(albvm.Album.AlbumID)).Select((a) => a).FirstOrDefault();

                            if (dbAlbum != null)
                            {
                                albvm.Album.ArtworkID = dbAlbum.ArtworkID;
                                albvm.ArtworkPath     = ArtworkUtils.GetArtworkPath(dbAlbum.ArtworkID);
                            }
                        }
                        catch (Exception ex)
                        {
                            LogClient.Instance.Logger.Error("Error while refreshing artwork for Album {0}/{1}. Exception: {2}", albvm.AlbumTitle, albvm.AlbumArtist, ex.Message);
                        }
                    }
                });
            }

            if (trackInfoViewModels != null && trackInfoViewModels.Count > 0)
            {
                await Task.Run(() =>
                {
                    foreach (TrackInfoViewModel tivm in trackInfoViewModels)
                    {
                        try
                        {
                            // Get an up to date version of this album from the database
                            Album dbAlbum = dbAlbums.Where((a) => a.AlbumID.Equals(tivm.TrackInfo.AlbumID)).Select((a) => a).FirstOrDefault();

                            if (dbAlbum != null)
                            {
                                tivm.TrackInfo.AlbumArtworkID = dbAlbum.ArtworkID;
                                tivm.ArtworkPath = ArtworkUtils.GetArtworkPath(dbAlbum.ArtworkID);
                            }
                        }
                        catch (Exception ex)
                        {
                            LogClient.Instance.Logger.Error("Error while refreshing artwork for TrackInfo with path {0}. Exception: {1}", tivm.TrackInfo.Path, ex.Message);
                        }
                    }
                });
            }
        }
Пример #6
0
        protected async virtual void ShowCoverArtAsync(TrackInfo trackInfo)
        {
            if (trackInfo == null)
            {
                this.CoverArtViewModel = new CoverArtViewModel {
                    CoverArt = null
                };
                return;
            }

            string artworkPath = string.Empty;

            await Task.Run(() =>
            {
                artworkPath = ArtworkUtils.GetArtworkPath(trackInfo.AlbumArtworkID);
            });

            if (string.IsNullOrEmpty(artworkPath))
            {
                this.CoverArtViewModel = new CoverArtViewModel {
                    CoverArt = null
                };
                return;
            }

            try
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    var proxyImage     = new Image();
                    proxyImage.Stretch = Stretch.Fill;

                    BitmapImage bmpImage = new BitmapImage();
                    bmpImage.BeginInit();
                    bmpImage.UriSource = new Uri(artworkPath);
                    bmpImage.EndInit();

                    proxyImage.Source      = bmpImage;
                    this.CoverArtViewModel = new CoverArtViewModel {
                        CoverArt = proxyImage
                    };
                });
            }
            catch (Exception ex)
            {
                LogClient.Instance.Logger.Error("Could not show cover art for Track {0}. Exception: {1}", trackInfo.Path, ex.Message);
                this.CoverArtViewModel = new CoverArtViewModel {
                    CoverArt = null
                };
            }
        }
Пример #7
0
        private async Task GetAlbumArtworkAsync()
        {
            await Task.Run(() => {
                string artworkPath = ArtworkUtils.GetArtworkPath(this.Album.ArtworkID);

                try
                {
                    if (!string.IsNullOrEmpty(artworkPath))
                    {
                        this.UpdateArtwork(artworkPath, ImageOperations.Image2ByteArray(artworkPath));
                    }
                    else
                    {
                        this.UpdateArtwork(string.Empty, null);
                    }
                }
                catch (Exception ex)
                {
                    LogClient.Instance.Logger.Error("An error occurred while getting the artwork for album with title='{0}' and artist='{1}'. Exception: {2}", this.Album.AlbumTitle, this.Album.AlbumArtist, ex.Message);
                }
            });
        }
Пример #8
0
        private void UpdateAlbumViewModel(int number, List <Album> albums, ref AlbumViewModel albumViewModel)
        {
            if (albums.Count < number)
            {
                albumViewModel = null;
            }
            else
            {
                Album alb = albums[number - 1];
                if (albumViewModel == null || !albumViewModel.Album.Equals(alb))
                {
                    albumViewModel = new AlbumViewModel
                    {
                        Album       = alb,
                        ArtworkPath = ArtworkUtils.GetArtworkPath(alb.ArtworkID)
                    };
                }
            }

            OnPropertyChanged("AlbumViewModel" + number.ToString());

            System.Threading.Thread.Sleep(Constants.CloudLoadDelay);
        }
        protected async virtual void ShowCoverArtAsync(TrackInfo trackInfo)
        {
            this.previousAlbum = this.album;

            // No track selected: clear cover art.
            if (trackInfo == null)
            {
                this.CoverArtViewModel = new CoverArtViewModel {
                    CoverArt = null
                };
                this.album = null;
                return;
            }

            this.album = new Album
            {
                AlbumArtist = this.playbackService.PlayingTrack.AlbumArtist,
                AlbumTitle  = this.playbackService.PlayingTrack.AlbumTitle,
                Year        = this.playbackService.PlayingTrack.AlbumYear,
                ArtworkID   = this.playbackService.PlayingTrack.AlbumArtworkID,
            };

            // The album didn't change: leave the previous covert art.
            if (this.album.Equals(this.previousAlbum))
            {
                return;
            }

            // The album changed: we need to show new cover art.
            string artworkPath = string.Empty;

            await Task.Run(() =>
            {
                artworkPath = ArtworkUtils.GetArtworkPath(trackInfo.AlbumArtworkID);
            });

            if (string.IsNullOrEmpty(artworkPath))
            {
                this.CoverArtViewModel = new CoverArtViewModel {
                    CoverArt = null
                };
                return;
            }

            try
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    var proxyImage     = new Image();
                    proxyImage.Stretch = Stretch.Fill;

                    BitmapImage bmpImage = new BitmapImage();
                    bmpImage.BeginInit();
                    bmpImage.UriSource = new Uri(artworkPath);
                    bmpImage.EndInit();

                    proxyImage.Source      = bmpImage;
                    this.CoverArtViewModel = new CoverArtViewModel {
                        CoverArt = proxyImage
                    };
                });
            }
            catch (Exception ex)
            {
                LogClient.Instance.Logger.Error("Could not show cover art for Track {0}. Exception: {1}", trackInfo.Path, ex.Message);
                this.CoverArtViewModel = new CoverArtViewModel {
                    CoverArt = null
                };
            }
        }