コード例 #1
0
        /// <summary>
        /// Create a listener to receive changes from Firebase
        /// </summary>
        public static void ReceiveChangesFromDB()
        {
            Rootobject RootObject = new Rootobject();

            try
            {
                DocumentReference       docRef   = firestoreDb.Collection(CollectionName).Document(DocumentName);
                FirestoreChangeListener listener = docRef.Listen(snapshot =>
                {
                    Console.WriteLine("Callback received document snapshot.");

                    if (snapshot.Exists)
                    {
                        Console.WriteLine("Document data for {0} document:", snapshot.Id);

                        var st = Newtonsoft.Json.JsonConvert.SerializeObject(snapshot.ToDictionary());
                        VIMManagement.SaveCurrentModel(st);

                        //TODO check this to detect changes
                    }
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error " + ex.Message);
                return;
            }
        }
コード例 #2
0
        /// <summary>
        /// Send a first model to Firestore
        /// </summary>
        /// <param name="model"></param>
        /// <param name="CollectionName"></param>
        /// <param name="ModelName"></param>
        internal static async void SendModelToDB(string model, string CollectionName, string ModelName)
        {
            var models = firestoreDb.Collection(CollectionName).Document(ModelName);
            var obj    = Newtonsoft.Json.JsonConvert.DeserializeObject <Rootobject>(model);

            VIMManagement.SaveCurrentModel(obj);
            await models.SetAsync(obj);
        }