void api_CatalogUpdateCompleted(object sender, EchoNestApiEventArgs e) { if (e.Error != null) { result.Text = App.HandleError(e.Error); } else { result.Text = "ticket " + e.GetResultData() as string; } }
void api_CatalogDeleteCompleted(object sender, EchoNestApiEventArgs e) { if (e.Error != null) { result.Text = App.HandleError(e.Error); } else { Catalog cat = (Catalog)e.GetResultData(); result.Text = "Deleted " + cat.Name + " with ID " + cat.Id; } }
void api_CatalogStatusCompleted(object sender, EchoNestApiEventArgs e) { if (e.Error != null) { result.Text = App.HandleError(e.Error); } else { Ticket t = e.GetResultData() as Ticket; result.Text = String.Format("ticket {0} at {1}% updated {2} items", t.Status, t.PercentComplete, t.ItemsUpdated); } }
void api_CatalogListCompleted(object sender, EchoNestApiEventArgs e) { if (e.Error != null) { result.Text = App.HandleError(e.Error); } else { result.Text = ((List<Catalog>)e.GetResultData()) .Select<Catalog, string>((cat) => cat.Name + " with ID " + cat.Id) .Aggregate<string>((sofar, current) => sofar + Environment.NewLine + current); } }
void api_SearchSongCompleted(object sender, EchoNestApiEventArgs e) { if (e.Error != null) { result.Text = App.HandleError(e.Error); } else { result.Text = ((List<Song>)e.GetResultData()) .Select<Song, string>((so) => so.Title + " by " + so.ArtistName) .Aggregate<string>((sofar, current) => sofar + Environment.NewLine + current); } }
void LoadCatalogIdNeedsToCreateCatalog_CatalogCreateCompleted( object sender, EchoNestApiEventArgs e) { if (e.Error == null) { Catalog cat = (Catalog)e.GetResultData(); // TODO If isolated storage fails here, then the next time they // run the app, we will create another catalog. We need to handle // this somehow - perhaps use the unique device ID (which is bad // practice apparently) as the catalog name to make sure there is // only one catalog created per device ever. logger.Debug("Creating remote CatalogID completed successfully"); SafeIsolatedStorageSettings settings = new SafeIsolatedStorageSettings(); settings[CatalogIdPropertyName] = cat.Id; settings.Save(); CatalogId = cat.Id; logger.Info("Completed LoadCatalogId"); } else { logger.Error("Creating remote CatalogID failed, retrying"); LoadCatalogIdNeedsToRunAgain(); } }
void DownloadAnalyzedSongs_CatalogReadCompleted( object sender, EchoNestApiEventArgs e) { if (e.Error == null) { Catalog cat = (Catalog)e.GetResultData(); if (cat.Items.Count > 0) { StoreDownloadedSongs(cat); } if (SongsToAnalyze.Count == 0) { // Yay, we are done AllDone = true; logger.Info("Completed DownloadAnalyzedSongs"); } else { if (cat.Items.Count == downloadTake) { // There are more songs to download, run again DownloadSkip++; } else { // There are no more songs in the remote catalog, but // we still have unanalyzed songs. Sigh... start // from the beginning DownloadSkip = 0; } logger.Debug("Download of analyzed songs completed, " + "will continue to run until all songs analyzed"); DownloadAnalyzedSongsNeedsToRunAgain(); } } else { logger.Error("Download of analyzed songs failed, retrying"); DownloadAnalyzedSongsNeedsToRunAgain(); } }
void DownloadAnalyzedSongsAlreadyInRemoteCatalog_CatalogReadCompleted( object sender, EchoNestApiEventArgs e) { if (e.Error == null) { Catalog cat = (Catalog)e.GetResultData(); if (cat.Items.Count > 0) { StoreDownloadedSongs(cat); } if (SongsToAnalyze.Count == 0) { // Yay, we are done AllDone = true; logger.Info("No songs left to analyze, all done"); logger.Info("Completed DownloadAnalyzedSongsAlreadyInRemoteCatalog"); } else { if (cat.Items.Count == downloadTake) { // We grabbed a full downloadTake number of items, so // there must be more items logger.Debug("Check if songs are already in remote catalog completed, " + "will run again since extra items are found"); DownloadSkip++; DownloadAnalyzedSongsAlreadyInRemoteCatalogNeedsToRunAgain(); } else { // Or it could be that we are done with the remote catalog, but we // still need to analyze some songs that weren't there, so we need // to go through with the rest of the process DownloadSkip = 0; SongsToAnalyzeBatchDownloadReady = true; logger.Info("Completed DownloadAnalyzedSongsAlreadyInRemoteCatalog"); } } } else { logger.Error("Check if songs are already in remote catalog failed, retrying"); DownloadAnalyzedSongsAlreadyInRemoteCatalogNeedsToRunAgain(); } }
static void Api_CatalogReadCompleted(object sender, EchoNestApiEventArgs e) { if (e.Error == null) { App thisApp = App.Current as App; BeatMachineDataContext context = new BeatMachineDataContext( BeatMachineDataContext.DBConnectionString); Catalog cat = (Catalog)e.GetResultData(); // TODO This check doesn't work well, it won't terminate // especially in the case where the catalog has more items that // the client doesn't know about if (!(cat.Items.Count == 0 && context.AnalyzedSongs.Count() == thisApp.Model.SongsToAnalyzeBatchSize)) { context.AnalyzedSongs.InsertAllOnSubmit( cat.Items.Select<Song, AnalyzedSong>( s => new AnalyzedSong { ItemId = s.Request.ItemId, ArtistName = s.ArtistName ?? s.Request.ArtistName, SongName = s.SongName ?? s.Request.SongName, AudioSummary = s.AudioSummary != null ? new AnalyzedSong.Summary { Tempo = s.AudioSummary.Tempo } : null } )); context.SubmitChanges(); downloadSkip = context.AnalyzedSongs.Count(); DownloadAnalyzedSongsNeedsToRunAgain(); } else { thisApp.Model.SongsToAnalyzeBatchDownloadReady = true; } } else { DownloadAnalyzedSongsNeedsToRunAgain(); } }
static void Api_CatalogCreateCompleted(object sender, EchoNestApiEventArgs e) { if (e.Error == null) { App thisApp = App.Current as App; Catalog cat = (Catalog)e.GetResultData(); // TODO If isolated storage fails here, then the next time they // run the app, we will create another catalog. We need to handle // this somehow - perhaps use the unique device ID (which is bad // practice apparently) as the catalog name to make sure there is // only one catalog created per device ever. lock (thisApp.Model.CatalogId) { // Store in isolated storage IsolatedStorageSettings.ApplicationSettings["CatalogId"] = cat.Id; IsolatedStorageSettings.ApplicationSettings.Save(); thisApp.Model.CatalogId = cat.Id; } } else { // Couldn't create successfully, try again later LoadCatalogIdNeedsToRunAgain(); } }