【问题标题】:Azure Offline Sync - Uncaught ExceptionAzure 脱机同步 - 未捕获的异常
【发布时间】:2017-05-23 23:54:48
【问题描述】:

我正在使用 Xamarin Forms 和 Azure 尝试在我的移动应用中实现离线同步,以存储 Machine 对象的列表。

在我处理离线同步的课程中,我有一个名为 Initialize() 的函数,用于在我的手机或平板电脑中设置本地数据库,以进行离线同步

    public MobileServiceClient client { get; set; }
    IMobileServiceSyncTable<Machine> machineTable;

    public async Task Initialize()
    {
        if (client?.SyncContext?.IsInitialized ?? false)
        {
            return;
        }
        var azureUrl = "http://mycoolwebsite.azurewebsites.net";

        //Create our client
        client = new MobileServiceClient(azureUrl);

        //InitialzeDatabase for path
        var path = "mylocaldb.db";
        path = Path.Combine(MobileServiceClient.DefaultDatabasePath, path);

        //setup our local sqlite store and intialize our table
        var store = new MobileServiceSQLiteStore(path);

        //Define table
        store.DefineTable<Machine>();

        //Initialize SyncContext -- Populate the local DB!
        await client.SyncContext.InitializeAsync(store, new MobileServiceSyncHandler());  //<-- EXCEPTION HERE
        machineTable = client.GetSyncTable<Machine>(); 
        // table.PurgeAsync();
    }

当我运行这段代码时,我在上面突出显示的那一行遇到了一个异常。我错过了什么?作为参考,我正在关注this教程。

【问题讨论】:

    标签: azure xamarin xamarin.forms offline-caching


    【解决方案1】:

    原来使用时:

        await client.SyncContext.InitializeAsync(store, new MobileServiceSyncHandler());
        machineTable = client.GetSyncTable<Machine>(); 
    

    我需要在我的Machine 对象中有一个public string Id { get; set; } 变量,因为构建本地数据库的代码需要这个字段。如果将其添加到某个地方的文档中会很好!

    【讨论】:

    • 离线同步可以关注adrian hall的书here
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-18
    • 2014-06-03
    • 2020-08-24
    • 2016-05-10
    • 2015-04-22
    • 2018-12-12
    相关资源
    最近更新 更多