我试图从James Montemagno重现“Azure移动应用程序的简易表入门”文章。不过,我想进行一些更改和/或添加,以便结果符合我个人的兴趣。一切工作正常,除了一个问题:Xamarin Forms和Azure移动应用程序:来自PullAsync的CancelledBySyncStoreError异常
PullAsync(从IMobileServiceSyncTable)抛出CancelledBySyncStoreError例外!
(我执行Xamarin窗体应用程序作为Android应用 - 目标decice是一个的Nexus 7与Android版5.1.1)是
详情如下:
在天青门户I”已经安装了一个简易表。该架构如下:
Azure Schema Definition of Easy Table
门户中的表似乎是正确建立,因为我可以集成在Visual Studio(2013年)服务器资源管理器的远程表。如从Visual Studio看出架构详情如下:
Table Schema as seen by Visual Studio
或者:
CREATE TABLE [dbo].[FirstHighScores] (
[id] NVARCHAR (255) CONSTRAINT [DF_FirstHighScores_id] DEFAULT (CONVERT([nvarchar](255),newid(),(0))) NOT NULL,
[createdAt] DATETIMEOFFSET (3) CONSTRAINT [DF_FirstHighScores_createdAt] DEFAULT (CONVERT([datetimeoffset](3),sysutcdatetime(),(0))) NOT NULL,
[updatedAt] DATETIMEOFFSET (3) NULL,
[version] ROWVERSION NOT NULL,
[deleted] BIT DEFAULT ((0)) NULL,
[Name] NVARCHAR (MAX) NULL,
[Score] FLOAT (53) NULL,
[PlayedAt] DATETIMEOFFSET (3) NULL,
PRIMARY KEY NONCLUSTERED ([id] ASC)
);
正如你所看到的,我在手动门户加入三列:名称, 得分和玩过。 相应的SQL数据类型是字符串,号码和日期。 所有其余的模式条目已由Azure门户方案设计器自动生成。
下一页关于我Xamarin一些相关信息窗体应用程序:
模型类我Azure的简易表如下所示 (Azure的表名和C#类的名称是相同的()!):
namespace AzureHighScoresFirstApp
{
public class FirstHighScores
{
[Newtonsoft.Json.JsonProperty("Id")]
public string Id { get; set; }
[Microsoft.WindowsAzure.MobileServices.Version]
public string AzureVersion { get; set; }
public String Name { get; set; }
public DateTime PlayedAt { get; set; }
public float Score { get; set; }
}
}
以下初始化 -Method运行没有(!)例外:
public async Task Initialize()
{
try
{
this.mobileService = new MobileServiceClient("http://peterstestapp.azurewebsites.net");
// setup local sqlite store and intialize our table
const string path = "syncstore.db";
MobileServiceSQLiteStore store = new MobileServiceSQLiteStore(path);
store.DefineTable<FirstHighScores>();
await this.mobileService.SyncContext.InitializeAsync(store, new MobileServiceSyncHandler());
// get our sync table that will call out to azure
this.scoresTable = this.mobileService.GetSyncTable<FirstHighScores>();
Debug.WriteLine("Did Initialize");
}
catch(Exception ex)
{
Debug.WriteLine("{0}", ex.Message);
}
}
的SyncScores - 方法如下所示:
public async Task SyncScores()
{
try
{
IMobileServiceTableQuery<FirstHighScores> query = this.scoresTable.CreateQuery();
await this.scoresTable.PullAsync("allScores", query); <== **crashes**
await this.mobileService.SyncContext.PushAsync(); <== not reached
}
catch (MobileServicePushFailedException ex)
{
string ErrorString = string.Format("Push failed because of sync errors: {0} errors, message: {1}",
ex.PushResult.Errors.Count, ex.Message);
Debug.WriteLine(ErrorString + " - " + ex.PushResult.Status);
}
catch (Exception ex)
{
Debug.WriteLine("Exception SyncScores: " + ex);
}
}
的SyncScores - 和初始化 - 方法分享以下实例变量:
private MobileServiceClient mobileService;
private IMobileServiceSyncTable<FirstHighScores> scoresTable;
如果我打电话个SyncScores(一读内 - 或写从我Xamarin - 方法窗体客户端),一个MobileServicePushFailedException -Exception并显示错误消息 'CancelledBySyncStoreError' 被抛出。
在我看来异常被抛出,因为SQLite的客户端在Xamarin窗体应用程序,被指示有关通过我的C#-class“FirstHighScores”的定义表方案及相应的远程表方案Azure Easy Table不完全匹配。
但我无法弄清楚区别....
对不起,有些想法?
如果您从设备上卸载应用程序,数据库将被删除。 –