Synchronizing different versions of objects

I have a Windows Form application built on a data model and a Windows Mobile application that contains a similar data model. When users enter information into the mobile app, I sync it with the data in the main app. This is achieved by essentially defining the class used in the mobile application in the main application and then coding the synchronization between the two different models.

Now I am at the point where the mobile application has been extended and the new version is built in such a way that when synchronized in the main application, it can be synchronized with mobile v1 or v2 which have different data models.

What is the best way to achieve synchronization. An example would be that the main app and v2 of the mobile app contain the order date for the order that needs to be synchronized. If a sync from v1 of a mobile app that does not contain this property should be ignored.

+1


a source to share


1 answer


I would subclass the model object to version 2:

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

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

      



Then, in a WinForms application, you can simply 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;
}

      

+1


a source







All Articles