Pergunta Updated data on upload interceptor is not synced back

  • 2 สิงหาคม 2554 17:06
     
      มีโค้ด

    We are using an upload request interceptor to change a property of an incoming Contact object before it gets saved on the db by the sync framework. Contacts belong to users and each user syncs his own contacts.

    This code in the upload interceptor does the following:

    • check whether ConnectionStatus = 4 of the incoming contact object, 
    • open a db context and get all other db contacts that also have ConnectionStatus = 4
    • set ConnectionStatus = 5 to db contacts
    • set ConnectionStatus = 5 to incoming contact
    • return and hope that the incoming contact will be sent back to the user with an updated ConnectionStatus on the subsequent Download response.

    [SyncRequestInterceptor("UserScope", SyncOperations.Upload)]
    public void Contact_Upload_Request(SyncOperationContext context) {
          ((SyncUploadRequestOperationContext)context).RequestHeaders.Add("UploadResponseInterceptorFired", "true");
           
          //get the collection of updated/created contactEmails
          ReadOnlyCollection<IOfflineEntity> incoming = ((SyncUploadRequestOperationContext)context).IncomingChanges;
        
          IEnumerable<Contact> incomingContacts = outgoing.OfType<covve.Services.Contact>().AsEnumerable();
    
         //open a db context
         //for each incoming contact
           //get some contacts from the db
           //change db contacts
           //change incoming contact
         //save the db context
    }
    

    The expected behabior is that the subsequent DownloadResponse context will sync the on-the-fly change back to the user. So our user will get a ConnectionStatus=5 even though he initially sent a contact with ConnectionStatus=4. This never happens, and the user's contact is never updated with connstatus=5, even though I can see that the database holds the correct, updated value. On the other hand, the contacts we changed directly on the DB are sent to their users when they sync with the server.

    We have verified that the db is provisioned OK and the specific column is getting Synced. The problem is that MOST of the times (and not always) this on-the-fly change is not sent back to the user. We have checked the download  response of the server and sync does not send back the updated object.

    The weird thing is that if the user with the onthefly updated contact deletes his local storage and syncs from scratch, he will get all the changes.

     

    Do you have any pointers or ideas? This really is the core of our business logic because a complex sync filter depends on this column.

ตอบทั้งหมด

  • 3 สิงหาคม 2554 8:42
    ผู้ดูแล
     
     

    try doing your extra processing on the  SyncResponseInterceptor instead.

    the problem with doing the on-the-fly change on the upload interceptor is that the metadata will not reflect this a change from a normal table operation. changes applied by sync framework itself updates the metadata to prevent uploaded changes from being detected as changes for download where your client end up uploading a change and downloading the same change

     

  • 3 สิงหาคม 2554 8:56
     
     

    Thanks for your reply.

     

    If I understand your point correctly, your are proposing that if the client sends Object.property = "text", the server intercepts the upload request and sets Object.property = "anotherText", the client will update his onw Object.property = "text". Well, we have tested and verified that indeed when something is changed on the upload interceptor the change is sent back to the client.

    The problem is that we are seeing maybe inconsistent behavior? Sometimes this seems to work and sometimes it doesn't. Is there something I can do to make sure that my upload request intercepted changes will be sent back, e.g by tweaking the sync metadata on the fly?

  • 3 สิงหาคม 2554 13:26
     
     

    We narrowed the problem even further. It doesn't have to do at all with operations done on the UploadRequest Interceptor. We change the properties in sql by hand and still no sync.

     

    I opened a new thread here

    http://social.msdn.microsoft.com/Forums/en-US/synclab/thread/ee2110cf-ff73-4096-8c2e-30f6d2f0ff22