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 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); } } } }
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); }
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); }
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); }
// 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); }
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); }
// 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 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; }
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); }
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) ); } } }
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 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); } }
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 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; }
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); } } }
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 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 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; }
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); 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; }