Azure应用服务-脱机同步-PullAsync事务 [英] Azure App Service - Offline Sync - PullAsync Transaction

查看:77
本文介绍了Azure应用服务-脱机同步-PullAsync事务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用Xamarin.Forms和Azure App Service的应用程序. 用户必须明确执行数据同步.当用户开始数据同步时,将执行许多此方法以从服务器获取当前数据:

I'm working on an App wich uses Xamarin.Forms and Azure App Service. The user must explicitly execute a data sync. When the user starts a data sync a lot of this methods are executed to get the current data from the server:

 await this.ISyncTable.PullAsync(queryId, query, cancellationToken).ConfigureAwait(false);

我的问题:应用程序可能会进入不一致状态.例如,当用户在数据同步完成之前关闭应用程序时.在这种状态下,该应用程序无法使用.

My problem: The application can get into an inconsistent state. For example when the user closes the App before the data sync is completed. In this state the App is not usable.

为了使其易于理解:假设我有一个表"ToDoItem"和"ToDoCategory".用户开始数据同步.数据同步运行,并且所有ToDoItems均已成功检索.在下一步中,数据同步将获取ToDoCategories(另一个对PullAsync的调用),但在此之前,用户关闭了应用程序.现在我有所有ToDoItems,但没有ToDoCategories.但是,如果没有ToDoCategories,该应用程序将无法使用.这是一个非常简单的例子.在实际项目中,数据结构要复杂得多.实体之间存在很多依赖关系.

这不是解决同步错误/取消并在下一个应用程序启动时提示用户进行另一次同步的解决方案.假设在下一个应用程序启动时,用户没有互联网连接,并且无法执行数据同步.我无法在下一次成功同步数据时锁定应用单元.

是否可以在一个事务中运行多个PullAsync操作?

Is there a way to run multiple PullAsync operations in a transaction?

推荐答案

是否可以在一个事务中运行多个PullAsync操作?

Is there a way to run multiple PullAsync operations in a transaction?

简短的回答是没有,没有.在所有PullAsync操作完成后设置一个标记,或者跟踪哪些表已成功同步.

Short answer is no, there isn't. Set a flag in when all your PullAsync operations are complete, or keep track of which tables have synced successfully.

记录同步错误/取消并在下一个应用程序启动时提示用户进行另一次同步,这不是解决方案.假设在下一个应用程序启动时,用户没有互联网连接,并且无法执行数据同步.我无法在下次成功进行数据同步时锁定应用程序unitl.

It is no solution to log the sync error / cancellation and prompt the user at the next app start for another sync. Assume on the next app start the user has no internet connection and cannot perform a data sync. I cannot lock the app unitl the next successful data sync.

如果用户启动了同步但在同步完成之前离开了应用程序,则第二次运行时您的应用程序的预期行为是什么?完成同步?提示用户重新开始?

What is your app's expected behavior on the second run if the user started the sync but then left the app before sync completed? Finish the sync? Prompt the user to start again?

还应考虑在用户离开后该应用程序可能会继续在后台同步.在iOS中,您必须使用UIApplication beginBackgroundTaskWithExpirationHandler与操作系统进行协调.

Also consider the app could probably continue syncing in the background after the user has left. In iOS you have to coordinate with the operating system using UIApplication beginBackgroundTaskWithExpirationHandler.

这篇关于Azure应用服务-脱机同步-PullAsync事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆