c# - Firebase 跨平台问题 - .setAsync() 设置在 2 个路径目标中,而不仅仅是一个
问题描述
我在 c# winforms 中为我的应用程序使用 Firesharp。这个数据库也连接到我的 ReactJS 网站,它处理相同的信息。
我注意到,当我.SetAsync
在网站上调用我的应用程序然后登录到我的 Winforms 应用程序时,我的 WinForms 应用程序将自动执行我在网站上执行的最后一个操作到我的数据库,这是一个.setAsync()
将一些用户信息添加到其他用户信息的列表。现在它不会停止。每当我登录到我的 c# 应用程序时,它都会运行它。
这让我觉得firesharp中有一个订单队列?
这是我的反应代码。据我所知,这并没有什么特别之处:
async function handleSubmit(e) {
e.preventDefault()
var date = moment().format("MM/DD/YYYY" )
setError("")
setLoading(true)
// grab user info first then use that.
await firebaseApp.database().ref("Users/" + currentUser.uid + "/UserData").on('value', snapshot => {
if (snapshot.val() != null) {
setContactObjects({
...snapshot.val()
})
firebaseApp.database().ref("Projects/" + projectGUIDRef.current.value + "/queueList/" + userIdRef.current.value).set({
"EntryTimeStamp": date + " " + moment().format("hh:mm:ss a"),
"IsSyncing": false,
"UserId": userIdRef.current.value,
"UserName": usernameRef.current.value,
})
}
})
history.push("/Demo")
setLoading(false)
}
这是我的代码执行位置的 c# winforms 代码。由于某种原因,当它执行时,它也会更新EntryTimeStamp
反应代码的字段并完全设置所有信息,即使我删除它也是如此。如果我跑步也会发生这种情况.set()
。
updateLastLogin2(authLink);
private async void updateLastLogin2(FirebaseAuthLink authLink)
{
IFirebaseConfig config = new FireSharp.Config.FirebaseConfig
{
AuthSecret = this.authLink.FirebaseToken,
BasePath = Command.dbURL,
};
IFirebaseClient client = new FireSharp.FirebaseClient(config);
string newDateTime = DateTime.Now.ToString();
if (authLink.User.DisplayName.Contains(adUserId) && authLink.User.DisplayName.Contains(adUserId))
{
await client.SetAsync("Users/" + this.authLink.User.LocalId + "/UserData/DateLastLogin", newDateTime);
}
}
感谢任何和所有的帮助,我已经在这里待了一天半了。
解决方案
我从来没有使用过火锐,但这是我的猜测
您正在调用await firebaseApp.database().ref("Users/" + currentUser.uid + "/UserData").on('value'
您的反应,然后在您的 Csharp 中您正在调用client.SetAsync("Users/" + this.authLink.User.LocalId
.
发生的情况是两个侦听器都在互相侦听,然后导致循环。
在这种情况下,最好使用它once
而不是on
只使用一次。
如果您无法使用.once
,那么您应该.off
在完成后使用 关闭监听器。
firebaseApp.database().ref("Users/" + currentUser.uid + "/UserData").once('value'`
你也不应该在await
这里使用,因为ref().on
创建了一个监听器,它不会返回一个承诺。
您还应该history.push("/Demo")
进入您的 firebase 数据库回调函数,以便在设置数据后调用它
推荐阅读
- java - 由 Java AES 加密的字符串,在 Python 问题中解密
- file - java.io.File 的 .createNewFile() 不会创建文件
- python - OpenCV:跟踪扩展矩形的坐标
- ios - 颤动的iOS功能背景模式已打开
- javascript - 如何在 Angular 5 规范中为 document.URL 编写单元测试
- python - 在 Django 应用程序中显示特定用户详细信息而不是所有详细信息
- ios - Xcode for Swift 4 中的屏幕时间报告
- c - 从 ARP 数据包打印源和目标 IP 地址
- raku - Perl 6:使用 AT-POS 的可写多维下标访问
- text - 使用记事本删除/或替换为空格->所有字符串以及其中的内容