我在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代码,说明代码的执行位置。出于某种原因,当执行此操作时,它还会更新react代码的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);
}
}
感谢所有的帮助,我已经做了一天半了。
我从未使用过火锐,但这是我的猜测
您在react中调用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
创建了一个监听器,它不会返回promise。
您还应该将history.push("/Demo")
移动到您的firebase数据库回调函数中,以便在设置数据后调用它