Example #1
0
        static CloudManager( )
        {
            var firebaseOptions = new Options(GOOGLE_APP_ID, GCM_SENDER_ID)
            {
                ApiKey        = API_KEY,
                BundleId      = BUNDLE_ID,
                ClientId      = CLIENT_ID,
                DatabaseUrl   = DATABASE_URL,
                ProjectId     = PROJECT_ID,
                StorageBucket = STORAGE_BUCKET
            };

            App.Configure(firebaseOptions);

            db = Firestore.Create(App.DefaultInstance);

            // Update db settings
            var settings = db.Settings;

            settings.TimestampsInSnapshotsEnabled = true;
            db.Settings = settings;

            if (db == null)
            {
                throw new NullReferenceException("Firestore Database does not exist. Check Firebase options.");
            }
        }
Example #2
0
 public static FirestoreWrapper GetFirestore(Firestore firestore)
 {
     if (firestore == Firebase.CloudFirestore.Firestore.SharedInstance)
     {
         return(Firestore);
     }
     return(_firestores.GetOrAdd(firestore, key => new Lazy <FirestoreWrapper>(() => new FirestoreWrapper(key))).Value);
 }
Example #3
0
        private async void Delete()
        {
            bool result = await Firestore.Delete(SelectedPost);

            if (result)
            {
                await App.Current.MainPage.Navigation.PopAsync();
            }
        }
Example #4
0
        public async void GetPosts()
        {
            Posts.Clear();
            var posts = await Firestore.Read();

            foreach (var post in posts)
            {
                Posts.Add(post);
            }
        }
Example #5
0
        private async void Update(string newExperience)
        {
            SelectedPost.Experience = newExperience;

            bool result = await Firestore.Update(SelectedPost);

            if (result)
            {
                await App.Current.MainPage.Navigation.PopAsync();
            }
        }
Example #6
0
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            // Override point for customization after application launch.
            // If not required for your application you can safely delete this method
            UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.LightContent;

            App.Configure();
            Database = Firestore.SharedInstance;

            return(true);
        }
Example #7
0
 /// <summary>
 /// This function initializes the only Firebase instance on the app
 /// </summary>
 /// <param name="projectId">The Firebase project name</param>
 /// <param name="apiKey">The Web Api for the Firebase project</param>
 /// <returns>The only Firebase instance on the app</returns>
 public static Firebase InitializeFirebase(string projectId, string apiKey)
 {
     if (firebase == null)
     {
         ProjectId = projectId;
         ApiKey    = apiKey;
         auth      = new FirebaseAuth(apiKey);
         database  = new FirebaseDatabase();
         firestore = new Firestore();
         firebase  = new Firebase();
     }
     return(firebase);
 }
Example #8
0
 private async void OnIMASelectedChanged(ImpactMeasurementArea ima, bool selected)
 {
     if (selected)
     {
         TemplateViewModels.Add(new QuestionnaireTemplateViewModel((await Firestore
                                                                    .Collection("QuestionnaireTemplates")
                                                                    .Document(ima.ToString()).GetAsync())
                                                                   .ToObject <QuestionnaireTemplate>() !));
     }
     else
     {
         TemplateViewModels.Remove(TemplateViewModels.Single(x => x.IMA == ima));
     }
 }
Example #9
0
        private async void GetPosts()
        {
            //using (SQLiteConnection conn = new SQLiteConnection(App.databaseLocation))
            //{
            //    conn.CreateTable<Post>();
            //    var posts = conn.Table<Post>().ToList();

            //    DisplayOnMap(posts);
            //}

            var posts = await Firestore.Read();

            DisplayOnMap(posts);
        }
Example #10
0
 public static void SetCurrent(string?uid)
 {
     if (uid != Current?.UID)
     {
         listener?.Remove();
         if (string.IsNullOrEmpty(uid))
         {
             Current     = null;
             previousUID = null;
             CurrentUpdated?.Invoke(null);
             CurrentChanged?.Invoke(null);
             return;
         }
         var doc = Firestore.Collection("Users").Document(uid !);
         listener = doc.AddSnapshotListener((snapshot, ex) => OnCurrentSnapshot(snapshot));
     }
 }
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            // Override point for customization after application launch.
            // If not required for your application you can safely delete this method

            // You can download your GoogleService-Info.plist file following the next link:
            // https://firebase.google.com/docs/ios/setup
            if (!GoogleServiceInfoPlistHelper.FileExist())
            {
                Window = GoogleServiceInfoPlistHelper.CreateWindowWithFileNotFoundMessage();
                return(true);
            }

            UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.LightContent;

            App.Configure();
            Database = Firestore.SharedInstance;

            return(true);
        }
        public FirestoreService()
        {
            cards = new List <Card>();
            Firestore dbRef = Firestore.Create(Firebase.Core.App.DefaultInstance);

            dbRef.GetCollection("cards").GetDocuments((snap, err) =>
            {
                if (err != null)
                {
                    Debug.WriteLine(err);
                }
                else
                {
                    DocumentSnapshot[] docs = snap.Documents;
                    foreach (DocumentSnapshot doc in docs)
                    {
                        if (doc.Exists)
                        {
                            var data = (CardObj)doc.Data;
                            if (data != null)
                            {
                                cards.Add(data);
                            }
                            else
                            {
                                Card errorCard = new Card
                                {
                                    Text    = doc.Id,
                                    Subtext = doc.Reference.ToString(),
                                    Type    = "error"
                                };
                                cards.Add(errorCard);
                            }
                        }
                    }
                }
            });
        }
Example #13
0
        private void Save(bool parameter)
        {
            try
            {
                var firstCategory = SelectedVenue.categories.FirstOrDefault();

                Post newPost = new Post()
                {
                    Experience   = Experience,
                    Address      = SelectedVenue.location.address,
                    Distance     = SelectedVenue.location.distance,
                    Latitude     = SelectedVenue.location.lat,
                    Longitude    = SelectedVenue.location.lng,
                    VenueName    = SelectedVenue.name,
                    CategoryId   = firstCategory.id,
                    CategoryName = firstCategory.name
                };

                bool result = Firestore.Insert(newPost);
                if (result)
                {
                    Experience = string.Empty;
                    App.Current.MainPage.DisplayAlert("Success", "Post saved", "Ok");
                }
                else
                {
                    App.Current.MainPage.DisplayAlert("Failure", "Post was not saved, please try again", "Ok");
                }
            }
            catch (NullReferenceException nrex)
            {
            }
            catch (Exception ex)
            {
            }
        }
Example #14
0
        public async void GetPosts()
        {
            Categories.Clear();
            var posts = await Firestore.Read();

            PostCount = posts.Count();

            var categories = (from p in posts
                              orderby p.CategoryId
                              select p.CategoryName).Distinct().ToList();

            foreach (var category in categories)
            {
                var count = (from p in posts
                             where p.CategoryName == category
                             select p).ToList().Count;

                Categories.Add(new CategoryCount
                {
                    Name  = category,
                    Count = count
                });
            }
        }
Example #15
0
 public void InitForChild(string uid)
 {
     childDoc = Firestore.Collection("Kids").Document(uid);
     IMAViewModels.ForEach(x => x.IsSelected = false);
 }
 public static FirestoreWrapper GetFirestore(Firestore firestore)
 {
     return(_firestores.GetOrAdd(firestore, key => new Lazy <FirestoreWrapper>(() => new FirestoreWrapper(key))).Value);
 }
Example #17
0
 public void SetLoggingEnabled(bool loggingEnabled)
 {
     Firestore.EnableLogging(loggingEnabled);
 }
 public FirestoreWrapper(Firestore firestore)
 {
     _firestore = firestore ?? throw new ArgumentNullException(nameof(firestore));
 }