protected override void IterateCore(HyenaDataReader reader) { var track = DatabaseTrackInfo.Provider.FetchSingle (reader.Get<long> (0)); bool cancelled = false; if (track != null && track.Uri != null && track.Uri.IsLocalPath) { analysis.TrackId = track.TrackId; try { if (Banshee.IO.File.Exists (track.Uri)) { Log.DebugFormat ("Mirage - Processing {0}-{1}-{2}", track.TrackId, track.ArtistName, track.TrackTitle); Status = String.Format("{0} - {1}", track.ArtistName, track.TrackTitle); analysis.ScmsData = Analyzer.Analyze (track.Uri.LocalPath).ToBytes (); analysis.Status = AnalysisStatus.Succeeded; } else { analysis.Status = AnalysisStatus.FileMissing; } } catch (AudioDecoderCanceledException) { cancelled = true; } catch (AudioDecoderErrorException) { analysis.Status = AnalysisStatus.Failed; } catch (Exception e) { analysis.Status = AnalysisStatus.UnknownFailure; Log.Exception ("Unexpected exception doing Mirage analysis", e); } finally { if (!cancelled) { TrackAnalysis.Provider.Delete (analysis.TrackId); // Manually do this query instead of using Save since we need to be able to specify // the primarykey value TrackAnalysis.Provider.Connection.Execute ( "INSERT INTO MirageTrackAnalysis (TrackID, ScmsData, Status) VALUES (?, ?, ?)", analysis.TrackId, analysis.ScmsData, (int)analysis.Status ); } } } }
protected override void IterateCore(HyenaDataReader reader) { SafeUri uri = new SafeUri(reader.Get <string> (0)); current_track_id = reader.Get <int> (1); // Wait for the result to be ready result_ready_event.Reset(); detector.ProcessFile(uri); result_ready_event.WaitOne(); if (IsCancelRequested) { return; } if (result_bpm > 0) { Log.DebugFormat("Saving BPM of {0} for {1}", result_bpm, result_uri); ServiceManager.DbConnection.Execute(update_query, result_bpm, DateTime.Now, current_track_id); } else { ServiceManager.DbConnection.Execute(update_query, -1, DateTime.Now, current_track_id); Log.DebugFormat("Unable to detect BPM for {0}", result_uri); } }
public static void ReloadWindow() { ClearData(); HyenaDataReader reader = new HyenaDataReader(ServiceManager.DbConnection.Query(@"SELECT CT.TrackID, CT.Title, CA.ArtistName, CA.Title, CT.URI, CT.TrackNumber FROM CoreTracks CT,CoreAlbums CA ON Ct.AlbumID = CA.AlbumID AND CT.TrackID IN ( SELECT CT1.TrackID from CoreTracks CT1,CoreTracks CT2 WHERE CT1.PrimarySourceID = ? AND CT1.PrimarySourceID = CT2.PrimarySourceID AND CT1.TrackID <> CT2.TrackID AND CT1.TitleLowered = CT2.TitleLowered AND CT1.AlbumID = CT2.AlbumID AND CT1.ArtistID = CT2.ArtistID AND CT1.Disc = CT2.Disc AND CT1.Duration = CT2.Duration ) ORDER BY CT.Title,CT.ArtistID,CT.TrackNumber", ServiceManager.SourceManager.MusicLibrary.DbId)); while (reader.Read()) { int ID = reader.Get <int> (0); String Title = reader.Get <String> (1); String Artist = reader.Get <String> (2); String Album = reader.Get <String> (3); String URI = reader.Get <String> (4); String TrackNumber = reader.Get <String> (5); AddData(ID, TrackNumber, Title, Artist, Album, URI); } }
public static IEnumerable <SmartPlaylistSource> LoadAll(PrimarySource parent) { ClearTemporary(); using (HyenaDataReader reader = new HyenaDataReader(ServiceManager.DbConnection.Query( @"SELECT SmartPlaylistID, Name, Condition, OrderBy, LimitNumber, LimitCriterion, PrimarySourceID, CachedCount, IsTemporary, IsHiddenWhenEmpty FROM CoreSmartPlaylists WHERE PrimarySourceID = ?", parent.DbId))) { while (reader.Read()) { SmartPlaylistSource playlist = null; try { playlist = new SmartPlaylistSource( reader.Get <int> (0), reader.Get <string> (1), reader.Get <string> (2), reader.Get <string> (3), reader.Get <string> (4), reader.Get <string> (5), parent, reader.Get <int> (7), reader.Get <bool> (8), reader.Get <bool> (9) ); } catch (Exception e) { Log.Warning("Ignoring Smart Playlist", String.Format("Caught error: {0}", e), false); } if (playlist != null) { yield return(playlist); } } } }
protected bool Iterate() { if (IsCancelRequested) { return(false); } YieldToScheduler(); int total = current_count + ServiceManager.DbConnection.Query <int> (count_command); try { using (HyenaDataReader reader = new HyenaDataReader(ServiceManager.DbConnection.Query(select_command))) { if (reader.Read()) { IterateCore(reader); } else { return(false); } } } catch (System.Threading.ThreadAbortException) { Cleanup(); throw; } catch (Exception e) { Log.Exception(e); } finally { Progress = (double)current_count / (double)total; current_count++; } return(true); }
public override void GetChunks(int chunk_size) { // mark as critical region to prevent consecutive calls from mucking things up lock (payload_lock) { long timestamp; lock (timestamp_lock) { if (UseBuffer) { buffer = new Dictionary <int, IDictionary <string, object> []> (); } timestamp = DateTime.Now.Ticks; CurrentTimestamp = timestamp; } int total = ServiceManager.DbConnection.Query <int> ( "SELECT COUNT(*) FROM CorePlaylistEntries WHERE PlaylistID = ?", Id ); if (total == 0) { IDictionary <string, object> [] empty = {}; // d-bus no like nulls OnChunkReady(ObjectPath, empty, timestamp, 1, 0); return; } chunk_size = chunk_size < 1 ? 100 : chunk_size; // default chunk_size HyenaDataReader reader = new HyenaDataReader(ServiceManager.DbConnection.Query( "SELECT TrackID FROM CorePlaylistEntries WHERE PlaylistID = ?", Id) ); // deliver data asynchronously via signal in chunks of chunk_size // this should make things look like they are happening quickly over our tube int sequence_num = 1; for (int i = 0; i < total; i += chunk_size) { int dict_size = (total - i) < chunk_size ? (total - i) : chunk_size; IDictionary <string, object> [] dict = new Dictionary <string, object> [dict_size]; for (int j = 0; j < dict.Length; j++) { dict[j] = new Dictionary <string, object> (); if (reader.Read()) { dict[j].Add("TrackID", reader.Get <int> (0)); } } if (UseBuffer) { buffer.Add(sequence_num, dict); } OnChunkReady(ObjectPath, dict, timestamp, sequence_num++, total); } } }
private void RemoveTrack(string track) { string uri = new SafeUri(track).AbsoluteUri; string hash_sql = String.Format( @"SELECT TrackID, MetadataHash FROM CoreTracks WHERE {0} = ? LIMIT 1", BansheeQuery.UriField.Column ); long track_id = 0; string hash = null; using (var reader = new HyenaDataReader(ServiceManager.DbConnection.Query(hash_sql, uri))) { if (reader.Read()) { track_id = reader.Get <long> (0); hash = reader.Get <string> (1); } } if (hash != null) { lock (queue) { var item = queue.FirstOrDefault( i => i.ChangeType == WatcherChangeTypes.Created && GetMetadataHash(i) == hash); if (item != null) { item.ChangeType = WatcherChangeTypes.Renamed; item.OldFullPath = track; return; } } } string delete_sql = @" INSERT INTO CoreRemovedTracks (DateRemovedStamp, TrackID, Uri) SELECT ?, TrackID, " + BansheeQuery.UriField.Column + @" FROM CoreTracks WHERE TrackID IN ({0}) ; DELETE FROM CoreTracks WHERE TrackID IN ({0})"; // If track_id is 0, it's a directory. HyenaSqliteCommand delete_command; if (track_id > 0) { delete_command = new HyenaSqliteCommand(String.Format(delete_sql, "?"), DateTime.Now, track_id, track_id); } else { string pattern = StringUtil.EscapeLike(uri) + "/_%"; string select_sql = String.Format(@"SELECT TrackID FROM CoreTracks WHERE {0} LIKE ? ESCAPE '\'", BansheeQuery.UriField.Column); delete_command = new HyenaSqliteCommand(String.Format(delete_sql, select_sql), DateTime.Now, pattern, pattern); } ServiceManager.DbConnection.Execute(delete_command); }
protected override void IterateCore(HyenaDataReader reader) { var track = new CoverartTrackInfo { AlbumTitle = reader.Get <string> (1), ArtistName = reader.Get <string> (2), PrimarySource = ServiceManager.SourceManager.MusicLibrary, Uri = new SafeUri(reader.Get <string> (3)), DbId = reader.Get <int> (4), AlbumId = reader.Get <int> (0) }; Status = String.Format(AddinManager.CurrentLocalizer.GetString("{0} - {1}"), track.ArtistName, track.AlbumTitle); WriteArt(track); }
protected override void IterateCore(HyenaDataReader reader) { DatabaseTrackInfo track = DatabaseTrackInfo.Provider.Load(reader.Reader); var write_delay = track.DateUpdated.AddSeconds(2) - DateTime.Now; if (write_delay.TotalMilliseconds > 0) { System.Threading.Thread.Sleep(write_delay); return; } bool wrote = false; bool renamed = false; try { if (WriteMetadataEnabled || WriteRatingsAndPlayCountsEnabled) { Hyena.Log.DebugFormat("Saving metadata for {0}", track); wrote = StreamTagger.SaveToFile(track, WriteMetadataEnabled, WriteRatingsAndPlayCountsEnabled); } // Rename tracks only from the Music Library if (RenameEnabled && track.PrimarySource.Equals(musicLibrarySource)) { Hyena.Log.DebugFormat("Updating file name for {0}", track); renamed = RenameFile(track); if (renamed && !wrote) { track.LastSyncedStamp = DateTime.Now; } } } catch (Exception) { Hyena.Log.ErrorFormat("Error writing to or renaming {0}", track); } finally { if (wrote || renamed) { // Save the resulting changes to FileSize, LastSyncedStamp, possibly to Uri, etc // Clear track model caches if URI changed track.Save(renamed); } else { if (update_synced_at == null) { update_synced_at = new HyenaSqliteCommand( "UPDATE CoreTracks SET LastSyncedStamp = ? WHERE TrackID = ?"); } ServiceManager.DbConnection.Execute(update_synced_at, DateTime.Now, track.TrackId); } } }
public virtual void UpdateUnfilteredAggregates() { HyenaSqliteCommand count_command = new HyenaSqliteCommand(String.Format( "SELECT COUNT(*), SUM(CoreTracks.FileSize) {0}", UnfilteredQuery )); using (HyenaDataReader reader = new HyenaDataReader(connection.Query(count_command))) { count = reader.Get <long> (0); filesize = reader.Get <long> (1); } }
public virtual void UpdateUnfilteredAggregates() { HyenaSqliteCommand count_command = new HyenaSqliteCommand(String.Format( "SELECT COUNT(*), SUM({0}), SUM({1}) {2}", BansheeQuery.FileSizeField.Column, BansheeQuery.DurationField.Column, UnfilteredQuery )); using (HyenaDataReader reader = new HyenaDataReader(connection.Query(count_command))) { count = reader.Get <long> (0); filesize = reader.Get <long> (1); duration = reader.Get <TimeSpan> (2); } }
public Playlist(uint id) { HyenaDataReader reader = new HyenaDataReader(ServiceManager.DbConnection.Query ("SELECT PlaylistID, Name from CorePlaylists WHERE PlaylistID = ?", id)); if (!reader.Read()) { throw new Exception("No such playlist!"); } ID = reader.Get <uint> (0); Name = reader.Get <string> (1); }
protected override void IterateCore(HyenaDataReader reader) { var track = new LyricsTrackInfo() { ArtistName = reader.Get<string> (1), TrackTitle = reader.Get<string> (2), PrimarySource = ServiceManager.SourceManager.MusicLibrary, Uri = new SafeUri (reader.Get<string> (3)), DbId = reader.Get<int> (0), }; Status = String.Format (AddinManager.CurrentLocalizer.GetString ("{0} - {1}"), track.ArtistName, track.TrackTitle); DownloadLyrics (track); }
protected override void IterateCore(HyenaDataReader reader) { var track = new LyricsTrackInfo() { ArtistName = reader.Get <string> (1), TrackTitle = reader.Get <string> (2), PrimarySource = ServiceManager.SourceManager.MusicLibrary, Uri = new SafeUri(reader.Get <string> (3)), DbId = reader.Get <int> (0), }; Status = String.Format(AddinManager.CurrentLocalizer.GetString("{0} - {1}"), track.ArtistName, track.TrackTitle); DownloadLyrics(track); }
protected override void IterateCore(HyenaDataReader reader) { DatabaseTrackInfo track = new DatabaseTrackInfo(); track.AlbumTitle = reader.Get <string> (1); track.ArtistName = reader.Get <string> (2); track.PrimarySource = ServiceManager.SourceManager.MusicLibrary; track.Uri = new SafeUri(reader.Get <string> (3)); track.AlbumId = reader.Get <int> (0); //Console.WriteLine ("have album {0}/{1} for track uri {2}", track.AlbumId, track.AlbumTitle, track.Uri); Status = String.Format(Catalog.GetString("{0} - {1}"), track.ArtistName, track.AlbumTitle); FetchForTrack(track); }
protected override void IterateCore(HyenaDataReader reader) { var track = new CoverartTrackInfo() { AlbumTitle = reader.Get <string> (1), ArtistName = reader.Get <string> (2), PrimarySource = ServiceManager.SourceManager.MusicLibrary, Uri = new SafeUri(reader.Get <string> (3)), DbId = reader.Get <long> (4), AlbumId = reader.Get <long> (0) }; Status = String.Format(Catalog.GetString("{0} - {1}"), track.ArtistName, track.AlbumTitle); FetchForTrack(track); }
public static IEnumerable <PlaylistSource> LoadAll(PrimarySource parent) { ClearTemporary(); using (HyenaDataReader reader = new HyenaDataReader(ServiceManager.DbConnection.Query( @"SELECT PlaylistID, Name, SortColumn, SortType, PrimarySourceID, CachedCount, IsTemporary FROM CorePlaylists WHERE Special = 0 AND PrimarySourceID = ?", parent.DbId))) { while (reader.Read()) { yield return(new PlaylistSource( reader.Get <string> (1), reader.Get <int> (0), reader.Get <int> (2), reader.Get <int> (3), parent, reader.Get <int> (5), reader.Get <bool> (6) )); } } }
public static List <Playlist> GetAllPlaylists() { // get all the Uri from database HyenaDataReader reader = new HyenaDataReader(ServiceManager.DbConnection.Query ("SELECT PlaylistID, Name from CorePlaylists")); var playlists = new List <Playlist> (); while (reader.Read()) { playlists.Add(new Playlist { ID = reader.Get <uint> (0), Name = reader.Get <string> (1) }); } return(playlists); }
protected override void IterateCore (HyenaDataReader reader) { DatabaseTrackInfo track = DatabaseTrackInfo.Provider.Load (reader.Reader); var write_delay = track.DateUpdated.AddSeconds (2) - DateTime.Now; if (write_delay.TotalMilliseconds > 0) { System.Threading.Thread.Sleep (write_delay); return; } bool wrote = false; bool renamed = false; try { if (WriteMetadataEnabled || WriteRatingsAndPlayCountsEnabled) { Hyena.Log.DebugFormat ("Saving metadata for {0}", track); wrote = StreamTagger.SaveToFile (track, WriteMetadataEnabled, WriteRatingsAndPlayCountsEnabled); } // Rename tracks only from the Music Library if (RenameEnabled && track.PrimarySource.Equals (musicLibrarySource)) { Hyena.Log.DebugFormat ("Updating file name for {0}", track); renamed = RenameFile (track); if (renamed && !wrote) { track.LastSyncedStamp = DateTime.Now; } } } catch (Exception) { Hyena.Log.ErrorFormat ("Error writing to or renaming {0}", track); } finally { if (wrote || renamed) { // Save the resulting changes to FileSize, LastSyncedStamp, possibly to Uri, etc // Clear track model caches if URI changed track.Save (renamed); } else { if (update_synced_at == null) { update_synced_at = new HyenaSqliteCommand ( "UPDATE CoreTracks SET LastSyncedStamp = ? WHERE TrackID = ?"); } ServiceManager.DbConnection.Execute (update_synced_at, DateTime.Now, track.TrackId); } } }
protected override void IterateCore(HyenaDataReader reader) { DatabaseTrackInfo track = DatabaseTrackInfo.Provider.Load(reader.Reader); bool wrote = false; bool renamed = false; try { if (WriteEnabled) { Hyena.Log.DebugFormat("Saving metadata for {0}", track); wrote = StreamTagger.SaveToFile(track); } if (RenameEnabled) { Hyena.Log.DebugFormat("Updating file name for {0}", track); renamed = RenameFile(track); if (renamed && !wrote) { track.LastSyncedStamp = DateTime.Now; } } } catch (Exception) { Hyena.Log.ErrorFormat("Error writing to or renaming {0}", track); } finally { if (wrote || renamed) { // Save the resulting changes to FileSize, LastSyncedStamp, possibly to Uri, etc // Clear track model caches if URI changed track.Save(renamed); } else { if (update_synced_at == null) { update_synced_at = new HyenaSqliteCommand( "UPDATE CoreTracks SET LastSyncedStamp = ? WHERE TrackID = ?"); } ServiceManager.DbConnection.Execute(update_synced_at, DateTime.Now, track.TrackId); } } }
// returns filenames of all included files in playlist public static List <Track> GetAllTracks(uint playlist_id) { HyenaDataReader reader = new HyenaDataReader(ServiceManager.DbConnection.Query( "SELECT t.TrackID, t.Uri from CorePlaylistEntries e JOIN CoreTracks t ON(e.TrackID = t.TrackID) " + "WHERE e.PlaylistID = ?", playlist_id)); // package the Uris into a List for convenience List <Track> tracks = new List <Track> (); while (reader.Read()) { tracks.Add(new Track() { ID = reader.Get <uint> (0), Uri = new SafeUri(reader.Get <string> (1)) }); } return(tracks); }
protected bool Iterate() { if (IsCancelRequested) { return(false); } YieldToScheduler(); int total = current_count + ServiceManager.DbConnection.Query <int> (count_command); try { using (HyenaDataReader reader = new HyenaDataReader(ServiceManager.DbConnection.Query(select_command))) { if (reader.Read()) { IterateCore(reader); failure_count = 0; } else { return(false); } } } catch (System.Threading.ThreadAbortException) { Cleanup(); throw; } catch (Exception e) { Log.Error(e); failure_count++; if (failure_count > MAX_FAILURE_COUNT) { Log.WarningFormat("Too many consecutive errors for job '{0}', aborting", this.Title); return(false); } } finally { Progress = (double)current_count / (double)total; current_count++; } return(true); }
protected override void IterateCore(HyenaDataReader reader) { var track = DatabaseTrackInfo.Provider.FetchSingle(reader.Get <long> (0)); bool cancelled = false; if (track != null && track.Uri != null && track.Uri.IsLocalPath) { analysis.TrackId = track.TrackId; try { if (Banshee.IO.File.Exists(track.Uri)) { Log.DebugFormat("Mirage - Processing {0}-{1}-{2}", track.TrackId, track.ArtistName, track.TrackTitle); Status = String.Format("{0} - {1}", track.ArtistName, track.TrackTitle); analysis.ScmsData = Analyzer.Analyze(track.Uri.LocalPath).ToBytes(); analysis.Status = AnalysisStatus.Succeeded; } else { analysis.Status = AnalysisStatus.FileMissing; } } catch (AudioDecoderCanceledException) { cancelled = true; } catch (AudioDecoderErrorException) { analysis.Status = AnalysisStatus.Failed; } catch (Exception e) { analysis.Status = AnalysisStatus.UnknownFailure; Log.Exception("Unexpected exception doing Mirage analysis", e); } finally { if (!cancelled) { TrackAnalysis.Provider.Delete(analysis.TrackId); // Manually do this query instead of using Save since we need to be able to specify // the primarykey value TrackAnalysis.Provider.Connection.Execute( "INSERT INTO MirageTrackAnalysis (TrackID, ScmsData, Status) VALUES (?, ?, ?)", analysis.TrackId, analysis.ScmsData, (int)analysis.Status ); } } } }
private bool Migrate_27() { // One time fixup to MetadataHash now that our unknown metadata is handled properly string sql_select = @" SELECT t.TrackID, al.Title, ar.Name, t.Duration, t.Genre, t.Title, t.TrackNumber, t.Year FROM CoreTracks AS t JOIN CoreAlbums AS al ON al.AlbumID=t.AlbumID JOIN CoreArtists AS ar ON ar.ArtistID=t.ArtistID WHERE t.Title IS NULL OR ar.Name IS NULL OR al.Title IS NULL "; HyenaSqliteCommand sql_update = new HyenaSqliteCommand(@" UPDATE CoreTracks SET MetadataHash = ? WHERE TrackID = ? "); StringBuilder sb = new StringBuilder(); using (var reader = new HyenaDataReader(connection.Query(sql_select))) { while (reader.Read()) { sb.Length = 0; sb.Append(reader.Get <string> (1)); sb.Append(reader.Get <string> (2)); sb.Append((int)reader.Get <TimeSpan> (3).TotalSeconds); sb.Append(reader.Get <string> (4)); sb.Append(reader.Get <string> (5)); sb.Append(reader.Get <int> (6)); sb.Append(reader.Get <int> (7)); string hash = Hyena.CryptoUtil.Md5Encode(sb.ToString(), System.Text.Encoding.UTF8); connection.Execute(sql_update, hash, reader.Get <int> (0)); } } return(true); }
public MetaMetrics(Database db) { var latest_samples = new SampleModel ("GROUP BY UserID, MetricID ORDER BY stamp desc", db, "COUNT(DISTINCT(UserID)), MIN(Stamp), MAX(Stamp)"); latest_samples.Cache.AggregatesUpdated += (reader) => { Console.WriteLine ("Total unique users for this time slice: {0}", reader[1]); Console.WriteLine ("First report was on {0}", SqliteUtils.FromDbFormat (typeof(DateTime), reader[2])); Console.WriteLine ("Last report was on {0}", SqliteUtils.FromDbFormat (typeof(DateTime), reader[3])); Console.WriteLine (); }; latest_samples.Reload (); var string_summary = new MetricSampleModel (latest_samples.Cache, db, @"COUNT(DISTINCT(UserID))" ); string_summary.Cache.AggregatesUpdated += (agg_reader) => { Console.WriteLine (String.Format (" Users: {0}", fmt), agg_reader[1]); using (var reader = new HyenaDataReader (db.Query ( @"SELECT COUNT(DISTINCT(UserId)) as users, Value FROM Samples, HyenaCache WHERE MetricId = ? AND HyenaCache.ModelID = ? AND HyenaCache.ItemID = Samples.ID GROUP BY Value ORDER BY users DESC", string_summary.MetricId, string_summary.Cache.CacheId))) { while (reader.Read ()) { Console.WriteLine (" {0,-5}: {1,-20}", reader.Get<long> (0), reader.Get<string> (1)); } } Console.WriteLine (); }; var numeric_slice = new MetricSampleModel (latest_samples.Cache, db, @"MIN(CAST(Value as NUMERIC)), MAX(CAST(Value as NUMERIC)), AVG(CAST(Value as NUMERIC)), HYENA_METRICS_MEDIAN_DOUBLE(CAST(Value as NUMERIC)), COUNT(DISTINCT(UserID))" ); numeric_slice.Cache.AggregatesUpdated += (reader) => { Console.WriteLine (String.Format (" Users: {0}", fmt), reader[5]); Console.WriteLine (String.Format (" Min: {0}", fmt), Metric.ToString (numeric_slice.MetricName, reader[1])); Console.WriteLine (String.Format (" Avg: {0}", fmt), Metric.ToString (numeric_slice.MetricName, reader[3])); Console.WriteLine (String.Format (" Median: {0}", fmt), Metric.ToString (numeric_slice.MetricName, reader[4])); Console.WriteLine (String.Format (" Max: {0}", fmt), Metric.ToString (numeric_slice.MetricName, reader[2])); Console.WriteLine (); }; var metrics = db.QueryEnumerable<string> ("SELECT Name FROM Metrics ORDER BY Name ASC"); foreach (var metric in metrics) { switch (GetMetricType (metric)) { case "string": Console.WriteLine ("{0}:", metric); string_summary.ChangeMetric (db, metric); break; //case "timespan" : SummarizeNumeric<TimeSpan> (metric); break; //case "datetime" : SummarizeNumeric<DateTime> (metric); break; case "float": Console.WriteLine ("{0}:", metric); //SummarizeNumeric<long> (metric_cache); numeric_slice.ChangeMetric (db, metric); break; //case "float": //SummarizeNumeric<double> (metric_cache); //break; } } }
private void RemoveTrack (string track) { string uri = new SafeUri(track).AbsoluteUri; const string hash_sql = @"SELECT TrackID, MetadataHash FROM CoreTracks WHERE Uri = ? LIMIT 1"; int track_id = 0; string hash = null; using (var reader = new HyenaDataReader (ServiceManager.DbConnection.Query (hash_sql, uri))) { if (reader.Read ()) { track_id = reader.Get<int> (0); hash = reader.Get<string> (1); } } if (hash != null) { lock (queue) { var item = queue.FirstOrDefault ( i => i.ChangeType == WatcherChangeTypes.Created && GetMetadataHash (i) == hash); if (item != null) { item.ChangeType = WatcherChangeTypes.Renamed; item.OldFullPath = track; return; } } } const string delete_sql = @" INSERT INTO CoreRemovedTracks (DateRemovedStamp, TrackID, Uri) SELECT ?, TrackID, Uri FROM CoreTracks WHERE TrackID IN ({0}) ; DELETE FROM CoreTracks WHERE TrackID IN ({0})"; // If track_id is 0, it's a directory. HyenaSqliteCommand delete_command; if (track_id > 0) { delete_command = new HyenaSqliteCommand (String.Format (delete_sql, "?"), DateTime.Now, track_id, track_id); } else { string pattern = StringUtil.EscapeLike (uri) + "/_%"; delete_command = new HyenaSqliteCommand (String.Format (delete_sql, @"SELECT TrackID FROM CoreTracks WHERE Uri LIKE ? ESCAPE '\'"), DateTime.Now, pattern, pattern); } ServiceManager.DbConnection.Execute (delete_command); }
public virtual void UpdateUnfilteredAggregates () { HyenaSqliteCommand count_command = new HyenaSqliteCommand (String.Format ( "SELECT COUNT(*), SUM(CoreTracks.FileSize), SUM(CoreTracks.Duration) {0}", UnfilteredQuery )); using (HyenaDataReader reader = new HyenaDataReader (connection.Query (count_command))) { count = reader.Get<long> (0); filesize = reader.Get<long> (1); duration = reader.Get<TimeSpan> (2); } }
public static void ReloadWindow () { ClearData (); HyenaDataReader reader = new HyenaDataReader (ServiceManager.DbConnection.Query (@"SELECT CT.TrackID, CT.Title, CA.ArtistName, CA.Title, CT.URI, CT.TrackNumber FROM CoreTracks CT,CoreAlbums CA ON Ct.AlbumID = CA.AlbumID AND CT.TrackID IN ( SELECT CT1.TrackID from CoreTracks CT1,CoreTracks CT2 where CT1.PrimarySourceID=1 AND CT1.TrackID <> CT2.TrackID AND CT1.TitleLowered = CT2.TitleLowered AND CT1.AlbumID = CT2.AlbumID AND CT1.ArtistID = CT2.ArtistID AND CT1.Disc = CT2.Disc AND CT1.Duration = CT2.Duration ) ORDER BY CT.Title,CT.ArtistID,CT.TrackNumber")); while (reader.Read ()) { int ID = reader.Get<int> (0); String Title = reader.Get<String> (1); String Artist = reader.Get<String> (2); String Album = reader.Get<String> (3); String URI = reader.Get<String> (4); String TrackNumber = reader.Get<String> (5); AddData (ID, TrackNumber,Title, Artist, Album, URI); } }
// returns filenames of all included files in playlist public static List<Track> GetAllTracks(uint playlist_id) { HyenaDataReader reader = new HyenaDataReader (ServiceManager.DbConnection.Query ( "SELECT t.TrackID, t.Uri from CorePlaylistEntries e JOIN CoreTracks t ON(e.TrackID = t.TrackID) " + "WHERE e.PlaylistID = ?", playlist_id)); // package the Uris into a List for convenience List<Track > tracks = new List<Track> (); while (reader.Read()) { tracks.Add (new Track () { ID = reader.Get<uint> (0), Uri = new SafeUri(reader.Get<string> (1)) }); } return tracks; }
public Playlist(uint id) { HyenaDataReader reader = new HyenaDataReader (ServiceManager.DbConnection.Query ("SELECT PlaylistID, Name from CorePlaylists WHERE PlaylistID = ?", id)); if (!reader.Read ()) throw new Exception ("No such playlist!"); ID = reader.Get<uint> (0); Name = reader.Get<string> (1); }
protected override void IterateCore(HyenaDataReader reader) { SafeUri uri = new SafeUri (reader.Get<string> (0)); current_track_id = reader.Get<long> (1); // Wait for the result to be ready result_ready_event.Reset (); detector.ProcessFile (uri); result_ready_event.WaitOne (); if (IsCancelRequested) { return; } if (result_bpm > 0) { Log.DebugFormat ("Saving BPM of {0} for {1}", result_bpm, result_uri); ServiceManager.DbConnection.Execute (update_query, result_bpm, DateTime.Now, current_track_id); } else { ServiceManager.DbConnection.Execute (update_query, -1, DateTime.Now, current_track_id); Log.DebugFormat ("Unable to detect BPM for {0}", result_uri); } }
public override void GetChunks(int chunk_size) { // mark as critical region to prevent consecutive calls from mucking things up lock (payload_lock) { long timestamp; lock (timestamp_lock) { if (UseBuffer) { buffer = new Dictionary <int, IDictionary <string, object> []> (); } timestamp = DateTime.Now.Ticks; CurrentTimestamp = timestamp; } int total = ServiceManager.DbConnection.Query<int> ( "SELECT COUNT(*) FROM CorePlaylistEntries WHERE PlaylistID = ?", Id ); if (total == 0) { IDictionary <string, object> [] empty = {}; // d-bus no like nulls OnChunkReady (ObjectPath, empty, timestamp, 1, 0); return; } chunk_size = chunk_size < 1 ? 100 : chunk_size; // default chunk_size HyenaDataReader reader = new HyenaDataReader (ServiceManager.DbConnection.Query ( "SELECT TrackID FROM CorePlaylistEntries WHERE PlaylistID = ?", Id) ); // deliver data asynchronously via signal in chunks of chunk_size // this should make things look like they are happening quickly over our tube int sequence_num = 1; for (int i = 0; i < total; i += chunk_size) { int dict_size = (total - i) < chunk_size ? (total - i) : chunk_size; IDictionary <string, object> [] dict = new Dictionary <string, object> [dict_size]; for (int j = 0; j < dict.Length; j++) { dict[j] = new Dictionary <string, object> (); if (reader.Read ()) { dict[j].Add ("TrackID", reader.Get <int> (0)); } } if (UseBuffer) { buffer.Add (sequence_num, dict); } OnChunkReady (ObjectPath, dict, timestamp, sequence_num++, total); } } }
private bool Migrate_39 () { // One time fixup to MetadataHash, since we no longer include the Duration string sql_select = @" SELECT t.TrackID, al.Title, ar.Name, t.Genre, t.Title, t.TrackNumber, t.Year FROM CoreTracks AS t JOIN CoreAlbums AS al ON al.AlbumID=t.AlbumID JOIN CoreArtists AS ar ON ar.ArtistID=t.ArtistID "; HyenaSqliteCommand sql_update = new HyenaSqliteCommand (@" UPDATE CoreTracks SET MetadataHash = ? WHERE TrackID = ? "); StringBuilder sb = new StringBuilder (); using (var reader = new HyenaDataReader (connection.Query (sql_select))) { while (reader.Read ()) { sb.Length = 0; sb.Append (reader.Get<string> (1)); sb.Append (reader.Get<string> (2)); sb.Append (reader.Get<string> (3)); sb.Append (reader.Get<string> (4)); sb.Append (reader.Get<int> (5)); sb.Append (reader.Get<int> (6)); string hash = Hyena.CryptoUtil.Md5Encode (sb.ToString (), System.Text.Encoding.UTF8); connection.Execute (sql_update, hash, reader.Get<int> (0)); } } return true; }
private void AddMetrics () { Add ("Client", Application.ActiveClient); Add ("BuildHostCpu", Application.BuildHostCpu); Add ("BuildHostOS", Application.BuildHostOperatingSystem); Add ("BuildTime", Application.BuildTime); Add ("BuildVendor", Application.BuildVendor); Add ("Version", Application.Version); Add ("StartedAt", ApplicationContext.StartedAt); // Query basic stats about what content the user has foreach (var src in ServiceManager.SourceManager.FindSources<PrimarySource> ()) { var type_name = src.TypeName; var reader = new HyenaDataReader (ServiceManager.DbConnection.Query ( @"SELECT COUNT(*), COUNT(CASE ifnull(Rating, 0) WHEN 0 THEN NULL ELSE 1 END), COUNT(CASE ifnull(BPM, 0) WHEN 0 THEN NULL ELSE 1 END), COUNT(CASE ifnull(LastStreamError, 0) WHEN 0 THEN NULL ELSE 1 END), COUNT(CASE ifnull(Composer, 0) WHEN 0 THEN NULL ELSE 1 END), COUNT(CASE ifnull(LicenseUri, 0) WHEN 0 THEN NULL ELSE 1 END), COUNT(CASE ifnull(Grouping, 0) WHEN 0 THEN NULL ELSE 1 END), COUNT(CASE PlayCount WHEN 0 THEN 1 ELSE NULL END), AVG(Score), AVG(BitRate), SUM(PlayCount), SUM(SkipCount), CAST (SUM(PlayCount * (Duration/1000)) AS INTEGER), SUM(FileSize) FROM CoreTracks WHERE PrimarySourceID = ?", src.DbId )); // DateAdded, Grouping var results = new string [] { "TrackCount", "RatedTrackCount", "BpmTrackCount", "ErrorTrackCount", "ComposerTrackCount", "LicenseUriTrackCount", "GroupingTrackCount", "UnplayedTrackCount", "AvgScore", "AvgBitRate", "TotalPlayCount", "TotalSkipCount", "TotalPlaySeconds", "TotalFileSize" }; for (int i = 0; i < results.Length; i++) { Add (String.Format ("{0}/{1}", type_name, results[i]), reader.Get<long> (i)); } reader.Dispose (); } // Wire up event-triggered metrics active_source_changed = Add ("ActiveSourceChanged"); ServiceManager.SourceManager.ActiveSourceChanged += OnActiveSourceChanged; shutdown = Add ("ShutdownAt", () => DateTime.Now); duration = Add ("RunDuration", () => DateTime.Now - ApplicationContext.StartedAt); Application.ShutdownRequested += OnShutdownRequested; sqlite_executed = Add ("LongSqliteCommand"); HyenaSqliteCommand.CommandExecuted += OnSqliteCommandExecuted; HyenaSqliteCommand.RaiseCommandExecuted = true; HyenaSqliteCommand.RaiseCommandExecutedThresholdMs = 400; playback_source_changed = Add ("PlaybackSourceChanged"); ServiceManager.PlaybackController.SourceChanged += OnPlaybackSourceChanged; shuffle_changed = Add ("ShuffleModeChanged"); ServiceManager.PlaybackController.ShuffleModeChanged += OnShuffleModeChanged; repeat_changed = Add ("RepeatModeChanged"); ServiceManager.PlaybackController.RepeatModeChanged += OnRepeatModeChanged; }
public static IEnumerable<PlaylistSource> LoadAll(PrimarySource parent) { ClearTemporary (); using (HyenaDataReader reader = new HyenaDataReader (ServiceManager.DbConnection.Query ( @"SELECT PlaylistID, Name, SortColumn, SortType, PrimarySourceID, CachedCount, IsTemporary FROM CorePlaylists WHERE Special = 0 AND PrimarySourceID = ?", parent.DbId))) { while (reader.Read ()) { yield return new PlaylistSource ( reader.Get<string> (1), reader.Get<long> (0), reader.Get<int> (2), reader.Get<int> (3), parent, reader.Get<int> (5), reader.Get<bool> (6) ); } } }
public virtual void UpdateUnfilteredAggregates() { HyenaSqliteCommand count_command = new HyenaSqliteCommand (String.Format ( "SELECT COUNT(*), SUM({0}), SUM({1}) {2}", BansheeQuery.FileSizeField.Column, BansheeQuery.DurationField.Column, UnfilteredQuery )); using (HyenaDataReader reader = new HyenaDataReader (connection.Query (count_command))) { count = reader.Get<long> (0); filesize = reader.Get<long> (1); duration = reader.Get<TimeSpan> (2); } }
protected abstract void IterateCore(HyenaDataReader reader);
protected override void IterateCore(HyenaDataReader reader) { var track = new CoverartTrackInfo () { AlbumTitle = reader.Get<string> (1), ArtistName = reader.Get<string> (2), PrimarySource = ServiceManager.SourceManager.MusicLibrary, Uri = new SafeUri (reader.Get<string> (3)), DbId = reader.Get<long> (4), AlbumId = reader.Get<long> (0) }; Status = String.Format (Catalog.GetString ("{0} - {1}"), track.ArtistName, track.AlbumTitle); FetchForTrack (track); }
public MetaMetrics(Database db) { var latest_samples = new SampleModel("GROUP BY UserID, MetricID ORDER BY stamp desc", db, "COUNT(DISTINCT(UserID)), MIN(Stamp), MAX(Stamp)"); latest_samples.Cache.AggregatesUpdated += (reader) => { Console.WriteLine("Total unique users for this time slice: {0}", reader[1]); Console.WriteLine("First report was on {0}", SqliteUtils.FromDbFormat(typeof(DateTime), reader[2])); Console.WriteLine("Last report was on {0}", SqliteUtils.FromDbFormat(typeof(DateTime), reader[3])); Console.WriteLine(); }; latest_samples.Reload(); var string_summary = new MetricSampleModel(latest_samples.Cache, db, @"COUNT(DISTINCT(UserID))" ); string_summary.Cache.AggregatesUpdated += (agg_reader) => { Console.WriteLine(String.Format(" Users: {0}", fmt), agg_reader[1]); using (var reader = new HyenaDataReader(db.Query( @"SELECT COUNT(DISTINCT(UserId)) as users, Value FROM Samples, HyenaCache WHERE MetricId = ? AND HyenaCache.ModelID = ? AND HyenaCache.ItemID = Samples.ID GROUP BY Value ORDER BY users DESC", string_summary.MetricId, string_summary.Cache.CacheId))) { while (reader.Read()) { Console.WriteLine(" {0,-5}: {1,-20}", reader.Get <long> (0), reader.Get <string> (1)); } } Console.WriteLine(); }; var numeric_slice = new MetricSampleModel(latest_samples.Cache, db, @"MIN(CAST(Value as NUMERIC)), MAX(CAST(Value as NUMERIC)), AVG(CAST(Value as NUMERIC)), HYENA_METRICS_MEDIAN_DOUBLE(CAST(Value as NUMERIC)), COUNT(DISTINCT(UserID))" ); numeric_slice.Cache.AggregatesUpdated += (reader) => { Console.WriteLine(String.Format(" Users: {0}", fmt), reader[5]); Console.WriteLine(String.Format(" Min: {0}", fmt), Metric.ToString(numeric_slice.MetricName, reader[1])); Console.WriteLine(String.Format(" Avg: {0}", fmt), Metric.ToString(numeric_slice.MetricName, reader[3])); Console.WriteLine(String.Format(" Median: {0}", fmt), Metric.ToString(numeric_slice.MetricName, reader[4])); Console.WriteLine(String.Format(" Max: {0}", fmt), Metric.ToString(numeric_slice.MetricName, reader[2])); Console.WriteLine(); }; var metrics = db.QueryEnumerable <string> ("SELECT Name FROM Metrics ORDER BY Name ASC"); foreach (var metric in metrics) { switch (GetMetricType(metric)) { case "string": Console.WriteLine("{0}:", metric); string_summary.ChangeMetric(db, metric); break; //case "timespan" : SummarizeNumeric<TimeSpan> (metric); break; //case "datetime" : SummarizeNumeric<DateTime> (metric); break; case "float": Console.WriteLine("{0}:", metric); //SummarizeNumeric<long> (metric_cache); numeric_slice.ChangeMetric(db, metric); break; //case "float": //SummarizeNumeric<double> (metric_cache); //break; } } }
public static List<Playlist> GetAllPlaylists() { // get all the Uri from database HyenaDataReader reader = new HyenaDataReader (ServiceManager.DbConnection.Query ("SELECT PlaylistID, Name from CorePlaylists")); var playlists = new List<Playlist> (); while (reader.Read()) { playlists.Add (new Playlist { ID = reader.Get<uint> (0), Name = reader.Get<string> (1) }); } return playlists; }
private void UpdateUnfilteredAggregates() { using (var reader = new HyenaDataReader(connection.Query(UnfilteredCountCommand))) { UnfilteredCount = reader.Get <int> (0); } }
protected override void IterateCore(HyenaDataReader reader) { SafeUri uri = new SafeUri (reader.Get<string> (0)); Log.Debug ("Detecting mood for " + uri.LocalPath); result_ready_event.Reset (); if (IsCancelRequested) { Log.Debug ("Detection canceled"); return; } if (moodbar_service == null) { Log.Debug ("Detection stopped - moodbar_service is null"); return; } moodbar_service.DetectMood (uri, m => { if (m != null) { Log.Debug ("Mood detected and saved as " + m.FilePath); Thread.Sleep (5000); } else { Log.Debug ("Mood not detected"); } result_ready_event.Set (); }); result_ready_event.WaitOne (); }
private void AddMetrics() { Add("Client", Application.ActiveClient); Add("BuildHostCpu", Application.BuildHostCpu); Add("BuildHostOS", Application.BuildHostOperatingSystem); Add("BuildTime", Application.BuildTime); Add("BuildVendor", Application.BuildVendor); Add("Version", Application.Version); Add("StartedAt", ApplicationContext.StartedAt); // Query basic stats about what content the user has foreach (var src in ServiceManager.SourceManager.FindSources <PrimarySource> ()) { var type_name = src.TypeName; var reader = new HyenaDataReader(ServiceManager.DbConnection.Query( @"SELECT COUNT(*), COUNT(CASE ifnull(Rating, 0) WHEN 0 THEN NULL ELSE 1 END), COUNT(CASE ifnull(BPM, 0) WHEN 0 THEN NULL ELSE 1 END), COUNT(CASE ifnull(LastStreamError, 0) WHEN 0 THEN NULL ELSE 1 END), COUNT(CASE ifnull(Composer, 0) WHEN 0 THEN NULL ELSE 1 END), COUNT(CASE ifnull(LicenseUri, 0) WHEN 0 THEN NULL ELSE 1 END), COUNT(CASE ifnull(Grouping, 0) WHEN 0 THEN NULL ELSE 1 END), COUNT(CASE PlayCount WHEN 0 THEN 1 ELSE NULL END), AVG(Score), AVG(BitRate), SUM(PlayCount), SUM(SkipCount), CAST (SUM(PlayCount * (Duration/1000)) AS INTEGER), SUM(FileSize) FROM CoreTracks WHERE PrimarySourceID = ?", src.DbId )); // DateAdded, Grouping var results = new string [] { "TrackCount", "RatedTrackCount", "BpmTrackCount", "ErrorTrackCount", "ComposerTrackCount", "LicenseUriTrackCount", "GroupingTrackCount", "UnplayedTrackCount", "AvgScore", "AvgBitRate", "TotalPlayCount", "TotalSkipCount", "TotalPlaySeconds", "TotalFileSize" }; for (int i = 0; i < results.Length; i++) { Add(String.Format("{0}/{1}", type_name, results[i]), reader.Get <long> (i)); } reader.Dispose(); } // Wire up event-triggered metrics active_source_changed = Add("ActiveSourceChanged"); ServiceManager.SourceManager.ActiveSourceChanged += OnActiveSourceChanged; shutdown = Add("ShutdownAt", () => DateTime.Now); duration = Add("RunDuration", () => DateTime.Now - ApplicationContext.StartedAt); Application.ShutdownRequested += OnShutdownRequested; sqlite_executed = Add("LongSqliteCommand"); HyenaSqliteCommand.CommandExecuted += OnSqliteCommandExecuted; HyenaSqliteCommand.RaiseCommandExecuted = true; HyenaSqliteCommand.RaiseCommandExecutedThresholdMs = 400; playback_source_changed = Add("PlaybackSourceChanged"); ServiceManager.PlaybackController.SourceChanged += OnPlaybackSourceChanged; shuffle_changed = Add("ShuffleModeChanged"); ServiceManager.PlaybackController.ShuffleModeChanged += OnShuffleModeChanged; repeat_changed = Add("RepeatModeChanged"); ServiceManager.PlaybackController.RepeatModeChanged += OnRepeatModeChanged; }
protected override void IterateCore(HyenaDataReader reader) { var track = new CoverartTrackInfo { AlbumTitle = reader.Get<string> (1), ArtistName = reader.Get<string> (2), PrimarySource = ServiceManager.SourceManager.MusicLibrary, Uri = new SafeUri (reader.Get<string> (3)), DbId = reader.Get<int> (4), AlbumId = reader.Get<int> (0) }; Status = String.Format (AddinManager.CurrentLocalizer.GetString ("{0} - {1}"), track.ArtistName, track.AlbumTitle); WriteArt (track); }
protected bool Iterate() { if (IsCancelRequested) { return false; } YieldToScheduler (); int total = current_count + ServiceManager.DbConnection.Query<int> (count_command); try { using (HyenaDataReader reader = new HyenaDataReader (ServiceManager.DbConnection.Query (select_command))) { if (reader.Read ()) { IterateCore (reader); failure_count = 0; } else { return false; } } } catch (System.Threading.ThreadAbortException) { Cleanup (); throw; } catch (Exception e) { Log.Error (e); failure_count++; if (failure_count > MAX_FAILURE_COUNT) { Log.WarningFormat ("Too many consecutive errors for job '{0}', aborting", this.Title); return false; } } finally { Progress = (double) current_count / (double) total; current_count++; } return true; }
private bool Migrate_27 () { // One time fixup to MetadataHash now that our unknown metadata is handled properly string sql_select = @" SELECT t.TrackID, al.Title, ar.Name, t.Duration, t.Genre, t.Title, t.TrackNumber, t.Year FROM CoreTracks AS t JOIN CoreAlbums AS al ON al.AlbumID=t.AlbumID JOIN CoreArtists AS ar ON ar.ArtistID=t.ArtistID WHERE t.Title IS NULL OR ar.Name IS NULL OR al.Title IS NULL "; HyenaSqliteCommand sql_update = new HyenaSqliteCommand (@" UPDATE CoreTracks SET MetadataHash = ? WHERE TrackID = ? "); StringBuilder sb = new StringBuilder (); using (var reader = new HyenaDataReader (connection.Query (sql_select))) { while (reader.Read ()) { sb.Length = 0; sb.Append (reader.Get<string> (1)); sb.Append (reader.Get<string> (2)); sb.Append ((int)reader.Get<TimeSpan> (3).TotalSeconds); sb.Append (reader.Get<string> (4)); sb.Append (reader.Get<string> (5)); sb.Append (reader.Get<int> (6)); sb.Append (reader.Get<int> (7)); string hash = Hyena.CryptoUtil.Md5Encode (sb.ToString (), System.Text.Encoding.UTF8); connection.Execute (sql_update, hash, reader.Get<int> (0)); } } return true; }
protected abstract void IterateCore (HyenaDataReader reader);
private void MigrateCacheDir() { int version = CacheVersion; if (version == CUR_VERSION) { return; } var legacy_root_path = CoverArtSpec.LegacyRootPath; if (version < 1) { string legacy_artwork_path = Paths.Combine(LegacyPaths.ApplicationData, "covers"); if (!Directory.Exists(legacy_root_path)) { Directory.Create(legacy_root_path); if (Directory.Exists(legacy_artwork_path)) { Directory.Move(new SafeUri(legacy_artwork_path), new SafeUri(legacy_root_path)); } } if (Directory.Exists(legacy_artwork_path)) { Log.InformationFormat("Deleting old (Banshee < 1.0) artwork cache directory {0}", legacy_artwork_path); Directory.Delete(legacy_artwork_path, true); } } if (version < 2) { int deleted = 0; foreach (string dir in Directory.GetDirectories(legacy_root_path)) { int size; string dirname = System.IO.Path.GetFileName(dir); if (Int32.TryParse(dirname, out size) && !IsCachedSize(size)) { Directory.Delete(dir, true); deleted++; } } if (deleted > 0) { Log.InformationFormat("Deleted {0} extraneous album-art cache directories", deleted); } } if (version < 3) { Log.Information("Migrating album-art cache directory"); var started = DateTime.Now; int count = 0; var root_path = CoverArtSpec.RootPath; if (!Directory.Exists(root_path)) { Directory.Create(root_path); } string sql = "SELECT Title, ArtistName FROM CoreAlbums"; using (var reader = new HyenaDataReader(ServiceManager.DbConnection.Query(sql))) { while (reader.Read()) { var album = reader.Get <string>(0); var artist = reader.Get <string>(1); var old_file = CoverArtSpec.CreateLegacyArtistAlbumId(artist, album); var new_file = CoverArtSpec.CreateArtistAlbumId(artist, album); if (String.IsNullOrEmpty(old_file) || String.IsNullOrEmpty(new_file)) { continue; } old_file = String.Format("{0}.jpg", old_file); new_file = String.Format("{0}.jpg", new_file); var old_path = new SafeUri(Paths.Combine(legacy_root_path, old_file)); var new_path = new SafeUri(Paths.Combine(root_path, new_file)); if (Banshee.IO.File.Exists(old_path) && !Banshee.IO.File.Exists(new_path)) { Banshee.IO.File.Move(old_path, new_path); count++; } } } if (ServiceManager.DbConnection.TableExists("PodcastSyndications")) { sql = "SELECT Title FROM PodcastSyndications"; foreach (var title in ServiceManager.DbConnection.QueryEnumerable <string> (sql)) { var old_digest = CoverArtSpec.LegacyEscapePart(title); var new_digest = CoverArtSpec.Digest(title); if (String.IsNullOrEmpty(old_digest) || String.IsNullOrEmpty(new_digest)) { continue; } var old_file = String.Format("podcast-{0}.jpg", old_digest); var new_file = String.Format("podcast-{0}.jpg", new_digest); var old_path = new SafeUri(Paths.Combine(legacy_root_path, old_file)); var new_path = new SafeUri(Paths.Combine(root_path, new_file)); if (Banshee.IO.File.Exists(old_path) && !Banshee.IO.File.Exists(new_path)) { Banshee.IO.File.Move(old_path, new_path); count++; } } } if (count == 0) { ResetScanResultCache(); } Directory.Delete(legacy_root_path, true); Log.InformationFormat("Migrated {0} files in {1}s", count, DateTime.Now.Subtract(started).TotalSeconds); } CacheVersion = CUR_VERSION; }
protected bool Iterate () { if (IsCancelRequested) { return false; } YieldToScheduler (); int total = current_count + ServiceManager.DbConnection.Query<int> (count_command); try { using (HyenaDataReader reader = new HyenaDataReader (ServiceManager.DbConnection.Query (select_command))) { if (reader.Read ()) { IterateCore (reader); } else { return false; } } } catch (System.Threading.ThreadAbortException) { Cleanup (); throw; } catch (Exception e) { Log.Exception (e); } finally { Progress = (double) current_count / (double) total; current_count++; } return true; }