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.");
            }
        }
        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);
                            }
                        }
                    }
                }
            });
        }