与 Xamarin Forms 和 Azure Easy Tables 同步的问题 [英] Syncing Problems with Xamarin Forms and Azure Easy Tables

查看:13
本文介绍了与 Xamarin Forms 和 Azure Easy Tables 同步的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 Azure 作为后端在 Visual Studio 中开发 Xamarin.Forms 应用程序有一段时间了,但我遇到了一个非常奇怪的问题.

请注意,我正在遵循此

如果没有记录,SDK会发送如下请求拉取记录:

https://{your-mobileapp-name}.azurewebsites.net/tables/TodoItem?$filter=(updatedAt%20ge%20datetimeoffset'1970-01-01T00%3A00%3A00.0000000%2B00%3A00')&$orderby=updatedAt&$skip=0&$top=50&__includeDeleted=true

注意:$filter 将设置为 (updatedAt ge datetimeoffset'1970-01-01T00:00:00.0000000+00:00')

当有记录时,SDK 会选择 value 作为最新的 updatedAt 时间戳并发送如下请求:

https://{your-mobileapp-name}.azurewebsites.net/tables/TodoItem?$filter=(updatedAt%20ge%20datetimeoffset'2017-06-26T02%3A44%3A25.3940000%2B00%3A00')&$orderby=updatedAt&$skip=0&$top=50&__includeDeleted=true

根据我的理解,如果您在不同的移动客户端处理具有相同查询 id(非空)的相同逻辑查询,您需要确保每个客户端都新创建本地数据库.此外,如果您想退出增量同步,请将 null 作为查询 ID 传递.在这种情况下,每次调用 PullAsync 时都会检索所有记录,这可能是低效的.有关更多详细信息,您可以参考 离线同步的工作原理.

此外,您可以利用 fiddler 在调用 PullAsync 时捕获网络跟踪,以便解决您的问题.

I've been working on a Xamarin.Forms application in Visual Studio using Azure for the backend for a while now, and I've come across a really strange issue.

Please note, that I am following the methods mentioned in this blog

For some strange reason the PullAsync() method seems to have some bizarre problems. Any data that I create and sync will only be pulled by PullAsync() from that solution. What I mean by that is that if I create another solution that accesses the exact same backend, it can perform it's own create/sync data, but will not bring over the data generated by the other solution, even though they both seem to have the exact same access. This appears to be some kind of a security feature/issue, but I can't quite make sense of it.

Has anyone else encountered this at all? Was there a work-around at all? This could potentially cause problems down the road if I were to ever want to create another solution that accesses the same system/data for whatever reason.

解决方案

For some strange reason the PullAsync() method seems to have some bizarre problems. Any data that I create and sync will only be pulled by PullAsync() from that solution.

According to your provided tutorial, I found that the related PullAsync is using Incremental Sync.

await coffeeTable.PullAsync("allCoffees", coffeeTable.CreateQuery());

Incremental Sync:

the first parameter to the pull operation is a query name that is used only on the client. If you use a non-null query name, the Azure Mobile SDK performs an incremental sync. Each time a pull operation returns a set of results, the latest updatedAt timestamp from that result set is stored in the SDK local system tables. Subsequent pull operations retrieve only records after that timestamp.

Here is my test, you could refer to it for a better understanding of Incremental Sync:

Client : await todoTable.PullAsync("todoItems-02", todoTable.CreateQuery());

The client SDK would check if there has a record with the id equals deltaToken|{table-name}|{query-id} from the __config table of your SQLite local store.

If there has no record, then the SDK would send a request as following for pulling your records:

https://{your-mobileapp-name}.azurewebsites.net/tables/TodoItem?$filter=(updatedAt%20ge%20datetimeoffset'1970-01-01T00%3A00%3A00.0000000%2B00%3A00')&$orderby=updatedAt&$skip=0&$top=50&__includeDeleted=true

Note: the $filter would be set as (updatedAt ge datetimeoffset'1970-01-01T00:00:00.0000000+00:00')

While there has a record, then the SDK would pick up the value as the latest updatedAt timestamp and send the request as follows:

https://{your-mobileapp-name}.azurewebsites.net/tables/TodoItem?$filter=(updatedAt%20ge%20datetimeoffset'2017-06-26T02%3A44%3A25.3940000%2B00%3A00')&$orderby=updatedAt&$skip=0&$top=50&__includeDeleted=true

Per my understanding, if you handle the same logical query with the same query id (non-null) in different mobile client, you need to make sure the local db is newly created by each client. Also, if you want to opt out of incremental sync, pass null as the query ID. In this case, all records are retrieved on every call to PullAsync, which is potentially inefficient. For more details, you could refer to How offline synchronization works.

Additionally, you could leverage fiddler for capturing the network traces when you invoke the PullAsync, in order to troubleshoot your issue.

这篇关于与 Xamarin Forms 和 Azure Easy Tables 同步的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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