DataRecorder: a lightweight data synchronization approach

Let's suppose for some reason in your .Net client\server application you can't use standard approaches to remote data synchronization, like .Net remoting, WCF and ICE objects (bypassing proxies\firewalls may be one of the reasons you may encounter this problem). So, you have to implement your own lightweight data synchronization engine or hardcode synchronization for every specific task, object and collection you want to synchronize. As a solution, it may be a good idea to write a class-manager that listens to a standard .Net data events from interfaces INotifyPropertyChanged and INotifyCollectionChanged, and records these changes into serializable commands, so it is possible to execute this commands remotely, updating the remote state of this object.

The process goes like this:

host1:

            Recorder rec1 = GetRecorder();
            TestObject to1 = new TestObject {ID = "45"};
            rec1.Manage(to1);

host2: (it is assumed that to2 is the result of deserialization of to1)

            Recorder rec2 = GetRecorder();
            TestObject to2 = new TestObject {ID = to1.ID};
            rec2.Manage(to2);

host1 (updates object properties)

            to1.IntProperty = 25;
            to1.Property = "234235";
 
            var commands = rec1.GetAllCommands();

(commands are serialized and transferred to host2)

host2

            rec2.ExecuteCommands(commands);
 
            Assert.AreEqual(to1.IntProperty,to2.IntProperty);
            Assert.AreEqual(to1.Property,to2.Property);

(must be equal)

This approach is data-independent, it assumes that data is "manageable" if a number of standard interfaces were implemented, and although it uses reflection and therefore works slower than direct hardcode, its generic event-based approach may prove very helpful, especially in synchronizations of heterogeneous, often-changing data.

DataRecorder becomes even more attractive when you have to merge different command streams from different sources, also it may be useful in miscellaneous Undo\Redo scenarios.

The raw, but working prototype of DataRecorder along with some tests you may find in the attachment.

AttachmentSize
DataRecorder.zip14.43 KB