void OnChange(RealmResults <T> sender, RealmResults <T> .ChangeSet change, Exception error) { if (error != null) { _errorCallback(error); } else if (change != null) { _suspendNotifications = _coalesceMultipleChangesIntoReset && change.InsertedIndices.Length + change.DeletedIndices.Length > 1; foreach (var removed in change.DeletedIndices.Reverse()) { // the row has been deleted, we need to recreate the adapter's contents if (!this[removed].RowHandle.IsAttached) { Recreate(); return; } RemoveAt(removed); } foreach (var added in change.InsertedIndices) { InsertItem(added, _results[added]); } if (_suspendNotifications) { RaiseReset(); _suspendNotifications = false; } } }
internal Adapter(RealmResults <T> results, Action <Exception> errorCallback, bool coalesceMultipleChangesIntoReset) : base(results) { _results = results; _errorCallback = errorCallback; _coalesceMultipleChangesIntoReset = coalesceMultipleChangesIntoReset; _token = results.SubscribeForNotifications(OnChange); }
/// <summary> /// Remove objects matcing a query from the realm. /// </summary> /// <typeparam name="T">Type of the objects to remove.</typeparam> /// <param name="range">The query to match for.</param> public void RemoveRange <T>(RealmResults <T> range) where T : RealmObject { if (!IsInTransaction) { throw new RealmOutsideTransactionException("Cannot remove Realm objects outside write transactions"); } NativeResults.clear(range.ResultsHandle); }
/// <summary> /// Remove objects matching a query from the realm. /// </summary> /// <typeparam name="T">Type of the objects to remove.</typeparam> /// <param name="range">The query to match for.</param> public void RemoveRange <T>(RealmResults <T> range) { if (range == null) { throw new ArgumentNullException(nameof(range)); } range.ResultsHandle.Clear(SharedRealmHandle); }
public Adapter(RealmResults <T> results, Action <Exception> errorCallback, bool coalesceMultipleChangesIntoReset) : base(results) { _results = results; _errorCallback = errorCallback; _coalesceMultipleChangesIntoReset = coalesceMultipleChangesIntoReset; _token = results.SubscribeForNotifications(OnChange); Debug.Assert(_token != null, "Subscription token must not be null."); }
/// <summary> /// Remove objects matcing a query from the realm. /// </summary> /// <typeparam name="T">Type of the objects to remove.</typeparam> /// <param name="range">The query to match for.</param> public void RemoveRange <T>(RealmResults <T> range) { if (range == null) { throw new ArgumentNullException(nameof(range)); } if (!IsInTransaction) { throw new RealmOutsideTransactionException("Cannot remove Realm objects outside write transactions"); } range.ResultsHandle.Clear(); }
/// <summary> /// Wraps a <see cref="RealmResults{T}" /> in an implementation of <see cref="INotifyCollectionChanged" /> so that it may be used in MVVM databinding. /// </summary> /// <param name="results">The <see cref="RealmResults{T}"/ > to observe for changes.</param> /// <param name="errorCallback">An error callback that will be invoked if the observing thread raises an error.</param> /// <param name="coalesceMultipleChangesIntoReset"> /// When a lot of items have been added or removed at once it is more efficient to raise <see cref="INotifyCollectionChanged.CollectionChanged" /> once /// with <see cref="NotifyCollectionChangedAction.Reset" /> instead of multiple times for every single change. Pass <c>true</c> to opt-in to this behavior. /// </param> /// <returns>An <see cref="ObservableCollection{T}" />-like object useful for MVVM databinding.</returns> /// <seealso cref="RealmResults{T}.SubscribeForNotifications(RealmResults{T}.NotificationCallback)"/> public static INotifyCollectionChanged ToNotifyCollectionChanged <T>(this RealmResults <T> results, Action <Exception> errorCallback, bool coalesceMultipleChangesIntoReset) where T : RealmObject { if (results == null) { throw new ArgumentNullException(nameof(results)); } if (errorCallback == null) { throw new ArgumentNullException(nameof(errorCallback)); } return(new ReadOnlyObservableCollection <T>(new Adapter <T>(results, errorCallback, coalesceMultipleChangesIntoReset))); }
/// <summary> /// Remove objects matcing a query from the realm. /// </summary> /// <typeparam name="T">Type of the objects to remove.</typeparam> /// <param name="range">The query to match for.</param> public void RemoveRange <T>(RealmResults <T> range) where T : RealmObject { RealmPCLHelpers.ThrowProxyShouldNeverBeUsed(); }
/// <summary> /// Wraps a <see cref="RealmResults{T}" /> in an implementation of <see cref="INotifyCollectionChanged" /> so that it may be used in MVVM databinding. /// </summary> /// <param name="results">The <see cref="RealmResults{T}"/ > to observe for changes.</param> /// <param name="errorCallback">An error callback that will be invoked if the observing thread raises an error.</param> /// <returns>An <see cref="ObservableCollection{T}" />-like object useful for MVVM databinding.</returns> /// <seealso cref="RealmResults{T}.SubscribeForNotifications(RealmResults{T}.NotificationCallback)"/> public static INotifyCollectionChanged ToNotifyCollectionChanged <T>(this RealmResults <T> results, Action <Exception> errorCallback) where T : RealmObject { return(ToNotifyCollectionChanged(results, errorCallback, coalesceMultipleChangesIntoReset: false)); }
public void Dispose() { _results.RemoveCallback(_callback); _callback = null; _results = null; }
internal NotificationToken(RealmResults <T> results, NotificationCallback callback) { _results = results; _callback = callback; }
/// <summary> /// Wraps a <see cref="RealmResults{T}" /> in an implementation of <see cref="INotifyCollectionChanged" /> so that it may be used in MVVM databinding. /// </summary> /// <param name="results">The <see cref="RealmResults{T}"/ > to observe for changes.</param> /// <param name="errorCallback">An error callback that will be invoked if the observing thread raises an error.</param> /// <param name="coalesceMultipleChangesIntoReset"> /// When a lot of items have been added or removed at once it is more efficient to raise <see cref="INotifyCollectionChanged.CollectionChanged" /> once /// with <see cref="NotifyCollectionChangedAction.Reset" /> instead of multiple times for every single change. Pass <c>true</c> to opt-in to this behavior. /// </param> /// <returns>An <see cref="ObservableCollection{T}" />-like object useful for MVVM databinding.</returns> /// <seealso cref="RealmResults{T}.SubscribeForNotifications(RealmResults{T}.NotificationCallback)"/> public static INotifyCollectionChanged ToNotifyCollectionChanged <T>(this RealmResults <T> results, Action <Exception> errorCallback, bool coalesceMultipleChangesIntoReset) where T : RealmObject { RealmPCLHelpers.ThrowProxyShouldNeverBeUsed(); return(null); }