public void LoadFromZuneWebsite()
        {
            var warningMsg = new ErrorMessage(ErrorMode.Warning, "This process could take a very long time, are you sure?");

            ZuneMessageBox.Show(warningMsg, () =>
            {
                this.CanShowScanAllButton = false;
                int counter = 0;

                //we have to get the list from the CollectionView because of how its sorted
                var toScan = (from object album in _cvs.View select album as AlbumDetailsViewModel)
                             .ToList().Where(x => x.LinkStatus != LinkStatus.Unlinked);

                foreach (AlbumDetailsViewModel album in toScan)
                {
                    album.LinkStatus = LinkStatus.Unknown; // reset the linkstatus so we can scan all multiple times
                    album.Right      = null;

                    AlbumDetailsViewModel closedAlbum = album;
                    //TODO: don't like having to call back into the zune db just to get the albumMediaId
                    var url = String.Concat(Urls.Album, album.AlbumMediaId);
                    AlbumDetailsDownloader.DownloadAsync(url, dledAlbum =>
                    {
                        if (dledAlbum != null)
                        {
                            closedAlbum.LinkStatus = LinkStatus.Linked;
                            closedAlbum.Right      = new AlbumThumbDetails
                            {
                                Artist     = dledAlbum.Artist,
                                ArtworkUrl = dledAlbum.ArtworkUrl,
                                Title      = dledAlbum.Title
                            };
                        }
                        else
                        {
                            closedAlbum.LinkStatus = LinkStatus.Unlinked;
                        }

                        counter++;
                        Trace.WriteLine(counter);
                        ReportProgress(counter, toScan.Count());
                    });
                }
            });
        }
Esempio n. 2
0
        private void Save()
        {
            Mouse.OverrideCursor = Cursors.Wait;

            var uaeExceptions = new List <UnauthorizedAccessException>();

            bool canContinue = true;

            if (UpdateAlbumInfo)
            {
                const string message = "Track metadata will be updated with information from the Zune Marketplace. Do you want to continue?";
                var          result  = ZuneMessageBox.Show(new ErrorMessage(ErrorMode.Warning, message), System.Windows.MessageBoxButton.YesNo);

                if (result == System.Windows.MessageBoxResult.Cancel)
                {
                    canContinue = false;
                }
            }

            if (canContinue)
            {
                foreach (var row in Rows.OfType <DetailRow>())
                {
                    try
                    {
                        if (row.SelectedSong != null)
                        {
                            var container = (IZuneTagContainer)row.SongDetails.BackingData;
                            container.RemoveZuneAttribute("WM/WMContentID");
                            container.RemoveZuneAttribute("WM/WMCollectionID");
                            container.RemoveZuneAttribute("WM/WMCollectionGroupID");
                            container.RemoveZuneAttribute("ZuneCollectionID");
                            container.RemoveZuneAttribute("WM/UniqueFileIdentifier");

                            foreach (var attribute in container.ZuneAttributes)
                            {
                                Trace.WriteLine(attribute.Name + " " + attribute.Guid);
                            }

                            var webTrack = (WebTrack)row.SelectedSong.BackingData;
                            container.AddZuneAttribute(new ZuneAttribute(ZuneIds.Album, webTrack.AlbumMediaId));
                            container.AddZuneAttribute(new ZuneAttribute(ZuneIds.Artist, webTrack.ArtistMediaId));
                            container.AddZuneAttribute(new ZuneAttribute(ZuneIds.Track, webTrack.MediaId));

                            if (UpdateAlbumInfo)
                            {
                                container.AddMetaData(CreateMetaDataFromWebDetails((WebTrack)row.SelectedSong.BackingData));
                            }

                            container.WriteToFile();
                            //TODO: run a verifier over whats been written to ensure that the tags have actually been written to file
                        }
                    }
                    catch (UnauthorizedAccessException uae)
                    {
                        uaeExceptions.Add(uae);
                        //TODO: better error handling
                    }
                }

                if (uaeExceptions.Count > 0)
                {   //usually occurs when a file is readonly
                    Messenger.Default.Send(new ErrorMessage(ErrorMode.Error,
                                                            "One or more files could not be written to. Have you checked the files are not marked read-only?"));
                }
                else
                {
                    _locator.SwitchToView <SuccessView, SuccessViewModel>();
                }
            }

            Mouse.OverrideCursor = null;
        }