Search code examples
c#wpfwcfazuremicrosoft-sync-framework

How to work with dynamic filters in Sync Framework without using deprovision?


I've a N-tier Sync Framework application that has a WCF Service hosted on Azure and clients running a small WPF client. These clients sync their local SQL Server Express database with a SQL Database on Azure using the WCF Service. So from the WPF app the SyncOrchestrator uses a SqlSyncProvider (LocalProvider) and a RelationalProviderProxy (RemoteProvider) via a Proxy. Provisioning is done manually on server using the SyncSvcUtilUI from Microsoft and is applied on clients at runtime. It works like a charm!

But now I need to add filters. So clients can choose what Customers they want to sync. They have a simple drop-down to choose client's location (let's say only clients from NY) and then I would apply these filters and Sync. So that's what I'm doing right now:

  1. I've changed the provisioning for the server. I've manually created a scope template using some dynamic filters. For example, Customers table has a side.location = @location filter clause. This is provisioned manually.
  2. When the client choose filters and hit 'Sync', it gets the scope template from the server, applies filter values and creates a new scope.
  3. Then it executes a deprovision of the server and itself (client) BEFORE applying the new scope.
  4. Finally, client applies this new scope that has filter values on both server and client.
  5. Then it syncs.
  6. This process happens for each sync request!

The problem? I've to execute a deprovision of both client and server EACH TIME before syncing, losing tracking and sending all the data again and again. And that's my problem. I can't believe that there is no other way around. Or am I missing something? I need to work with filters and they need to be dynamic.

Please, if anyone has some tips about a better way to do it, I would really appreciate (I'm all ears) :)

Thanks!!


Solution

  • there is no support for dynamic filtering in Sync Fx (partition realignment or rows going in and out of scope).

    the suggested way is to deprovision and re-initialize the client.

    you can try overriding the sync provider and building the filter query yourself (see approach here for overriding the query).

    bringing a row in scope (the row qualifies in the filter condition) is easy. but you will have to deal separately with rows going out of scope (the row has been synched to a client, but the filter condition was modified so the row isnt supposed to be at the client)