Pattern/technique for sending ‘updated only fields’ from server to client for a given object?
I have some serverside data that I need replicating (pushed in real-time) from a server app to around 100 wpf clients. My problem is when a given Order object changes it typically only changes a 1 or 2 fields so I only want to send those changes over the wire Not the whole object – thus decreasing the wire payload, processing time etc as the whole Order object has around 50 fields.
开发者_运维问答The data is a Dictionary of Order objects keyed on OrderId. I use protobuf-net to seralise the data and send over the wire to the wpf clients.
Has anyone dealt with this patterm/problem before? Or have any ideas on who to achieve this?
Thanks a lot.
Create a simple proxy using Castle.DynamicProxy which saves the name of all properties that have been changed.
protobuf-net supports a number of patterns to aid this type of scenario, the simplest being (to share the pattern used by System.ComponentModel):
[ProtoMember(1)]
public string Foo { get;set; }
public bool ShouldSerializeFoo() { /* return true if Foo is "dirty" */ }
This assumes you have some mechanism for tracking the changes yourself (for hooking into the ShouldSerialize*
method); protobuf-net doesn't do change tracking itself. If you don't currently have any change tracking, you might be able to use something from this answer: Comparing 2 objects and retrieve a list of fields with different values
精彩评论