C
C#16mo ago
sts.sl

✅ Tracking changes on a complex object provided by a third party library

Hi! I have a third party .Net Framework dll that allows me to load a file. This file is potentially several hundreds of megabytes in size, I get a single object to manage it. It's not just a plan object, it has it's own processing threads and does complicated logic and has it's own editor. Once I'm done working with this object, I can serialize it again. The clients request was to add change tracking to this. As it does processing with real time data, I have a bunch of rules for what is considered a change. My current solution is loading the object twice and using https://github.com/GregFinzer/Compare-Net-Objects with lots of custom rules for comparison. I have two issues with the current approach: 1.: Memory usage. I potentially have up to 8 of these loaded, implementing change tracking on them like this might make me run out of memory. 2.: Resource usage. The object potentially needs access to physical resources. Loading it twice might cause errors where these resources can't be shared. Ideally I'd be able to track changes to specific properties and fields instead of having two copies to compare. How would you guys approach this problem? I have plenty of change events available that are potentially enough for me to track everything, however this is a deeply nested object with potentially hundreds of types, some of them might not be known to me at compile time so ideally I'd prefer a blacklist-based approach.
GitHub
GitHub - GregFinzer/Compare-Net-Objects: What you have been waiting...
What you have been waiting for :+1: Perform a deep compare of any two .NET objects using reflection. Shows the differences between the two objects. - GitHub - GregFinzer/Compare-Net-Objects: What...
6 Replies
Sossenbinder
Sossenbinder16mo ago
In what format do you need to track these changes? Is it possible to use something akin to event sourcing to retain a list of changes and what they changed, and replay them on the object later? This sounds like it would make use of reflection though Since you need to replay them if I got it right
ThomFox
ThomFox16mo ago
I'd also check, if there was change tracking already implemented in that 3rd party library and whether there might already be an add-on that would allow change tracking
sts.sl
sts.slOP16mo ago
The end goal is to generate a changelog when saving the object that can be displayed in a list with two types of entries (depending on the specific property)
Path.To.Nested.Object.PropertyName1: OldValue => NewValue
Path.To.Nested.Object.PropertyName2 has changed
Path.To.Nested.Object.PropertyName1: OldValue => NewValue
Path.To.Nested.Object.PropertyName2 has changed
The nested objects all implement the same interface, which provides a Changed event. This event contains the property names but not the values I highly doubt it because even when I open the "official" editor and try to close it, it asks me if I want to save 😄 I'm basically working an Editor+ for this thing. But I'll have a look, maybe they have something like this
ThomFox
ThomFox16mo ago
I see, the 3rd party library comes with its own UI presented to the user to edit the object?
sts.sl
sts.slOP16mo ago
Yeah, it's a deeply nested object of various types which each have their own editor window. This results in usually 5-10 windows being open at any time whenever someone is using it. My editor has a simple treeview to simplify this and has some additional features, such as adding documentation to each object, validation and more controlled data processing. At the end of the day I'm presenting their editor windows, just with a different structure. I could create custom editor controls for these types but that's a bigger project than this current one. I'd love to do it but there's no business reason for it and it would take months potentially.
Accord
Accord16mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server