Exemplo n.º 1
0
        private async void GetFirebaseData()
        {
            CollectionReference collectionReference = db.Collection("Product");
            QuerySnapshot       snapshots           = await collectionReference.OrderBy("Name").GetSnapshotAsync();

            //List<DocumentSnapshot> documents = snapshots.ToList();
            List <ProductRecord> products = new List <ProductRecord>();

            foreach (DocumentSnapshot document in snapshots.ToList())
            {
                ProductRecord p = new ProductRecord()
                {
                    Id        = document.Id,
                    Name      = document.GetValue <String>("Name"),
                    Detail    = document.GetValue <String>("Detail"),
                    PathImage = document.GetValue <String>("PathImage"),
                    Image     = document.GetValue <String>("Image")
                };

                products.Add(p);
            }


            // mapping list to datagridview datasource
            dgv.DataSource = products;

            // decorated columns
            //dgv.Columns["PathImage"].Visible = false;

            UpdateUI();
        }
    /// <summary>
    /// Function to be registered as an event when the bird dies, crashing into obstacles or ground.
    /// The event is registered in Bird script.
    /// </summary>
    public void BirdDied()
    {
        gameOver = true;

        //Retrieve the collection named 'High Score Collection' from our database in the Firebase Cloud
        CollectionReference HighScoreCollection = db.Collection("High Score Collection");

        HighScore = 0;

        //Retrieve the results from the cloud
        HighScoreCollection.GetSnapshotAsync().ContinueWithOnMainThread(task =>
        {
            QuerySnapshot snapshot = task.Result;
            //Convert the queury's result from the server to List for convenience
            List <DocumentSnapshot> ListOfDocs = snapshot.ToList();

            //Since there is only one Document in the the collection, 'High Score Document'
            Dictionary <string, object> documentDictionary = ListOfDocs[0].ToDictionary();

            //Check for the field containing our high score
            if (documentDictionary.ContainsKey("High Score"))
            {
                if (int.TryParse(documentDictionary["High Score"].ToString(), out HighScore))
                {
                    //if the current score of the user is higher than the already registered high score, then update it on the cloud
                    if (score > HighScore)
                    {
                        SetHighScore(score);
                    }

                    else
                    {
                        SetPageState(UserInterfaceState.GameOver);
                    }
                }
            }
        });
    }