views:

74

answers:

1

I have a Windows Form application built on a data model and a Windows Mobile application which contains a similar data model. When users enter information in the mobile application I sync it with the data in the main application. This is achieved by essentially having the class defintions used in the mobile application in the main application and then coding the synchronisation between the two different models.

I am now at a point where the mobile application has been enhanced and a new version created so when synchronisation occurs in the main application it could be syncing from mobile v1 or v2 which have different data models.

What is the best way to achieve synchronisation. An example may be that the main application and v2 of the mobile application contain an order date for an order which needs to be synced. If syncing from v1 of the mobile app which does not contain this property it should be ignored.

+1  A: 

I would subclass the model object to a version 2:

public class DataObject
{
     public string CustomerName { get; set; }
}

public class DataObjectVersion2 : DataObject
{
    public DataTimeOrderDate { get; set; }
}

Then in the WinForms app you can just check the type to determine how much data is available:

public void SyncDataFromMobile(DataObject data)
{
    this.WinformsData = new WinFormsDataObject();

    this.WinFormsData.CustomerName = data.CustomerName;

    DataObjectVersion2 data2 = data as DataObjectVersion2;

    if (data2 != null)
    {
        SyncDataFromMobileVersion2(data2);
    }
}

private void SyncDataFromMobileVersion2(DataObjectVersion2 data)
{
    this.WinFormsData.OrderDate = data.OrderDate;
}
Martin Harris
This works - it may become unwiedly when there are a lot of versions of the objects and perhaps needs thought when a certain version of an obejct depends on a certain version of another object
Gary Joynes