Exemplo n.º 1
0
    /**
     * Function that
     *  1. Hashes the downloaded map data
     *  2. Checks to see if the map has a current high score
     *
     *
     */
    public void CheckForHighScore()
    {
        FirebaseFirestore   db     = FirebaseFirestore.DefaultInstance;
        CollectionReference colRef = db.Collection("Maps");

        // Get hash value for map data
        SHA256Managed hash = new SHA256Managed();

        byte[] result    = hash.ComputeHash(heightData);
        string hashValue = "";

        foreach (byte b in result)
        {
            hashValue += b.ToString("x2");
        }
        map_hash_value = hashValue;

        //query the db to see if the map exists
        Firebase.Firestore.Query query = colRef.WhereEqualTo("hash", hashValue);
        query.GetSnapshotAsync().ContinueWithOnMainThread((querySnapshotTask) =>
        {
            foreach (DocumentSnapshot docSnap in querySnapshotTask.Result.Documents)
            {
                Dictionary <string, object> mapObj = docSnap.ToDictionary();
                var mapScore = mapObj["score"];
                double mapScoreD;
                double.TryParse(mapScore.ToString(), out mapScoreD);
                mapHighScore = mapScoreD;
            }
        });
    }
    //Grab all data or set query on which data you grab
    void Grab()
    {
        // Enter in Your Collection's name
        Firebase.Firestore.Query query = db.Collection("YourCollectionName");

        //Firebase.Firestore.Query query = db.Collection("YourCollectionName").WhereEqualTo("isBlue", true);;

        ListenerRegistration listener = query.Listen(snapshot =>
        {
            foreach (DocumentSnapshot documentSnapshot in snapshot.Documents)
            {
                Debug.Log(documentSnapshot.Id);

                Dictionary <string, object> data = documentSnapshot.ToDictionary();
                Text_Example.Add(data["Document_Field_Name"].ToString());
            }
            ;
        });
    }