Example #1
0
        private void UpdateLocationInfo(IDocumentSnapshot document, GeoPoint location)
        {
            var key = document.Id;

            _locationInfos.TryGetValue(key, out var oldInfo);
            var isNew           = oldInfo == null;
            var changedLocation = oldInfo != null && !Equals(oldInfo.Location, location);
            var wasInQuery      = oldInfo != null && oldInfo.InGeoQuery;

            var isInQuery = LocationIsInQuery(location);

            if ((isNew || !wasInQuery) && isInQuery)
            {
                OnDocumentEntered?.Invoke(this, new DocumentEventArgs <T>(document.ToObject <T>(), location));
            }
            else if (!isNew && isInQuery)
            {
                if (changedLocation)
                {
                    OnDocumentMoved?.Invoke(this, new DocumentEventArgs <T>(document.ToObject <T>(), location));
                }
                OnDocumentChanged?.Invoke(this, new DocumentEventArgs <T>(document.ToObject <T>(), location));
            }
            else if (wasInQuery && !isInQuery)
            {
                OnDocumentExited?.Invoke(this, new DocumentEventArgs <T>(document.ToObject <T>()));
            }

            var newInfo = new LocationInfo(location, LocationIsInQuery(location), document);

            _locationInfos.Add(key, newInfo);
        }
Example #2
0
        private static void OnCurrentSnapshot(IDocumentSnapshot?snapshot)
        {
            Current = snapshot?.ToObject <DonorUser>();
            CurrentUpdated?.Invoke(Current);
            if (previousUID != Current?.UID)
            {
                previousUID = Current?.UID;
                CurrentChanged?.Invoke(Current);
                CrossFirebasePushNotification.Current.UnsubscribeAll();
                if (!(Current is null))
                {
                    CrossFirebasePushNotification.Current.Subscribe("Urgent_Project");
                }
            }
            _ = DonationBundle.SetCurrentAsync(Current?.CurrentDonationBundle);
            if (!(Current is null) && ThemeEngine.SetTheme(Current.DesiredTheme))
            {
                SecureStorage.SetAsync("ThemePreference", Current.DesiredTheme.ToString());
            }
            var newTopics = Current?.DonatedProjectUIDs.Select(x => "Project_" + x)
                            .Where(x => !CrossFirebasePushNotification.Current.SubscribedTopics.Contains(x));

            if (newTopics?.Any() ?? false)
            {
                CrossFirebasePushNotification.Current.Subscribe(newTopics.ToArray());
            }
            System.Diagnostics.Debug.WriteLine(string.Join(", ", CrossFirebasePushNotification.Current.SubscribedTopics));
        }
Example #3
0
        public async Task <User> GetUserByPresenceIdAsync(string presenceId)
        {
            User result = null;

            if (!string.IsNullOrEmpty(presenceId))
            {
                try
                {
                    IQuerySnapshot querySnapshot = await _firestore.GetCollection(nameof(User)).WhereEqualsTo(nameof(User.PresenceId), presenceId).GetDocumentsAsync();

                    IDocumentSnapshot documentSnapshot = querySnapshot.Documents.FirstOrDefault();
                    if (documentSnapshot.Exists)
                    {
                        result = documentSnapshot.ToObject <User>();
                    }
                }
                catch (Exception e)
                {
                    result = null;
                    App.LogException(e);
                }
            }

            return(result);
        }
Example #4
0
 private static void OnCurrentSnapshot(IDocumentSnapshot?snapshot)
 {
     Current = snapshot?.ToObject <Team>();
     CurrentUpdated?.Invoke(Current);
     if (previousUID != Current?.UID)
     {
         previousUID = Current?.UID;
         CurrentChanged?.Invoke(Current);
     }
 }
Example #5
0
        public async Task <Int64> CreateOrderIdAsync()
        {
            IDocumentSnapshot document = await fireStoreInstance.GetDocument("/OrderIds/unCmzg3mr1W9U9pAQQSk").GetDocumentAsync();

            OrderId orderId        = document.ToObject <OrderId>();
            Int64   currentOrderId = orderId.Id;

            orderId.Id = currentOrderId + 1;
            await fireStoreInstance.GetDocument("/OrderIds/unCmzg3mr1W9U9pAQQSk").UpdateDataAsync(orderId);

            return(await Task.FromResult(orderId.Id));
        }
Example #6
0
 private static void OnCurrentSnapshot(IDocumentSnapshot?snapshot)
 {
     Current = snapshot?.ToObject <DonationBundle>();
     CurrentUpdated?.Invoke(Current);
     if (previousUID != Current?.UID)
     {
         previousUID = Current?.UID;
         CurrentChanged?.Invoke(Current);
     }
     if (Current?.StripeStatus is StripeStatus.Succeeded || Current?.StripeStatus is StripeStatus.Failed)
     {
         _ = SetCurrentAsync(null);
         CurrentProcessed?.Invoke(Current?.StripeStatus is StripeStatus.Succeeded);
     }
 }
Example #7
0
 private static void OnCurrentSnapshot(IDocumentSnapshot?snapshot)
 {
     Current = snapshot?.ToObject <PartnerUser>();
     CurrentUpdated?.Invoke(Current);
     if (Current?.UID != previousUID)
     {
         previousUID = Current?.UID;
         CurrentChanged?.Invoke(Current);
     }
     if (Current?.TeamConfirmed ?? false)
     {
         Team.SetCurrent(Current.TeamUID);
     }
     if (!(Current is null) && ThemeEngine.SetTheme(Current.DesiredTheme))
     {
         SecureStorage.SetAsync("ThemePreference", Current.DesiredTheme.ToString());
     }
 }
Example #8
0
        public async Task <Event> GetEventAsync(string id)
        {
            Event result = null;

            if (!string.IsNullOrEmpty(id))
            {
                try
                {
                    IDocumentSnapshot documentSnapshot = await _firestore.GetCollection(nameof(Event)).GetDocument(id).GetDocumentAsync();

                    if (documentSnapshot.Exists)
                    {
                        result = documentSnapshot.ToObject <Event>();
                    }
                }
                catch (Exception e)
                {
                    result = null;
                    App.LogException(e);
                }
            }

            return(result);
        }
Example #9
0
        public async Task <User> GetUserAsync(string email)
        {
            User result = null;

            if (!string.IsNullOrEmpty(email))
            {
                try
                {
                    IDocumentSnapshot documentSnapshot = await _firestore.GetCollection(nameof(User)).GetDocument(email).GetDocumentAsync();

                    if (documentSnapshot.Exists)
                    {
                        result = documentSnapshot.ToObject <User>();
                    }
                }
                catch (Exception e)
                {
                    result = null;
                    App.LogException(e);
                }
            }

            return(result);
        }