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