我可以使用Cloud Firestore进行Google Smart Home Action开发吗?

问题描述 投票:0回答:1

我正在开发在C#控制台应用程序上运行的IoT设备,但我确实找不到合适的方法来使我的网关(连接到我的IoT设备的集线器)监听Firebase实时数据库数据更改。由于没有适用于C#的Firebase的事件侦听器,因此我不愿意尝试所有方法。但是在Firestore中,有C#支持的文档,但是我不清楚如何做到这一点。我已经使用给定的washer项目完成了Codelabs,但它已部署在实时数据库中。请帮助。

firebase google-cloud-firestore google-assistant-sdk google-smart-home
1个回答
0
投票
Get realtime updates with Cloud Firestore Documentation上,您必须使用C#中的onSnapshot()docRef.Listen(snapshot => {})来侦听实时更新,还有一个代码段,其中包含以下C#示例:

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); } } });

您可以检查同一文档,以收听多个文档更新和其他一些功能。

请注意,Cloud Firestore的C#库当前不支持几个功能,它们是:

    聆听本地更改;
  • 收听元数据更改。
  • 因此,您的应用必须对它们进行不同的处理。
  • © www.soinside.com 2019 - 2024. All rights reserved.