0

我试图从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不完全匹配。

但我无法弄清楚区别....

对不起,有些想法?

回答

0

我自己找到了解决方法。

也许在我的应用程序开发过程中,根据数据库方案的一些细节可能已经改变(尽管我真的不记得这一点)。

当数据库模型的设计是稳定的,我刚刚创建了一个新的MobileServiceSQLiteStore对象 (表示:我选择另一个名称为数据库存储)...和同步方式工作得很好!

+0

如果您从设备上卸载应用程序,数据库将被删除。 –

相关问题