gpt4 book ai didi

azure - 使用 MobileService.GetSyncTable PullAsync 问题

转载 作者:行者123 更新时间:2023-12-03 00:32:05 31 4
gpt4 key购买 nike

我正在尝试使用带有同步功能的 Azure 后端来为我的应用程序工作。但看起来 PullAsync 并未填充我的本地表。

我的表设置如下:

private IMobileServiceSyncTable<Familie> FamilienTable = App.MobileService.GetSyncTable<Familie>(); // offline sync

首先是一些代码。像这样初始化表:

if (!App.MobileService.SyncContext.IsInitialized)
{
var store = new MobileServiceSQLiteStore("localGarden.db");
store.DefineTable<Familie>();
await App.MobileService.SyncContext.InitializeAsync(store);
}

我可以看到该表已创建,并且稍后位于我的本地系统上(也已尝试设置新表)。

稍后在我的代码中这被称为:

 try
{
await FamilienTable.PullAsync(null, FamilienTable.CreateQuery());
}
catch (Exception ex)
{
errorString = "Pull failed: " + ex.Message +
"\n\nIf you are still in an offline scenario, " +
"you can try your Pull again when connected with your Mobile Serice.";
}

if (errorString != null)
{
MessageDialog d = new MessageDialog(errorString);
await d.ShowAsync();
}

我最初是根据 https://azure.microsoft.com/en-us/documentation/articles/mobile-services-xamarin-ios-get-started-offline-data/ 设置的并适配使用Win10 App。这里主要使用Microsoft.Azure.Mobile.Client.SQLitestore 2.0.1。

我知道我需要将 PullAsync 中的 null 替换为字符串,以便将来进行增量更新。

使用 fiddler,我发现在 pullAsync 期间有 2 个对 Azure 上由 Node.js 支持的 API 的调用:[已删除].azurewebsites.net/tables/Familie?$skip=0&$top=50&__includeDeleted=true (返回一个包含表中 6 行的 JSON),之后立即[已删除].azurewebsites.net/tables/Familie?$skip=6&$top=50&__includeDeleted=true 返回空 JSON。

我的本​​地 table 仍然是空的。

有人可以告诉我,如果这种行为是有意为之,请解释一下为什么我会接到 2 个电话,并告诉我在哪里查找本地表未填充的原因?

非常感谢!

<小时/>

其他信息:LoggingHandler 的输出:

CREATE TABLE IF NOT EXISTS [Familie] ([id] INTEGER PRIMARY KEY, [Name] TEXT, [Deleted] BOOLEAN, [Version] DATETIME, [createdAt] DATETIME, [updatedAt] DATETIME)
CREATE TABLE IF NOT EXISTS [__operations] ([id] TEXT PRIMARY KEY, [kind] INTEGER, [state] INTEGER, [tableName] TEXT, [tableKind] INTEGER, [itemId] TEXT, [item] TEXT, [createdAt] DATETIME, [sequence] INTEGER, [version] INTEGER)
CREATE TABLE IF NOT EXISTS [__errors] ([id] TEXT PRIMARY KEY, [httpStatus] INTEGER, [operationVersion] INTEGER, [operationKind] INTEGER, [tableName] TEXT, [tableKind] INTEGER, [item] TEXT, [rawResult] TEXT)
CREATE TABLE IF NOT EXISTS [__config] ([id] TEXT PRIMARY KEY, [value] TEXT)
BEGIN TRANSACTION
INSERT OR IGNORE INTO [__config] ([id]) VALUES (@p0)
The thread 0x2fcc has exited with code 0 (0x0).
UPDATE [__config] SET [value] = @p0 WHERE [id] = @p1
COMMIT TRANSACTION
SELECT * FROM [__operations] ORDER BY [sequence] DESC LIMIT 1
SELECT COUNT(1) AS [count] FROM [__operations]
Pulling changes from remote server
'Gemüsebeetplaner.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Users\Jens\documents\visual studio 14\Projects\Gemüsebeetplaner\Gemüsebeetplaner\bin\x86\Debug\AppX\System.Linq.Queryable.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
SELECT * FROM [__operations] WHERE ([tableName] = @p1) LIMIT 0
SELECT COUNT(1) AS [count] FROM [__operations] WHERE ([tableName] = @p1)
Pulling changes from remote server
SELECT * FROM [__operations] WHERE ([tableName] = @p1) LIMIT 0
SELECT COUNT(1) AS [count] FROM [__operations] WHERE ([tableName] = @p1)
SELECT * FROM [Familie] ORDER BY [Name]
<小时/>

附加信息 2:

**表格截图** Screenshot

这是启用参数的日志:从远程服务器拉取更改

SELECT * FROM [__operations] WHERE ([tableName] = @p1) LIMIT 0
@p1:Familie
SELECT COUNT(1) AS [count] FROM [__operations] WHERE ([tableName] = @p1)
@p1:Familie
{
"count": 0
}
Pulling changes from remote server
SELECT * FROM [__operations] WHERE ([tableName] = @p1) LIMIT 0
@p1:Familie
SELECT COUNT(1) AS [count] FROM [__operations] WHERE ([tableName] = @p1)
@p1:Familie
{
"count": 0
}
SELECT * FROM [Familie] ORDER BY [Name]
The thread 0x24c8 has exited with code 0 (0x0).
The thread 0x1474 has exited with code 0 (0x0).
The thread 0x1a40 has exited with code 0 (0x0).
<小时/>

public class Familie
{
[JsonProperty(PropertyName = "Id")]
public int Id { get; set; }

[JsonProperty(PropertyName = "Name")]
public string Name { get; set; }

}

最佳答案

在进行 Pull 操作时,总会有至少 2 次调用,因为客户端无法知道服务器批量大小。在您的示例中,服务器发送了 6 条记录,因此客户端需要执行另一个查询来查找是否还有更多记录

您的本地表未填充的症状是什么?查询 FamilienTable 时是否得到空结果?

第一次调用是否返回结果?如果是这样,本地数据库的填充方式一定有一些奇怪的地方。尝试将日志记录 SQLite 存储添加到您的应用程序中,这将记录所有本地数据库语句,这是一个示例:https://github.com/Azure-Samples/app-service-mobile-dotnet-todo-list-files/blob/master/src/client/MobileAppsFilesSample/Helpers/LoggingHandler.cs

关于azure - 使用 MobileService.GetSyncTable PullAsync 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35238416/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com