Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
191 views
in Technique[技术] by (71.8m points)

android - Azure App Service - Offline Sync - PullAsync Transaction

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.

Edit:

To make it easier to understand: Let's assume i have a table "ToDoItem" and "ToDoCategory". The user starts a data sync. The data sync runs and the all ToDoItems are successfully retrieved . In the next step the data sync will get the ToDoCategories (another call to PullAsync) but before this the user closes the app. Now i have all ToDoItems but no ToDoCategories. But the App is not useable with no ToDoCategories. This is a really simple example. The data structure is much more complex in the real project. There are a lot of dependencies between the entities.

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.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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.

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?

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...