public void RegisterForChatUpdates(string gameId, Action <ChatState> callback)
 {
     Debug.Log("Registering for Chat " + gameId);
     _chatUpdateListener = db.Collection("chats").Document(gameId).Listen(snapshot => {
         callback(snapshot.ConvertTo <ChatState>());
     });
 }
 public void RegisterForGameUpdates(string gameId, Action <GameState> callback)
 {
     Debug.Log("Registering for Game " + gameId);
     _gameUpdateListener = db.Collection("games").Document(gameId).Listen(snapshot => {
         callback(snapshot.ConvertTo <GameState>());
     });
 }
Esempio n. 3
0
    // Start is called before the first frame update
    void Start()
    {
        jugador = FindObjectOfType <puntuacionFinal>();
        score   = jugador.puntos;
        puntosJugador.GetComponent <TextMeshProUGUI>().text = $" {score} puntos";
        textRepe.SetActive(false);



        db = FirebaseFirestore.GetInstance(FirebaseApp.Create());
        CollectionReference jugadoresRef = db.Collection("jugadores");
        Query query = jugadoresRef.OrderByDescending("puntos").Limit(5);
        ListenerRegistration listener = query.Listen(snapshot =>
        {
            string top5 = "TOP 5 \n\n";
            var cont    = 1;
            foreach (DocumentSnapshot documentSnapshot in snapshot.Documents)
            {
                Dictionary <string, object> jugador = documentSnapshot.ToDictionary();
                top5 += $"{cont}-{documentSnapshot.Id}..........{jugador["puntos"]}\n";
                cont += 1;
                nicks.Add(documentSnapshot.Id.ToString());
            }
            marcador.GetComponent <TextMeshProUGUI>().text = top5;
        });
    }
        public async Task After_Recycling_Then_Events_Can_Still_Be_Processed_Correctly()
        {
            // arrange
            var parser = new RuntimeEventParser()
            {
                RefreshIntervalSeconds = 1
            };
            var eventAssertion = TestHelpers.ArrangeEventAssertion <IncrementingCounterValue>(e => parser.ExceptionCount += e);
            var services       = new ServiceCollection();
            var parserRego     = ListenerRegistration.Create(CaptureLevel.Counters, _ => parser);

            parserRego.RegisterServices(services);
            services.AddSingleton <ISet <ListenerRegistration>, HashSet <ListenerRegistration> >(_ => new[] { parserRego }.ToHashSet());

            // act
            using var l = new DotNetRuntimeStatsCollector(services.BuildServiceProvider(), new CollectorRegistry(), new DotNetRuntimeStatsCollector.Options()
            {
                RecycleListenersEvery = TimeSpan.FromSeconds(3)
            });
            Assert.That(() => eventAssertion.Fired, Is.True.After(2000, 10));
            await Task.Delay(TimeSpan.FromSeconds(10));

            // Why do we expected this value of events? Although we are waiting for 10 seconds for events, recycles may cause a counter period
            // to not fire. As counter events fire each second, as long as this value is greater than the recycle period this test can veryify
            // recycling is working correctly.
            const int expectedCounterEvents = 6;

            Assert.That(eventAssertion.History.Count, Is.GreaterThanOrEqualTo(expectedCounterEvents));
            Assert.That(l.EventListenerRecycles.Value, Is.InRange(3, 5));
        }
Esempio n. 5
0
        public IEnumerator DocumentReference_TasksFailProperly()
        {
            var docWithInvalidName = TestCollection().Document("__badpath__");
            var fieldPathData      = new Dictionary <FieldPath, object> {
                { new FieldPath("key"), 42 }
            };

            {
                Task task = docWithInvalidName.DeleteAsync();
                yield return(AwaitCompletion(task));

                AssertTaskFaulted(task, FirestoreError.InvalidArgument);
            }
            {
                Task task = docWithInvalidName.UpdateAsync(TestData(0));
                yield return(AwaitCompletion(task));

                AssertTaskFaulted(task, FirestoreError.InvalidArgument);
            }
            {
                Task task = docWithInvalidName.UpdateAsync("fieldName", 42);
                yield return(AwaitCompletion(task));

                AssertTaskFaulted(task, FirestoreError.InvalidArgument);
            }
            {
                Task task = docWithInvalidName.UpdateAsync(fieldPathData);
                yield return(AwaitCompletion(task));

                AssertTaskFaulted(task, FirestoreError.InvalidArgument);
            }
            {
                Task task = docWithInvalidName.SetAsync(TestData(), SetOptions.MergeAll);
                yield return(AwaitCompletion(task));

                AssertTaskFaulted(task, FirestoreError.InvalidArgument);
            }
            {
                Task <DocumentSnapshot> task = docWithInvalidName.GetSnapshotAsync();
                yield return(AwaitCompletion(task));

                AssertTaskFaulted(task, FirestoreError.InvalidArgument);
            }
            {
                Task <DocumentSnapshot> task = docWithInvalidName.GetSnapshotAsync(Source.Default);
                yield return(AwaitCompletion(task));

                AssertTaskFaulted(task, FirestoreError.InvalidArgument);
            }
            {
                ListenerRegistration listenerRegistration = docWithInvalidName.Listen(snap => {});
                yield return(AwaitCompletion(listenerRegistration.ListenerTask));

                AssertTaskFaulted(listenerRegistration.ListenerTask, FirestoreError.InvalidArgument);
                listenerRegistration.Stop();
            }
        }
Esempio n. 6
0
 private void CreateSut(IKernel kernel = null, IProcessManagerListener[] listener = null)
 {
     _kernel       = kernel ?? Substitute.For <IKernel>();
     _fakeBus      = Substitute.For <IBus>();
     _registration = new ListenerRegistration(
         listener ?? new IProcessManagerListener[] { new SampleListener() },
         _fakeBus,
         _kernel
         );
 }
Esempio n. 7
0
    public void ListenMatch(string matchId)
    {
        DocumentReference docRef = Match.collectionRef.Document(matchId);

        listener = docRef.Listen(snapshot =>
        {
            Debug.Log("Match updated");
            Match newMatch = new Match(snapshot);
            OnMatchUpdated?.Invoke(newMatch);
        });
    }
    //Grab data by document name
    void Grab2()
    {
        // Enter in Your Collection's name
        DocumentReference docRef = db.Collection("YourCollectionName").Document("YourDocument");

        ListenerRegistration listener = docRef.Listen(snapshot =>
        {
            Debug.Log(snapshot.Id);

            Dictionary <string, object> data = snapshot.ToDictionary();
            Text_Example2.text = data["Document_Field_Name"].ToString();
        });
    }
Esempio n. 9
0
    public void ListenMatches()
    {
        string userId = FirebaseAuth.DefaultInstance.CurrentUser.UserId;

        Query query = Match.collectionRef.WhereEqualTo(userId, true).WhereEqualTo(Constants.IS_ACTIVE, true);

        listener = query.Listen(snapshot =>
        {
            Debug.Log("Matches updated");
            List <Match> matches = new List <Match>();
            foreach (DocumentSnapshot documentSnapshot in snapshot.Documents)
            {
                Match match = new Match(documentSnapshot);
                matches.Add(match);
            }
            OnMatchesUpdated?.Invoke(matches);
        });
    }
Esempio n. 10
0
    void Start()
    {
        // Conexión a Firestore
        db = FirebaseFirestore.DefaultInstance;

        botonIzquierda = GameObject.Find("BotonIzquierda");
        botonDerecha   = GameObject.Find("BotonDerecha");
        marcador       = GameObject.Find("Marcador");

        izquierda = random.Next(imagenes.Length);
        nuevaImagen(botonIzquierda, izquierda);
        derecha = random.Next(imagenes.Length);
        nuevaImagen(botonDerecha, derecha);

        // Crear los documentos vacíos
        foreach (var nombre in nombres)
        {
            DocumentReference docRef = db.Collection("animals").Document(nombre.ToLower());

            var datos = new Dictionary <string, object>
            {
            };

            docRef.SetAsync(datos, SetOptions.MergeAll);
        }

        // Observar una colección
        CollectionReference animalsRef = db.Collection("animals");
        Query query = animalsRef.Limit(10).OrderByDescending("count");

        ListenerRegistration listener = query.Listen(snapshot =>
        {
            String top10 = "Top 10\n\n";

            foreach (DocumentSnapshot documentSnapshot in snapshot.Documents)
            {
                Dictionary <string, object> animal = documentSnapshot.ToDictionary();
                top10 += $"{documentSnapshot.Id} ({animal["count"]})\n";
            }

            marcador.GetComponent <TMP_Text>().text = top10;
        });
    }
    //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());
            }
            ;
        });
    }
Esempio n. 12
0
        public IEnumerator CollectionReference_TasksFailProperly()
        {
            var collectionWithInvalidName = TestCollection().Document("__badpath__").Collection("sub");
            {
                Task <QuerySnapshot> task = collectionWithInvalidName.GetSnapshotAsync();
                yield return(AwaitCompletion(task));

                AssertTaskFaulted(task, FirestoreError.InvalidArgument, "__badpath__");
            }
            {
                Task <QuerySnapshot> task = collectionWithInvalidName.GetSnapshotAsync(Source.Default);
                yield return(AwaitCompletion(task));

                AssertTaskFaulted(task, FirestoreError.InvalidArgument, "__badpath__");
            }
            {
                Task <DocumentReference> task = collectionWithInvalidName.AddAsync(TestData(0));
                yield return(AwaitCompletion(task));

                AssertTaskFaulted(task, FirestoreError.InvalidArgument);
            }
            {
                ListenerRegistration listenerRegistration = collectionWithInvalidName.Listen(snap => {});
                yield return(AwaitCompletion(listenerRegistration.ListenerTask));

                AssertTaskFaulted(listenerRegistration.ListenerTask, FirestoreError.InvalidArgument,
                                  "__badpath__");
                listenerRegistration.Stop();
            }
            {
                ListenerRegistration listenerRegistration =
                    collectionWithInvalidName.Listen(MetadataChanges.Include, snap => {});
                yield return(AwaitCompletion(listenerRegistration.ListenerTask));

                AssertTaskFaulted(listenerRegistration.ListenerTask, FirestoreError.InvalidArgument,
                                  "__badpath__");
                listenerRegistration.Stop();
            }
        }
Esempio n. 13
0
    void Start()
    {
        // Conectamos con la base de datos
        try
        {
            db = FirebaseFirestore.GetInstance(FirebaseApp.Create()); // Se cierra también :/
        }
        catch
        {
            db = FirebaseFirestore.GetInstance(FirebaseApp.DefaultInstance); //<- Bug!
        }

        // Creamos una referencia a una colección (es decir, a una """tabla""" para luego trabajar con los datos)
        CollectionReference puntuaciones = db.Collection("puntuaciones");

        // Preparamos la Query
        Query query = puntuaciones.OrderByDescending("puntos").Limit(30);

        // Creamos un listener con la Query, es decir, recogemos los datos pero no solo eso
        // sino que también, este listener se ejecutará cada vez que haya un cambio en la BBDD
        ListenerRegistration listener = query.Listen(snapshot =>
        {
            List <Puntuacion> cargandoPuntuaciones = new List <Puntuacion>();
            //Guardo continuamente los jugadores en una lista para enseñarla cuando muestre la tabla de puntuaciones
            foreach (DocumentSnapshot documentSnapshot in snapshot.Documents)
            {
                Dictionary <string, object> punt = documentSnapshot.ToDictionary();
                Puntuacion puntuacion            = new Puntuacion();
                puntuacion.nombre = $"{punt["nombre"]}";
                string puntosStr  = $"{punt["puntos"]}";
                puntuacion.puntos = int.Parse(puntosStr);
                cargandoPuntuaciones.Add(puntuacion);
            }
            listaPuntuaciones = cargandoPuntuaciones;
        });
    }