var config = Db4oEmbedded.NewConfiguration ();
using (var container = Db4oEmbedded.OpenFile (config, FILE))
{
var foo = new Foo ("Test");
container.Store (foo);
foo.Name = "NewName";
container.Store (foo);
}
Any way to resolve the history of container for开发者_如何学运维 foo in the format below?
Foo created with values "Test" Foo
Foo's property "Test" changed to "NewName"
You can do by implementing event-handlers. Basically you can register a event-handler for the creating and the updating event. Like this:
IEventRegistry events = EventRegistryFactory.ForObjectContainer(container);
events.Creating +=delegate(object sender, CancellableObjectEventArgs args)
{
Console.WriteLine("{0} created: Value {1}",args.Object.GetType(),args.Object);
};
For viewing value changes you maybe need to peek the old state in the event-handler. You can do this like this:
IEventRegistry events = EventRegistryFactory.ForObjectContainer(container);
events.Creating +=delegate(object sender, CancellableObjectEventArgs args)
{
IObjectContainer eventContainer = args.ObjectContainer();
object oldVersion = eventContainer.Ext().Peek(args.Object,1,false);
object currentVersion = args.Object;
// Do comparison and print stuff
};
Of course the comparison and printing is the work you have to do. There's nothing built in for that.
精彩评论