void OnContentUpdated(string location, bool removed) { ContentUpdated?.Invoke(this, new ContentUpdatedEventArgs(location, removed)); }
public void OnContentUpdated() { ContentUpdated?.Invoke(this, new EventArgs()); }
private void SyncDatabaseToImageRecList(IEnumerable <ImageRec> filesOnDisk, Theme theme, Database db, CancellationToken cancel) { var table = db.SelectDataTable("select rowid, * from img where location_id = @id", "@id", _rowid); // Find files in the database that don't exist on disk var filesToRemove = new List <long>(); foreach (DataRow row in table.Rows) { if (cancel.IsCancellationRequested) { return; } var path = (string)row["path"]; var found = false; foreach (var file in filesOnDisk) { if (string.Equals(file.Location, path, StringComparison.OrdinalIgnoreCase)) { found = true; break; } } if (!found) { filesToRemove.Add((long)row["rowid"]); } } var changesMade = false; using (var tran = db.BeginTransaction()) { if (filesToRemove.Count > 0) { using (var cmd = db.CreateCommand("delete from img where rowid = @rowid")) { foreach (var rowid in filesToRemove) { if (cancel.IsCancellationRequested) { return; } cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@rowid", rowid); cmd.ExecuteNonQuery(); changesMade = true; } } } // Find files on disk that don't exist in the database var filesToAdd = new List <ImageRec>(); foreach (var file in filesOnDisk) { if (cancel.IsCancellationRequested) { return; } DataRow foundRow = null; foreach (DataRow row in table.Rows) { if (cancel.IsCancellationRequested) { return; } if (string.Equals(file.Location, (string)row["path"], StringComparison.OrdinalIgnoreCase)) { foundRow = row; break; } } if (foundRow == null) { filesToAdd.Add(file); } else { // Check if new cache path needs to be updated in the img table if (file.Type == ImageLocationType.Url && string.IsNullOrEmpty(file.LocationOnDisk)) { string cachePathName; if (ImageCache.TryGetCachedImage(db, file.Location, out cachePathName)) { db.ExecuteNonQuery("update img set cache_path = @cache_path where path = @path", "@cache_path", cachePathName, "@path", file.Location); db.ExecuteNonQuery("update history set cache_path = @cache_path where path = @path", "@cache_path", cachePathName, "@path", file.Location); changesMade = true; } } // Check if the size needs updating if (foundRow.GetLong("size", -1) == -1 && !string.IsNullOrEmpty(file.LocationOnDisk)) { file.RefreshFileSize(); var size = file.Size; if (size.HasValue) { db.ExecuteNonQuery("update img set size = @size where path = @path", "@size", size.Value, "@path", file.Location); // No need to update history since it doesn't care about the size. changesMade = true; } } } } if (filesToAdd.Count > 0) { using (var cmd = db.CreateCommand("insert into img (theme_id, location_id, type, path, pub_date, rating, thumb, size)" + " values (@theme_id, @location_id, @type, @path, @pub_date, @rating, @thumb, @size)")) { foreach (var img in filesToAdd) { if (cancel.IsCancellationRequested) { return; } #if DEBUG Log.Debug("Inserting: {0}", img.Location); #endif cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@theme_id", theme.RowId); cmd.Parameters.AddWithValue("@location_id", _rowid); cmd.Parameters.AddWithValue("@type", img.Type.ToString()); cmd.Parameters.AddWithValue("@path", img.Location); cmd.Parameters.AddWithValue("@pub_date", img.PubDate.HasValue ? (object)img.PubDate.Value : null); cmd.Parameters.AddWithValue("@rating", img.Rating); cmd.Parameters.AddWithValue("@thumb", img.Thumbnail?.Data); if (img.Size.HasValue) { cmd.Parameters.AddWithValue("@size", img.Size.Value); } else { cmd.Parameters.AddWithValue("@size", null); } cmd.ExecuteNonQuery(); changesMade = true; } } } tran.Commit(); } if (changesMade) { ContentUpdated?.Invoke(this, EventArgs.Empty); } }
void UpdateControls(Size screenSize) { ContentUpdated?.Invoke(GetViewportBoundaries(screenSize)); }
protected void NotifyContentUpdated() { ContentUpdated?.Invoke(this, EventArgs.Empty); }
/// <summary> /// Signals an update by firing the <see cref="ContentUpdated"/> event. /// Call this whenever status changes to trigger a soft render. /// </summary> protected void SignalUpdate() => ContentUpdated?.Invoke(this, new EventArgs());