3

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.

arkina
  • 991
  • 2
  • 11
  • 17

2 Answers2

0

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

Community
  • 1
  • 1
Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • Sorry how would this work? I can track changes using INotifyPropertyChanged and store the last change in a Hashtable (key: PropertyName, Value = theValue). But in your example, how would ShouldSerializeFoo be used? Inside the property? – arkina Jun 28 '11 at 11:21
  • Also do you have any System.ComponentModel examples? I can't find anything on this usage pattern? – arkina Jun 28 '11 at 11:25
  • @arkina - [see here](http://msdn.microsoft.com/en-us/library/system.componentmodel.propertydescriptor.shouldserializevalue.aspx) for MSDN discussing that pattern. Re your earlier comment, I might use a `HashSet` and just store the names; "as is" the object would need to be able to return `true`/`false` on a member-by-member basis, i.e. `return deltas.Contains("Foo")` – Marc Gravell Jun 28 '11 at 12:08
  • I meant a Dictionary (hashtable) (key: PropertyName, Value = theValue) to store the property name and latest values – arkina Jun 28 '11 at 12:35
  • @arkina fine, whatever works; as long as you can tell whether it has changed or not. – Marc Gravell Jun 28 '11 at 12:36
0

Create a simple proxy using Castle.DynamicProxy which saves the name of all properties that have been changed.

jgauffin
  • 99,844
  • 45
  • 235
  • 372