예제 #1
0
        public IListenerRegistration AddSnapshotListener(QuerySnapshotHandler listener)
        {
            var registration = _collectionReference.AddSnapshotListener(new EventHandlerListener <QuerySnapshot>((value, error) =>
            {
                listener?.Invoke(value == null ? null : new QuerySnapshotWrapper(value),
                                 error == null ? null : ExceptionMapper.Map(error));
            }));

            return(new ListenerRegistrationWrapper(registration));
        }
예제 #2
0
        public IListenerRegistration AddSnapshotListener(QuerySnapshotHandler listener)
        {
            var registration = _collectionReference.AddSnapshotListener((snapshot, error) =>
            {
                listener?.Invoke(snapshot == null ? null : new QuerySnapshotWrapper(snapshot),
                                 error == null ? null : ExceptionMapper.Map(error));
            });

            return(new ListenerRegistrationWrapper(registration));
        }
        public IDisposable AddSnapshotListener <T>(Action <IQuerySnapshot <T> > onChanged, Action <Exception> onError = null, bool includeMetaDataChanges = false)
        {
            var registration = _wrapped
                               .AddSnapshotListener(includeMetaDataChanges ? MetadataChanges.Include : MetadataChanges.Exclude, new EventListener(
                                                        x => onChanged(new QuerySnapshotWrapper <T>(x.JavaCast <QuerySnapshot>())),
                                                        e => onError?.Invoke(new FirebaseException(e.LocalizedMessage))));

            return(new DisposableWithAction(registration.Remove));
        }
        public IDisposable AddSnapshotListener <T>(Action <IQuerySnapshot <T> > onChanged, Action <Exception> onError = null, bool includeMetaDataChanges = false)
        {
            var registration = _wrapped.AddSnapshotListener(includeMetaDataChanges, (snapshot, error) => {
                if (error == null)
                {
                    onChanged(new QuerySnapshotWrapper <T>(snapshot));
                }
                else
                {
                    onError?.Invoke(new FirebaseException(error.LocalizedDescription));
                }
            });

            return(new DisposableWithAction(registration.Remove));
        }
        public static Task <IEnumerable <T> > GetCollectionAsync <T>(this CollectionReference reference) where T : class
        {
            var tcs = new TaskCompletionSource <IEnumerable <T> >();

            reference
            .AddSnapshotListener((snapshot, error) =>
            {
                if (error != null)
                {
                    tcs.SetException(new Exception(error.LocalizedDescription));
                    return;
                }

                var data = snapshot.Documents.Select((doc) => Cast <T>(doc)).ToList();
                tcs.SetResult(data);
            });

            return(tcs.Task);
        }