/// <summary>Empty the binding source table</summary> public void Clear() { // Notify of the pending reset of the binding source table ListChanging?.Invoke(this, new ListChgEventArgs <Type>(this, ListChg.PreReset, -1, default(Type))); Count = 0; // Notify of binding source data reset ListChanging?.Invoke(this, new ListChgEventArgs <Type>(this, ListChg.Reset, -1, default(Type))); }
public CollectionBase(Exchange exchange, Func <TValue, TKey> key_from) { Exchange = exchange; Updated = new ConditionVariable <DateTimeOffset>(DateTimeOffset.MinValue); m_data = new BindingDict <TKey, TValue> { KeyFrom = key_from }; m_data.CollectionChanged += (s, a) => CollectionChanged?.Invoke(this, a); m_data.ListChanging += (s, a) => ListChanging?.Invoke(this, a); }
/// <summary>Updates the data table based on current filter, sorting, etc.</summary> public void Update(bool raise_events = true) { // Invalidate to cause an Invalidated event before every update if (!UpdateRequired) { Invalidate(); } UpdateRequired = false; // No data source, no update if (DB == null) { Count = 0; Cache.Flush(); return; } // Check for threading issues // TODO: this can take a long time. It needs to be asynchronous somehow Debug.Assert(DB.AssertCorrectThread()); // Generate the new binding source table in a temp table allowing use // of the previous table while the 'Filtering' is happening. var tmp_table = TableName + "_TMP"; // Create the temporary table using (var t = DB.NewTransaction()) { DB.Execute($"drop table if exists {tmp_table}"); DB.Execute( $"create table {tmp_table} (\n" + " [Idx] integer primary key autoincrement,\n" + " [Key] integer\n" + ")"); // Populate from the base table using the filters var join = Join ?? string.Empty; var filter = Filter ?? string.Empty; var orderby = OrderBy ?? string.Empty; DB.Execute( $"insert into {tmp_table} ([Key])\n" + $"select {Pk} from {BaseTableName}\n" + (join.Length != 0 ? $" join {join}" : "") + (filter.Length != 0 ? $"{(join.Contains(" where ") ? " and " : " where ")} {filter}" : "") + (orderby.Length != 0 ? $" order by {orderby}" : "")); t.Commit(); } // Notify of the pending reset of the binding source table if (raise_events) { ListChanging?.Invoke(this, new ListChgEventArgs <Type>(this, ListChg.PreReset, -1, default(Type))); } // Drop the old table and rename the temporary table to the new binding source table using (var t = DB.NewTransaction()) { DB.Execute($"drop table if exists {TableName}"); DB.Execute($"alter table {tmp_table} rename to {TableName}"); t.Commit(); } // Get the new table count Count = DB.ExecuteScalar($"select count(*) from {TableName}"); Cache.Flush(); // Notify of binding source data reset if (raise_events) { ListChanging?.Invoke(this, new ListChgEventArgs <Type>(this, ListChg.Reset, -1, default(Type))); } }
private void OnReseting() { ListChanging?.Invoke(this, new ListChangingEventArgs <MessageTraceItem>(ListChangingType.Clearing, null)); }
protected virtual void OnListChanging(ListChgEventArgs <TValue> args) { ListChanging?.Invoke(this, args); }