Rabu, 20 Februari 2008

Handle Data Conflicts and Errors ADO.NET Synchronization

partial class LocalDataCache1ServerSyncProvider
{
protected override void OnChangesSelected(ChangesSelectedEventArgs value)
{
base.OnChangesSelected(value);


}
public override SyncContext GetChanges(SyncGroupMetadata groupMetadata, SyncSession syncSession)
{
return base.GetChanges(groupMetadata, syncSession);
MessageBox.Show(groupMetadata.BatchCount + " Change");
}
protected override void OnSelectingChanges(SelectingChangesEventArgs value)
{
base.OnSelectingChanges(value);

}
protected override void OnApplyChangeFailed(Microsoft.Synchronization.Data.ApplyChangeFailedEventArgs value)
{
DataTable clientchanges = value.Conflict.ClientChange;
DataTable serverchanges = value.Conflict.ServerChange;
if(value.Conflict.ConflictType==ConflictType.ClientUpdateServerDelete)
{


value.Action = ApplyAction.RetryWithForceWrite;


}
if (value.Conflict.ConflictType == ConflictType.ClientInsertServerInsert)
{
value.Action = ApplyAction.RetryWithForceWrite;
}

if (value.Conflict.ConflictType == ConflictType.ClientUpdateServerUpdate)
{
//Logic goes here.
Form1 a = new Form1();
a.ultraGrid1.DataSource = serverchanges;
a.ultraGrid2.DataSource = clientchanges;
a.ultraStatusBar1.Text = "Data has been changed by other user since your last synchronization";
a.ShowDialog();
value.Action = a.action;
}

if (value.Conflict.ConflictType == ConflictType.ErrorsOccurred)
{
//Logic goes here.
MessageBox.Show(value.Conflict.ErrorMessage, "UnKnown Error Happened:Continuing");

}

}
protected override void OnApplyingChanges(ApplyingChangesEventArgs value)
{
DataSet clientchanges = value.Changes;
}
}

Tidak ada komentar: