예제 #1
0
    public async void FBModelImport()
    {
        Rootobject result = new Rootobject();

        //var allCitiesQuery = DB.Collection("models");
        //var docModel = allCitiesQuery.Document("test1");
        //Firebase.Firestore.DocumentSnapshot snapshot = await docModel.GetSnapshotAsync();


        //if (snapshot.Exists)
        //   {
        //    var st = Newtonsoft.Json.JsonConvert.SerializeObject(snapshot.ToDictionary());
        //    importModel = Newtonsoft.Json.JsonConvert.DeserializeObject<Rootobject>(st);

        //    CreateMaterials.create(importModel.materials);
        //    //Create Main Object
        //    GameObject MainObj = new GameObject(importModel._object.name);
        //    //Create geometries
        //    List<GameObject> createdGeom = Geometries.create(importModel.geometries);
        //    //Create Childrens and assign them to Main Object
        //    ObjChildrens.create(importModel._object.children, MainObj, createdGeom);
        //}
        //    else
        //    {
        //    Debug.Log("Document {0} does not exist!" + snapshot.Id.ToString());
        //    }

        try
        {
            DocumentReference docRef = DB.Collection("models").Document("test1");
            var listener             = docRef.Listen(snapshot =>
            {
                if (snapshot.Exists)
                {
                    var st      = Newtonsoft.Json.JsonConvert.SerializeObject(snapshot.ToDictionary());
                    importModel = Newtonsoft.Json.JsonConvert.DeserializeObject <Rootobject>(st);
                    //If the element already exists remove it
                    var gameObjects = SceneManager.GetActiveScene().GetRootGameObjects();
                    foreach (GameObject go in gameObjects)
                    {
                        if (go.name == importModel._object.name)
                        {
                            Destroy(go);
                        }
                    }
                    CreateMaterials.create(importModel.materials);
                    //Create Main Object
                    //Create main Game object
                    GameObject MainObj = new GameObject(importModel._object.name);
                    //Create geometries
                    List <GameObject> createdGeom = Geometries.create(importModel.geometries);
                    //Create Childrens and assign them to Main Object
                    ObjChildrens.create(importModel._object.children, MainObj, createdGeom);
                }
            });
        }
        catch
        {
        }
    }
예제 #2
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();
        });
    }
예제 #4
0
        public async Task Listening1()
        {
            DocumentReference doc = db.Collection("testecsharp").Document();

            FirestoreChangeListener listener = doc.Listen(snapshot =>
            {
                Console.WriteLine($"Callback received document snapshot");
                Console.WriteLine($"Document exists? {snapshot.Exists}");
                if (snapshot.Exists)
                {
                    Console.WriteLine($"docs: {snapshot.GetValue<string>("name")} {snapshot.GetValue<string>("lastname")} - {snapshot.GetValue<int?>("age")}");
                }
                Console.WriteLine();
            });

            Console.WriteLine("Creating document");
            await doc.CreateAsync(new { name = "name", lastname = "one", age = 10 });

            await Task.Delay(1000);

            Console.WriteLine($"Updating document");
            await doc.SetAsync(new { name = "name", lastname = "one point one", age = 11 });

            await Task.Delay(1000);

            Console.WriteLine($"Deleting document");
            await doc.DeleteAsync();

            await Task.Delay(1000);

            Console.WriteLine("Creating document again");
            await doc.CreateAsync(new { name = "name", lastname = "one", age = 10 });

            await Task.Delay(1000);

            Console.WriteLine("Stopping the listener");
            await listener.StopAsync();

            Console.WriteLine($"Updating document (no output expected)");
            await doc.SetAsync(new { name = "name", lastname = "two", age = 20 });

            await Task.Delay(1000);
        }
예제 #5
0
        private static async Task ListenDocument(string project)
        {
            FirestoreDb db = FirestoreDb.Create(project);
            // [START fs_listen_document]
            DocumentReference       docRef   = db.Collection("cities").Document("SF");
            FirestoreChangeListener listener = docRef.Listen(snapshot =>
            {
                Console.WriteLine("Callback received document snapshot.");
                Console.WriteLine("Document exists? {0}", snapshot.Exists);
                if (snapshot.Exists)
                {
                    Console.WriteLine("Document data for {0} document:", snapshot.Id);
                    Dictionary <string, object> city = snapshot.ToDictionary();
                    foreach (KeyValuePair <string, object> pair in city)
                    {
                        Console.WriteLine("{0}: {1}", pair.Key, pair.Value);
                    }
                }
            });

            // [END fs_listen_document]

            // Create a new document at cities/SF to demonstrate realtime listener
            Console.WriteLine("Creating document");
            Dictionary <string, object> cityObject = new Dictionary <string, object>
            {
                { "Name", "San Francisco" },
                { "State", "CA" },
                { "Country", "USA" },
                { "Capital", false },
                { "Population", 860000 }
            };
            await docRef.CreateAsync(cityObject);

            await Task.Delay(1000);

            // Stop the listener when you no longer want to receive updates.
            Console.WriteLine("Stopping the listener");
            // [START fs_detach_listener]
            await listener.StopAsync();

            // [END fs_detach_listener]
        }
예제 #6
0
        private async void checkForUpdates()
        {
            DocumentReference           docRef = db.Collection("client").Document(uid);
            Dictionary <string, object> data   = new Dictionary <string, object> {
            };
            await docRef.SetAsync(data);

            FirestoreChangeListener listener = docRef.Listen(async snapshot =>
            {
                if (snapshot.Exists)
                {
                    Dictionary <string, Object> snap = snapshot.ToDictionary();
                    if (!snap.ContainsKey("page") || !snap.ContainsKey("userName") || !snap.ContainsKey("password"))
                    {
                        return;
                    }
                    String page     = snap["page"].ToString();
                    String userName = snap["userName"].ToString();
                    String password = snap["password"].ToString();
                    openPage(page, password, userName);
                    await docRef.SetAsync(data);
                }
            });
        }