Locations of visitors to this page


Sync Services Part 2

Onteora Software

Ken Tucker's Blog

About the author

Author Name is someone.
E-mail me Send mail

Recent comments

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

Sync Services Part 2

In the second post of this series we will make it so changes we make to the local data will be sent back to the server.  Lets start by opening the project we created in the previous post.

 

So lets extend the SyncAgent Partial classes to make the sync 2 way. The class contains a partial method OnInitialized which you can add code to.   In this method we will make the Products table Sync Direction Bidirectional.

 

Partial Public Class NorthwindSyncAgent

    Private Sub OnInitialized()
        Me.Products.SyncDirection = SyncDirection.Bidirectional
    End Sub
End Class

 

Now what if there is a conflict? Let create a form to give the user the option of keeping the changes he/she made or to accept the changes on the server.  Add a form named frmConflict to the project.  On the form add 2 buttons (btnClient, and btnServer) and 2 datagridviews (dgvClient, and dgvServer).  Here is what my form looks like

 

image

 

Add the following code to the buttons

Private Sub btnClient_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClient.Click
    Me.DialogResult = Windows.Forms.DialogResult.OK
    Me.Close()
End Sub

Private Sub btnServer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnServer.Click
    Me.DialogResult = Windows.Forms.DialogResult.Cancel
    Me.Close()
End Sub

 

Now we need to extend the ServerSyncProvider to raise an event when there is a conflict. If the user presses the Keep my changes button we force the changes to be written to the database otherwise we allow the change to be made

 

Partial Public Class NorthwindServerSyncProvider

    Private Sub OnInitialized()
        AddHandler ApplyChangeFailed, AddressOf ApplyChangesFailed
    End Sub

    Public Sub ApplyChangesFailed(ByVal sender As Object, ByVal e As ApplyChangeFailedEventArgs)
        Dim frm As New frmConflict
        frm.dgvClient.DataSource = e.Conflict.ClientChange
        frm.dgvServer.DataSource = e.Conflict.ServerChange
        frm.ShowDialog()
        If frm.DialogResult = DialogResult.OK Then
            e.Action = ApplyAction.RetryWithForceWrite
        Else
            e.Action = ApplyAction.Continue
        End If
    End Sub

End Class



kick it on DotNetKicks.com

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by Ken Tucker on Saturday, January 26, 2008 8:59 PM
Permalink | Comments (1) | Post RSSRSS comment feed

Related posts

Comments

DotNetKicks.com

Sunday, January 27, 2008 5:40 AM

trackback

Trackback from DotNetKicks.com

Sync Services Part 2

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

Thursday, November 20, 2008 10:53 PM