示例#1
0
        //public async Task InitializeAsync()
        //{
        //    try
        //    {
        //        var localStoreId = await LocalSyncProvider.GetStoreIdAsync();
        //        var remoteStoreId = await RemoteSyncProvider.GetStoreIdAsync();

        //        var initialLocalChangeSet = await LocalSyncProvider.GetInitialSnapshotAsync(remoteStoreId, SyncDirection.UploadOnly);
        //        await RemoteSyncProvider.ApplyChangesAsync(initialLocalChangeSet, (item) => throw new InvalidOperationException($"Conflit on insert initial item on remote store: {item}"));
        //        //await LocalSyncProvider.SaveVersionForStoreAsync(remoteStoreId, initialLocalChangeSet.SourceAnchor.Version);

        //        var initialRemoteChangeSet = await RemoteSyncProvider.GetInitialSnapshotAsync(localStoreId, SyncDirection.DownloadOnly);
        //        await LocalSyncProvider.ApplyChangesAsync(initialRemoteChangeSet, (item) => throw new InvalidOperationException($"Conflit on insert initial item on local store: {item}"));
        //        //await RemoteSyncProvider.SaveVersionForStoreAsync(localStoreId, initialRemoteChangeSet.SourceAnchor.Version);

        //        await LocalSyncProvider.ApplyProvisionAsync();
        //        await RemoteSyncProvider.ApplyProvisionAsync();

        //    }
        //    catch (Exception ex)
        //    {
        //        throw new SynchronizationException("Unable to initialize stores", ex);
        //    }
        //}

        public async Task SynchronizeAsync(
            Func <SyncItem, ConflictResolution> remoteConflictResolutionFunc = null,
            Func <SyncItem, ConflictResolution> localConflictResolutionFunc  = null)
        {
            try
            {
                remoteConflictResolutionFunc = remoteConflictResolutionFunc ?? ((_) => ConflictResolution.Skip);
                localConflictResolutionFunc  = localConflictResolutionFunc ?? ((_) => ConflictResolution.ForceWrite);

                var localStoreId = await LocalSyncProvider.GetStoreIdAsync();

                var remoteStoreId = await RemoteSyncProvider.GetStoreIdAsync();

                var localChangeSet = await LocalSyncProvider.GetChangesAsync(remoteStoreId, SyncDirection.UploadOnly);

                await RemoteSyncProvider.ApplyChangesAsync(localChangeSet, remoteConflictResolutionFunc);

                await LocalSyncProvider.SaveVersionForStoreAsync(remoteStoreId, localChangeSet.SourceAnchor.Version);

                var remoteChangeSet = await RemoteSyncProvider.GetChangesAsync(localStoreId, SyncDirection.DownloadOnly);

                await LocalSyncProvider.ApplyChangesAsync(remoteChangeSet, localConflictResolutionFunc);

                await RemoteSyncProvider.SaveVersionForStoreAsync(localStoreId, remoteChangeSet.SourceAnchor.Version);

                await LocalSyncProvider.ApplyProvisionAsync();

                await RemoteSyncProvider.ApplyProvisionAsync();
            }
            catch (Exception ex)
            {
                throw new SynchronizationException("Unable to synchronize stores", ex);
            }
        }
示例#2
0
        public async Task SynchronizeAsync(
            Func <SyncItem, ConflictResolution> remoteConflictResolutionFunc = null,
            Func <SyncItem, ConflictResolution> localConflictResolutionFunc  = null)
        {
            try
            {
                var localStoreId = await LocalSyncProvider.GetStoreIdAsync();

                var remoteStoreId = await RemoteSyncProvider.GetStoreIdAsync();

                var localChangeSet = await LocalSyncProvider.GetChangesAsync(remoteStoreId);

                var remoteChangeSet = await RemoteSyncProvider.GetChangesAsync(localStoreId);

                await RemoteSyncProvider.ApplyChangesAsync(localChangeSet, remoteConflictResolutionFunc);

                await LocalSyncProvider.ApplyChangesAsync(remoteChangeSet, localConflictResolutionFunc);
            }
            catch (Exception ex)
            {
                throw new SynchronizationException("Unable to synchronize stores", ex);
            }
        }