예제 #1
0
            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;
                    }
                }
            }
예제 #2
0
            internal Adapter(RealmResults <T> results, Action <Exception> errorCallback, bool coalesceMultipleChangesIntoReset) : base(results)
            {
                _results       = results;
                _errorCallback = errorCallback;
                _coalesceMultipleChangesIntoReset = coalesceMultipleChangesIntoReset;

                _token = results.SubscribeForNotifications(OnChange);
            }
예제 #3
0
        /// <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);
        }
예제 #4
0
        /// <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);
        }
예제 #5
0
            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.");
            }
예제 #6
0
        /// <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();
        }
예제 #7
0
        /// <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)));
        }
예제 #8
0
 /// <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();
 }
예제 #9
0
 /// <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));
 }
예제 #10
0
 public void Dispose()
 {
     _results.RemoveCallback(_callback);
     _callback = null;
     _results  = null;
 }
예제 #11
0
 internal NotificationToken(RealmResults <T> results, NotificationCallback callback)
 {
     _results  = results;
     _callback = callback;
 }
예제 #12
0
 /// <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);
 }